From 2cf13759ba1696d88f5ff86afee5324f30ccdbfc Mon Sep 17 00:00:00 2001 From: Frederic Suter Date: Sat, 16 Feb 2019 23:29:07 +0100 Subject: [PATCH] week-end cleanups in ActorImpl That excalated quickly ... --- src/kernel/activity/CommImpl.cpp | 12 +- src/kernel/activity/ConditionVariableImpl.cpp | 2 +- src/kernel/activity/MutexImpl.cpp | 4 +- src/kernel/activity/SemaphoreImpl.cpp | 2 +- src/kernel/activity/SleepImpl.cpp | 4 +- src/kernel/context/Context.cpp | 10 +- .../CommunicationDeterminismChecker.cpp | 18 +-- src/mc/checker/SafetyChecker.cpp | 4 +- src/mc/mc_base.cpp | 4 +- src/mc/mc_comm_pattern.cpp | 2 +- src/mc/mc_global.cpp | 4 +- src/mc/mc_request.cpp | 113 +++++++++--------- src/mc/mc_smx.cpp | 4 +- src/mc/mc_state.cpp | 6 +- src/mc/mc_state.hpp | 2 +- src/mc/remote/Client.cpp | 2 +- src/mc/sosp/mc_checkpoint.cpp | 2 +- src/msg/msg_process.cpp | 2 +- src/plugins/vm/VirtualMachineImpl.cpp | 4 +- src/s4u/s4u_Actor.cpp | 22 ++-- src/s4u/s4u_Host.cpp | 8 +- src/simix/ActorImpl.cpp | 91 +++++++------- src/simix/ActorImpl.hpp | 81 +++++++------ src/simix/popping_generated.cpp | 2 +- src/simix/simcalls.py | 2 +- src/simix/smx_global.cpp | 9 +- src/simix/smx_host.cpp | 4 +- src/simix/smx_io.cpp | 2 +- src/simix/smx_network.cpp | 12 +- src/smpi/mpi/smpi_comm.cpp | 2 +- src/surf/HostImpl.cpp | 6 +- 31 files changed, 227 insertions(+), 215 deletions(-) diff --git a/src/kernel/activity/CommImpl.cpp b/src/kernel/activity/CommImpl.cpp index 34e15450d3..e6042d46dd 100644 --- a/src/kernel/activity/CommImpl.cpp +++ b/src/kernel/activity/CommImpl.cpp @@ -69,8 +69,8 @@ void CommImpl::start() /* If both the sender and the receiver are already there, start the communication */ if (state_ == SIMIX_READY) { - s4u::Host* sender = src_actor_->host_; - s4u::Host* receiver = dst_actor_->host_; + s4u::Host* sender = src_actor_->get_host(); + s4u::Host* receiver = dst_actor_->get_host(); surf_action_ = surf_network_model->communicate(sender, receiver, task_size_, rate_); surf_action_->set_data(this); @@ -92,11 +92,11 @@ void CommImpl::start() if (src_actor_->is_suspended()) XBT_DEBUG("The communication is suspended on startup because src (%s@%s) was suspended since it initiated the " "communication", - src_actor_->get_cname(), src_actor_->host_->get_cname()); + src_actor_->get_cname(), src_actor_->get_host()->get_cname()); else XBT_DEBUG("The communication is suspended on startup because dst (%s@%s) was suspended since it initiated the " "communication", - dst_actor_->get_cname(), dst_actor_->host_->get_cname()); + dst_actor_->get_cname(), dst_actor_->get_host()->get_cname()); surf_action_->suspend(); } @@ -112,8 +112,8 @@ void CommImpl::copy_data() return; XBT_DEBUG("Copying comm %p data from %s (%p) -> %s (%p) (%zu bytes)", this, - src_actor_ ? src_actor_->host_->get_cname() : "a finished process", src_buff_, - dst_actor_ ? dst_actor_->host_->get_cname() : "a finished process", dst_buff_, buff_size); + src_actor_ ? src_actor_->get_host()->get_cname() : "a finished process", src_buff_, + dst_actor_ ? dst_actor_->get_host()->get_cname() : "a finished process", dst_buff_, buff_size); /* Copy at most dst_buff_size bytes of the message to receiver's buffer */ if (dst_buff_size_) diff --git a/src/kernel/activity/ConditionVariableImpl.cpp b/src/kernel/activity/ConditionVariableImpl.cpp index 1d60b46c89..144373c740 100644 --- a/src/kernel/activity/ConditionVariableImpl.cpp +++ b/src/kernel/activity/ConditionVariableImpl.cpp @@ -28,7 +28,7 @@ static void _SIMIX_cond_wait(smx_cond_t cond, smx_mutex_t mutex, double timeout, mutex->unlock(issuer); } - synchro = SIMIX_synchro_wait(issuer->host_, timeout); + synchro = SIMIX_synchro_wait(issuer->get_host(), timeout); synchro->simcalls_.push_front(simcall); issuer->waiting_synchro = synchro; cond->sleeping.push_back(*simcall->issuer); diff --git a/src/kernel/activity/MutexImpl.cpp b/src/kernel/activity/MutexImpl.cpp index cc82ce65f2..538e418f37 100644 --- a/src/kernel/activity/MutexImpl.cpp +++ b/src/kernel/activity/MutexImpl.cpp @@ -34,7 +34,7 @@ void MutexImpl::lock(smx_actor_t issuer) if (this->locked) { /* FIXME: check if the host is active ? */ /* Somebody using the mutex, use a synchronization to get host failures */ - synchro = SIMIX_synchro_wait(issuer->host_, -1); + synchro = SIMIX_synchro_wait(issuer->get_host(), -1); synchro->simcalls_.push_back(&issuer->simcall); issuer->waiting_synchro = synchro; this->sleeping.push_back(*issuer); @@ -81,7 +81,7 @@ void MutexImpl::unlock(smx_actor_t issuer) /* If the mutex is not owned by the issuer, that's not good */ if (issuer != this->owner) THROWF(mismatch_error, 0, "Cannot release that mutex: it was locked by %s (pid:%ld), not by you.", - this->owner->get_cname(), this->owner->pid_); + this->owner->get_cname(), this->owner->get_pid()); if (not this->sleeping.empty()) { /*process to wake up */ diff --git a/src/kernel/activity/SemaphoreImpl.cpp b/src/kernel/activity/SemaphoreImpl.cpp index 29e92657b6..9d47f0bce5 100644 --- a/src/kernel/activity/SemaphoreImpl.cpp +++ b/src/kernel/activity/SemaphoreImpl.cpp @@ -18,7 +18,7 @@ void SemaphoreImpl::acquire(smx_actor_t issuer, double timeout) XBT_DEBUG("Wait semaphore %p (timeout:%f)", this, timeout); if (value_ <= 0) { - synchro = SIMIX_synchro_wait(issuer->host_, timeout); + synchro = SIMIX_synchro_wait(issuer->get_host(), timeout); synchro->simcalls_.push_front(&issuer->simcall); issuer->waiting_synchro = synchro; sleeping_.push_back(*issuer); diff --git a/src/kernel/activity/SleepImpl.cpp b/src/kernel/activity/SleepImpl.cpp index f666d03dcf..18bdbef0d7 100644 --- a/src/kernel/activity/SleepImpl.cpp +++ b/src/kernel/activity/SleepImpl.cpp @@ -64,12 +64,12 @@ void SleepImpl::post() THROW_IMPOSSIBLE; break; } - if (not simcall->issuer->host_->is_on()) { + if (not simcall->issuer->get_host()->is_on()) { simcall->issuer->context_->iwannadie = true; } simcall_process_sleep__set__result(simcall, result); simcall->issuer->waiting_synchro = nullptr; - if (simcall->issuer->suspended_) { + if (simcall->issuer->is_suspended()) { XBT_DEBUG("Wait! This process is suspended and can't wake up now."); simcall->issuer->suspended_ = false; simcall_HANDLER_process_suspend(simcall, simcall->issuer); diff --git a/src/kernel/context/Context.cpp b/src/kernel/context/Context.cpp index 0cca7b8656..5f754be6ea 100644 --- a/src/kernel/context/Context.cpp +++ b/src/kernel/context/Context.cpp @@ -86,10 +86,10 @@ void Context::stop() { actor_->finished_ = true; - if (actor_->auto_restart_ && not actor_->host_->is_on()) { - XBT_DEBUG("Insert host %s to watched_hosts because it's off and %s needs to restart", actor_->host_->get_cname(), - actor_->get_cname()); - watched_hosts.insert(actor_->host_->get_name()); + if (actor_->has_to_auto_restart() && not actor_->get_host()->is_on()) { + XBT_DEBUG("Insert host %s to watched_hosts because it's off and %s needs to restart", + actor_->get_host()->get_cname(), actor_->get_cname()); + watched_hosts.insert(actor_->get_host()->get_name()); } // Execute the termination callbacks @@ -106,7 +106,7 @@ void Context::stop() actor_->comms.clear(); XBT_DEBUG("%s@%s(%ld) should not run anymore", actor_->get_cname(), actor_->iface()->get_host()->get_cname(), - actor_->pid_); + actor_->get_pid()); if (this->cleanup_func_) this->cleanup_func_(this->actor_); diff --git a/src/mc/checker/CommunicationDeterminismChecker.cpp b/src/mc/checker/CommunicationDeterminismChecker.cpp index e40236d855..f9e5fb1853 100644 --- a/src/mc/checker/CommunicationDeterminismChecker.cpp +++ b/src/mc/checker/CommunicationDeterminismChecker.cpp @@ -102,8 +102,8 @@ static void update_comm_pattern(simgrid::mc::PatternCommunication* comm_pattern, smx_actor_t src_proc = mc_model_checker->process().resolveActor(simgrid::mc::remote(comm->src_actor_.get())); smx_actor_t dst_proc = mc_model_checker->process().resolveActor(simgrid::mc::remote(comm->dst_actor_.get())); - comm_pattern->src_proc = src_proc->pid_; - comm_pattern->dst_proc = dst_proc->pid_; + comm_pattern->src_proc = src_proc->get_pid(); + comm_pattern->dst_proc = dst_proc->get_pid(); comm_pattern->src_host = MC_smx_actor_get_host_name(src_proc); comm_pattern->dst_host = MC_smx_actor_get_host_name(dst_proc); if (comm_pattern->data.size() == 0 && comm->src_buff_ != nullptr) { @@ -172,8 +172,8 @@ void CommunicationDeterminismChecker::get_comm_pattern(xbt_dynar_t list, smx_sim { const smx_actor_t issuer = MC_smx_simcall_get_issuer(request); simgrid::mc::PatternCommunicationList* initial_pattern = - xbt_dynar_get_as(initial_communications_pattern, issuer->pid_, simgrid::mc::PatternCommunicationList*); - xbt_dynar_t incomplete_pattern = xbt_dynar_get_as(incomplete_communications_pattern, issuer->pid_, xbt_dynar_t); + xbt_dynar_get_as(initial_communications_pattern, issuer->get_pid(), simgrid::mc::PatternCommunicationList*); + xbt_dynar_t incomplete_pattern = xbt_dynar_get_as(incomplete_communications_pattern, issuer->get_pid(), xbt_dynar_t); std::unique_ptr pattern = std::unique_ptr(new simgrid::mc::PatternCommunication()); @@ -193,7 +193,8 @@ void CommunicationDeterminismChecker::get_comm_pattern(xbt_dynar_t list, smx_sim char* remote_name = mc_model_checker->process().read( RemotePtr((uint64_t)(synchro->mbox ? &synchro->mbox->name_ : &synchro->mbox_cpy->name_))); pattern->rdv = mc_model_checker->process().read_string(RemotePtr(remote_name)); - pattern->src_proc = mc_model_checker->process().resolveActor(simgrid::mc::remote(synchro->src_actor_.get()))->pid_; + pattern->src_proc = + mc_model_checker->process().resolveActor(simgrid::mc::remote(synchro->src_actor_.get()))->get_pid(); pattern->src_host = MC_smx_actor_get_host_name(issuer); #if HAVE_SMPI @@ -243,13 +244,14 @@ void CommunicationDeterminismChecker::get_comm_pattern(xbt_dynar_t list, smx_sim &remote_name, remote(comm->mbox ? &simgrid::xbt::string::to_string_data(comm->mbox->name_).data : &simgrid::xbt::string::to_string_data(comm->mbox_cpy->name_).data)); pattern->rdv = mc_model_checker->process().read_string(RemotePtr(remote_name)); - pattern->dst_proc = mc_model_checker->process().resolveActor(simgrid::mc::remote(comm->dst_actor_.get()))->pid_; + pattern->dst_proc = + mc_model_checker->process().resolveActor(simgrid::mc::remote(comm->dst_actor_.get()))->get_pid(); pattern->dst_host = MC_smx_actor_get_host_name(issuer); } else xbt_die("Unexpected call_type %i", (int) call_type); - XBT_DEBUG("Insert incomplete comm pattern %p for process %ld", pattern.get(), issuer->pid_); - xbt_dynar_t dynar = xbt_dynar_get_as(incomplete_communications_pattern, issuer->pid_, xbt_dynar_t); + XBT_DEBUG("Insert incomplete comm pattern %p for process %ld", pattern.get(), issuer->get_pid()); + xbt_dynar_t dynar = xbt_dynar_get_as(incomplete_communications_pattern, issuer->get_pid(), xbt_dynar_t); simgrid::mc::PatternCommunication* pattern2 = pattern.release(); xbt_dynar_push(dynar, &pattern2); } diff --git a/src/mc/checker/SafetyChecker.cpp b/src/mc/checker/SafetyChecker.cpp index 51c0a97f94..b8344033f5 100644 --- a/src/mc/checker/SafetyChecker.cpp +++ b/src/mc/checker/SafetyChecker.cpp @@ -230,7 +230,7 @@ void SafetyChecker::backtrack() state->num); } - if (not prev_state->actorStates[issuer->pid_].isDone()) + if (not prev_state->actorStates[issuer->get_pid()].isDone()) prev_state->addInterleavingSet(issuer); else XBT_DEBUG("Process %p is in done set", req->issuer); @@ -246,7 +246,7 @@ void SafetyChecker::backtrack() const smx_actor_t previous_issuer = MC_smx_simcall_get_issuer(&prev_state->internal_req); XBT_DEBUG("Simcall %d, process %ld (state %d) and simcall %d, process %ld (state %d) are independent", - req->call, issuer->pid_, state->num, prev_state->internal_req.call, previous_issuer->pid_, + req->call, issuer->get_pid(), state->num, prev_state->internal_req.call, previous_issuer->get_pid(), prev_state->num); } } diff --git a/src/mc/mc_base.cpp b/src/mc/mc_base.cpp index 162fd84426..ed16b52e5b 100644 --- a/src/mc/mc_base.cpp +++ b/src/mc/mc_base.cpp @@ -72,7 +72,7 @@ bool actor_is_enabled(smx_actor_t actor) #if SIMGRID_HAVE_MC // If in the MCer, ask the client app since it has all the data if (mc_model_checker != nullptr) { - return mc_model_checker->process().actor_is_enabled(actor->pid_); + return mc_model_checker->process().actor_is_enabled(actor->get_pid()); } #endif @@ -116,7 +116,7 @@ bool actor_is_enabled(smx_actor_t actor) if (mutex->owner == nullptr) return true; - return mutex->owner->pid_ == req->issuer->pid_; + return mutex->owner->get_pid() == req->issuer->get_pid(); } case SIMCALL_SEM_ACQUIRE: { diff --git a/src/mc/mc_comm_pattern.cpp b/src/mc/mc_comm_pattern.cpp index 2be0e8e15b..07e30d0db9 100644 --- a/src/mc/mc_comm_pattern.cpp +++ b/src/mc/mc_comm_pattern.cpp @@ -95,7 +95,7 @@ void MC_handle_comm_pattern( value, sizeof(comm_addr)); comm_addr = remote(addr); } - checker->complete_comm_pattern(pattern, comm_addr, MC_smx_simcall_get_issuer(req)->pid_, backtracking); + checker->complete_comm_pattern(pattern, comm_addr, MC_smx_simcall_get_issuer(req)->get_pid(), backtracking); } break; default: diff --git a/src/mc/mc_global.cpp b/src/mc/mc_global.cpp index 95105d634f..f85660aa71 100644 --- a/src/mc/mc_global.cpp +++ b/src/mc/mc_global.cpp @@ -175,11 +175,11 @@ double MC_process_clock_get(smx_actor_t process) if (simgrid::mc::processes_time.empty()) return 0; if (process != nullptr) - return simgrid::mc::processes_time[process->pid_]; + return simgrid::mc::processes_time[process->get_pid()]; return -1; } void MC_process_clock_add(smx_actor_t process, double amount) { - simgrid::mc::processes_time[process->pid_] += amount; + simgrid::mc::processes_time[process->get_pid()] += amount; } diff --git a/src/mc/mc_request.cpp b/src/mc/mc_request.cpp index 0ac83559e8..27a7ec8158 100644 --- a/src/mc/mc_request.cpp +++ b/src/mc/mc_request.cpp @@ -205,11 +205,11 @@ std::string simgrid::mc::request_to_string(smx_simcall_t req, int value, simgrid type = "iSend"; char* p = pointer_to_string(simcall_comm_isend__get__src_buff(req)); char* bs = buff_size_to_string(simcall_comm_isend__get__src_buff_size(req)); - if (issuer->host_) - args = bprintf("src=(%ld)%s (%s), buff=%s, size=%s", issuer->pid_, MC_smx_actor_get_host_name(issuer), + if (issuer->get_host()) + args = bprintf("src=(%ld)%s (%s), buff=%s, size=%s", issuer->get_pid(), MC_smx_actor_get_host_name(issuer), MC_smx_actor_get_name(issuer), p, bs); else - args = bprintf("src=(%ld)%s, buff=%s, size=%s", issuer->pid_, MC_smx_actor_get_name(issuer), p, bs); + args = bprintf("src=(%ld)%s, buff=%s, size=%s", issuer->get_pid(), MC_smx_actor_get_name(issuer), p, bs); xbt_free(bs); xbt_free(p); break; @@ -225,11 +225,11 @@ std::string simgrid::mc::request_to_string(smx_simcall_t req, int value, simgrid type = "iRecv"; char* p = pointer_to_string(simcall_comm_irecv__get__dst_buff(req)); char* bs = buff_size_to_string(size); - if (issuer->host_) - args = bprintf("dst=(%ld)%s (%s), buff=%s, size=%s", issuer->pid_, MC_smx_actor_get_host_name(issuer), + if (issuer->get_host()) + args = bprintf("dst=(%ld)%s (%s), buff=%s, size=%s", issuer->get_pid(), MC_smx_actor_get_host_name(issuer), MC_smx_actor_get_name(issuer), p, bs); else - args = bprintf("dst=(%ld)%s, buff=%s, size=%s", issuer->pid_, MC_smx_actor_get_name(issuer), p, bs); + args = bprintf("dst=(%ld)%s, buff=%s, size=%s", issuer->get_pid(), MC_smx_actor_get_name(issuer), p, bs); xbt_free(bs); xbt_free(p); break; @@ -259,9 +259,9 @@ std::string simgrid::mc::request_to_string(smx_simcall_t req, int value, simgrid smx_actor_t src_proc = mc_model_checker->process().resolveActor(simgrid::mc::remote(act->src_actor_.get())); smx_actor_t dst_proc = mc_model_checker->process().resolveActor(simgrid::mc::remote(act->dst_actor_.get())); args = - bprintf("comm=%s [(%ld)%s (%s)-> (%ld)%s (%s)]", p, src_proc ? src_proc->pid_ : 0, + bprintf("comm=%s [(%ld)%s (%s)-> (%ld)%s (%s)]", p, src_proc ? src_proc->get_pid() : 0, src_proc ? MC_smx_actor_get_host_name(src_proc) : "", src_proc ? MC_smx_actor_get_name(src_proc) : "", - dst_proc ? dst_proc->pid_ : 0, dst_proc ? MC_smx_actor_get_host_name(dst_proc) : "", + dst_proc ? dst_proc->get_pid() : 0, dst_proc ? MC_smx_actor_get_host_name(dst_proc) : "", dst_proc ? MC_smx_actor_get_name(dst_proc) : ""); } xbt_free(p); @@ -291,8 +291,8 @@ std::string simgrid::mc::request_to_string(smx_simcall_t req, int value, simgrid smx_actor_t src_proc = mc_model_checker->process().resolveActor(simgrid::mc::remote(act->src_actor_.get())); smx_actor_t dst_proc = mc_model_checker->process().resolveActor(simgrid::mc::remote(act->dst_actor_.get())); - args = bprintf("comm=%s [(%ld)%s (%s) -> (%ld)%s (%s)]", p, src_proc->pid_, MC_smx_actor_get_name(src_proc), - MC_smx_actor_get_host_name(src_proc), dst_proc->pid_, MC_smx_actor_get_name(dst_proc), + args = bprintf("comm=%s [(%ld)%s (%s) -> (%ld)%s (%s)]", p, src_proc->get_pid(), MC_smx_actor_get_name(src_proc), + MC_smx_actor_get_host_name(src_proc), dst_proc->get_pid(), MC_smx_actor_get_name(dst_proc), MC_smx_actor_get_host_name(dst_proc)); } xbt_free(p); @@ -344,11 +344,11 @@ std::string simgrid::mc::request_to_string(smx_simcall_t req, int value, simgrid ? simcall_mutex_lock__get__mutex(req) : simcall_mutex_trylock__get__mutex(req) )); - args = - bprintf("locked = %d, owner = %d, sleeping = n/a", mutex.getBuffer()->locked, - mutex.getBuffer()->owner != nullptr - ? (int)mc_model_checker->process().resolveActor(simgrid::mc::remote(mutex.getBuffer()->owner))->pid_ - : -1); + args = bprintf( + "locked = %d, owner = %d, sleeping = n/a", mutex.getBuffer()->locked, + mutex.getBuffer()->owner != nullptr + ? (int)mc_model_checker->process().resolveActor(simgrid::mc::remote(mutex.getBuffer()->owner))->get_pid() + : -1); break; } @@ -365,10 +365,10 @@ std::string simgrid::mc::request_to_string(smx_simcall_t req, int value, simgrid std::string str; if (args != nullptr) - str = simgrid::xbt::string_printf("[(%ld)%s (%s)] %s(%s)", issuer->pid_, MC_smx_actor_get_host_name(issuer), + str = simgrid::xbt::string_printf("[(%ld)%s (%s)] %s(%s)", issuer->get_pid(), MC_smx_actor_get_host_name(issuer), MC_smx_actor_get_name(issuer), type, args); else - str = simgrid::xbt::string_printf("[(%ld)%s (%s)] %s ", issuer->pid_, MC_smx_actor_get_host_name(issuer), + str = simgrid::xbt::string_printf("[(%ld)%s (%s)] %s ", issuer->get_pid(), MC_smx_actor_get_host_name(issuer), MC_smx_actor_get_name(issuer), type); xbt_free(args); return str; @@ -436,25 +436,26 @@ std::string request_get_dot_output(smx_simcall_t req, int value) switch (req->call) { case SIMCALL_COMM_ISEND: - if (issuer->host_) - label = simgrid::xbt::string_printf("[(%ld)%s] iSend", issuer->pid_, MC_smx_actor_get_host_name(issuer)); + if (issuer->get_host()) + label = simgrid::xbt::string_printf("[(%ld)%s] iSend", issuer->get_pid(), MC_smx_actor_get_host_name(issuer)); else - label = bprintf("[(%ld)] iSend", issuer->pid_); + label = bprintf("[(%ld)] iSend", issuer->get_pid()); break; case SIMCALL_COMM_IRECV: - if (issuer->host_) - label = simgrid::xbt::string_printf("[(%ld)%s] iRecv", issuer->pid_, MC_smx_actor_get_host_name(issuer)); + if (issuer->get_host()) + label = simgrid::xbt::string_printf("[(%ld)%s] iRecv", issuer->get_pid(), MC_smx_actor_get_host_name(issuer)); else - label = simgrid::xbt::string_printf("[(%ld)] iRecv", issuer->pid_); + label = simgrid::xbt::string_printf("[(%ld)] iRecv", issuer->get_pid()); break; case SIMCALL_COMM_WAIT: if (value == -1) { - if (issuer->host_) - label = simgrid::xbt::string_printf("[(%ld)%s] WaitTimeout", issuer->pid_, MC_smx_actor_get_host_name(issuer)); + if (issuer->get_host()) + label = + simgrid::xbt::string_printf("[(%ld)%s] WaitTimeout", issuer->get_pid(), MC_smx_actor_get_host_name(issuer)); else - label = simgrid::xbt::string_printf("[(%ld)] WaitTimeout", issuer->pid_); + label = simgrid::xbt::string_printf("[(%ld)] WaitTimeout", issuer->get_pid()); } else { simgrid::kernel::activity::ActivityImpl* remote_act = simcall_comm_wait__getraw__comm(req); simgrid::mc::Remote temp_comm; @@ -464,13 +465,13 @@ std::string request_get_dot_output(smx_simcall_t req, int value) smx_actor_t src_proc = mc_model_checker->process().resolveActor(simgrid::mc::remote(comm->src_actor_.get())); smx_actor_t dst_proc = mc_model_checker->process().resolveActor(simgrid::mc::remote(comm->dst_actor_.get())); - if (issuer->host_) - label = simgrid::xbt::string_printf("[(%ld)%s] Wait [(%ld)->(%ld)]", issuer->pid_, - MC_smx_actor_get_host_name(issuer), src_proc ? src_proc->pid_ : 0, - dst_proc ? dst_proc->pid_ : 0); + if (issuer->get_host()) + label = simgrid::xbt::string_printf("[(%ld)%s] Wait [(%ld)->(%ld)]", issuer->get_pid(), + MC_smx_actor_get_host_name(issuer), src_proc ? src_proc->get_pid() : 0, + dst_proc ? dst_proc->get_pid() : 0); else - label = simgrid::xbt::string_printf("[(%ld)] Wait [(%ld)->(%ld)]", issuer->pid_, src_proc ? src_proc->pid_ : 0, - dst_proc ? dst_proc->pid_ : 0); + label = simgrid::xbt::string_printf("[(%ld)] Wait [(%ld)->(%ld)]", issuer->get_pid(), + src_proc ? src_proc->get_pid() : 0, dst_proc ? dst_proc->get_pid() : 0); } break; @@ -480,15 +481,17 @@ std::string request_get_dot_output(smx_simcall_t req, int value) mc_model_checker->process().read(temp_comm, remote(static_cast(remote_act))); simgrid::kernel::activity::CommImpl* comm = temp_comm.getBuffer(); if (comm->src_actor_.get() == nullptr || comm->dst_actor_.get() == nullptr) { - if (issuer->host_) - label = simgrid::xbt::string_printf("[(%ld)%s] Test FALSE", issuer->pid_, MC_smx_actor_get_host_name(issuer)); + if (issuer->get_host()) + label = + simgrid::xbt::string_printf("[(%ld)%s] Test FALSE", issuer->get_pid(), MC_smx_actor_get_host_name(issuer)); else - label = bprintf("[(%ld)] Test FALSE", issuer->pid_); + label = bprintf("[(%ld)] Test FALSE", issuer->get_pid()); } else { - if (issuer->host_) - label = simgrid::xbt::string_printf("[(%ld)%s] Test TRUE", issuer->pid_, MC_smx_actor_get_host_name(issuer)); + if (issuer->get_host()) + label = + simgrid::xbt::string_printf("[(%ld)%s] Test TRUE", issuer->get_pid(), MC_smx_actor_get_host_name(issuer)); else - label = simgrid::xbt::string_printf("[(%ld)] Test TRUE", issuer->pid_); + label = simgrid::xbt::string_printf("[(%ld)] Test TRUE", issuer->get_pid()); } break; } @@ -496,53 +499,53 @@ std::string request_get_dot_output(smx_simcall_t req, int value) case SIMCALL_COMM_WAITANY: { unsigned long comms_size = read_length( mc_model_checker->process(), remote(simcall_comm_waitany__get__comms(req))); - if (issuer->host_) - label = simgrid::xbt::string_printf("[(%ld)%s] WaitAny [%d of %lu]", issuer->pid_, + if (issuer->get_host()) + label = simgrid::xbt::string_printf("[(%ld)%s] WaitAny [%d of %lu]", issuer->get_pid(), MC_smx_actor_get_host_name(issuer), value + 1, comms_size); else - label = simgrid::xbt::string_printf("[(%ld)] WaitAny [%d of %lu]", issuer->pid_, value + 1, comms_size); + label = simgrid::xbt::string_printf("[(%ld)] WaitAny [%d of %lu]", issuer->get_pid(), value + 1, comms_size); break; } case SIMCALL_COMM_TESTANY: if (value == -1) { - if (issuer->host_) - label = - simgrid::xbt::string_printf("[(%ld)%s] TestAny FALSE", issuer->pid_, MC_smx_actor_get_host_name(issuer)); + if (issuer->get_host()) + label = simgrid::xbt::string_printf("[(%ld)%s] TestAny FALSE", issuer->get_pid(), + MC_smx_actor_get_host_name(issuer)); else - label = simgrid::xbt::string_printf("[(%ld)] TestAny FALSE", issuer->pid_); + label = simgrid::xbt::string_printf("[(%ld)] TestAny FALSE", issuer->get_pid()); } else { - if (issuer->host_) - label = simgrid::xbt::string_printf("[(%ld)%s] TestAny TRUE [%d of %lu]", issuer->pid_, + if (issuer->get_host()) + label = simgrid::xbt::string_printf("[(%ld)%s] TestAny TRUE [%d of %lu]", issuer->get_pid(), MC_smx_actor_get_host_name(issuer), value + 1, simcall_comm_testany__get__count(req)); else - label = simgrid::xbt::string_printf("[(%ld)] TestAny TRUE [%d of %lu]", issuer->pid_, value + 1, + label = simgrid::xbt::string_printf("[(%ld)] TestAny TRUE [%d of %lu]", issuer->get_pid(), value + 1, simcall_comm_testany__get__count(req)); } break; case SIMCALL_MUTEX_TRYLOCK: - label = simgrid::xbt::string_printf("[(%ld)] Mutex TRYLOCK", issuer->pid_); + label = simgrid::xbt::string_printf("[(%ld)] Mutex TRYLOCK", issuer->get_pid()); break; case SIMCALL_MUTEX_LOCK: - label = simgrid::xbt::string_printf("[(%ld)] Mutex LOCK", issuer->pid_); + label = simgrid::xbt::string_printf("[(%ld)] Mutex LOCK", issuer->get_pid()); break; case SIMCALL_MC_RANDOM: - if (issuer->host_) - label = simgrid::xbt::string_printf("[(%ld)%s] MC_RANDOM (%d)", issuer->pid_, MC_smx_actor_get_host_name(issuer), - value); + if (issuer->get_host()) + label = simgrid::xbt::string_printf("[(%ld)%s] MC_RANDOM (%d)", issuer->get_pid(), + MC_smx_actor_get_host_name(issuer), value); else - label = simgrid::xbt::string_printf("[(%ld)] MC_RANDOM (%d)", issuer->pid_, value); + label = simgrid::xbt::string_printf("[(%ld)] MC_RANDOM (%d)", issuer->get_pid(), value); break; default: THROW_UNIMPLEMENTED; } - const char* color = get_color(issuer->pid_ - 1); + const char* color = get_color(issuer->get_pid() - 1); return simgrid::xbt::string_printf( "label = \"%s\", color = %s, fontcolor = %s", label.c_str(), color, color); diff --git a/src/mc/mc_smx.cpp b/src/mc/mc_smx.cpp index 8398078b03..60d5ae5c8b 100644 --- a/src/mc/mc_smx.cpp +++ b/src/mc/mc_smx.cpp @@ -117,7 +117,7 @@ smx_actor_t MC_smx_simcall_get_issuer(s_smx_simcall const* req) const char* MC_smx_actor_get_host_name(smx_actor_t actor) { if (mc_model_checker == nullptr) - return actor->host_->get_cname(); + return actor->get_host()->get_cname(); simgrid::mc::RemoteClient* process = &mc_model_checker->process(); @@ -141,7 +141,7 @@ const char* MC_smx_actor_get_host_name(smx_actor_t actor) // Read the simgrid::xbt::string in the MCed process: simgrid::mc::ActorInformation* info = actor_info_cast(actor); - auto remote_string_address = remote((simgrid::xbt::string_data*)((char*)actor->host_ + offset)); + auto remote_string_address = remote((simgrid::xbt::string_data*)((char*)actor->get_host() + offset)); simgrid::xbt::string_data remote_string = process->read(remote_string_address); char hostname[remote_string.len]; process->read_bytes(hostname, remote_string.len + 1, remote(remote_string.data)); diff --git a/src/mc/mc_state.cpp b/src/mc/mc_state.cpp index a689df8d19..7095aa97b5 100644 --- a/src/mc/mc_state.cpp +++ b/src/mc/mc_state.cpp @@ -63,7 +63,7 @@ Transition State::getTransition() const static inline smx_simcall_t MC_state_get_request_for_process(simgrid::mc::State* state, smx_actor_t actor) { /* reset the outgoing transition */ - simgrid::mc::ProcessState* procstate = &state->actorStates[actor->pid_]; + simgrid::mc::ProcessState* procstate = &state->actorStates[actor->get_pid()]; state->transition.pid = -1; state->transition.argument = -1; state->executed_req.call = SIMCALL_NONE; @@ -146,7 +146,7 @@ static inline smx_simcall_t MC_state_get_request_for_process(simgrid::mc::State* if (not req) return nullptr; - state->transition.pid = actor->pid_; + state->transition.pid = actor->get_pid(); state->executed_req = *req; // Fetch the data of the request and translate it: state->internal_req = *req; @@ -206,7 +206,7 @@ smx_simcall_t MC_state_get_request(simgrid::mc::State* state) { for (auto& actor : mc_model_checker->process().actors()) { /* Only consider the actors that were marked as interleaving by the checker algorithm */ - if (not state->actorStates[actor.copy.getBuffer()->pid_].isTodo()) + if (not state->actorStates[actor.copy.getBuffer()->get_pid()].isTodo()) continue; smx_simcall_t res = MC_state_get_request_for_process(state, actor.copy.getBuffer()); diff --git a/src/mc/mc_state.hpp b/src/mc/mc_state.hpp index fcde776a7d..bfdce906d9 100644 --- a/src/mc/mc_state.hpp +++ b/src/mc/mc_state.hpp @@ -130,7 +130,7 @@ public: explicit State(unsigned long state_number); std::size_t interleaveSize() const; - void addInterleavingSet(smx_actor_t actor) { this->actorStates[actor->pid_].consider(); } + void addInterleavingSet(smx_actor_t actor) { this->actorStates[actor->get_pid()].consider(); } Transition getTransition() const; }; } diff --git a/src/mc/remote/Client.cpp b/src/mc/remote/Client.cpp index ffbbfae6ab..7cbff1f4b0 100644 --- a/src/mc/remote/Client.cpp +++ b/src/mc/remote/Client.cpp @@ -249,7 +249,7 @@ void Client::declareStack(void* stack, size_t size, smx_actor_t process, ucontex region.block = ((char*)stack - (char*)heap->heapbase) / BLOCKSIZE + 1; #if HAVE_SMPI if (smpi_privatize_global_variables == SmpiPrivStrategies::MMAP && process) - region.process_index = process->pid_ - 1; + region.process_index = process->get_pid() - 1; else #endif region.process_index = -1; diff --git a/src/mc/sosp/mc_checkpoint.cpp b/src/mc/sosp/mc_checkpoint.cpp index 4f8585d181..8a20452067 100644 --- a/src/mc/sosp/mc_checkpoint.cpp +++ b/src/mc/sosp/mc_checkpoint.cpp @@ -504,7 +504,7 @@ std::shared_ptr take_snapshot(int num_state) std::shared_ptr snapshot = std::make_shared(mc_process, num_state); for (auto const& p : mc_model_checker->process().actors()) - snapshot->enabled_processes.insert(p.copy.getBuffer()->pid_); + snapshot->enabled_processes.insert(p.copy.getBuffer()->get_pid()); snapshot_handle_ignore(snapshot.get()); diff --git a/src/msg/msg_process.cpp b/src/msg/msg_process.cpp index fa1c3b8353..dd37f44d0f 100644 --- a/src/msg/msg_process.cpp +++ b/src/msg/msg_process.cpp @@ -186,7 +186,7 @@ int MSG_process_get_number() int MSG_process_self_PID() { smx_actor_t self = SIMIX_process_self(); - return self == nullptr ? 0 : self->pid_; + return self == nullptr ? 0 : self->get_pid(); } /** @brief Return the PPID of the current process. diff --git a/src/plugins/vm/VirtualMachineImpl.cpp b/src/plugins/vm/VirtualMachineImpl.cpp index b662d97fd0..727bc34691 100644 --- a/src/plugins/vm/VirtualMachineImpl.cpp +++ b/src/plugins/vm/VirtualMachineImpl.cpp @@ -173,7 +173,7 @@ void VirtualMachineImpl::suspend(smx_actor_t issuer) { if (get_state() != s4u::VirtualMachine::state::RUNNING) THROWF(vm_error, 0, "Cannot suspend VM %s: it is not running.", piface_->get_cname()); - if (issuer->host_ == piface_) + if (issuer->get_host() == piface_) THROWF(vm_error, 0, "Actor %s cannot suspend the VM %s in which it runs", issuer->get_cname(), piface_->get_cname()); @@ -240,7 +240,7 @@ void VirtualMachineImpl::shutdown(smx_actor_t issuer) for (auto& smx_process : process_list_) { XBT_DEBUG("kill %s@%s on behalf of %s which shutdown that VM.", smx_process.get_cname(), - smx_process.host_->get_cname(), issuer->get_cname()); + smx_process.get_host()->get_cname(), issuer->get_cname()); issuer->kill(&smx_process); } diff --git a/src/s4u/s4u_Actor.cpp b/src/s4u/s4u_Actor.cpp index 1b92776b39..7619d44bc6 100644 --- a/src/s4u/s4u_Actor.cpp +++ b/src/s4u/s4u_Actor.cpp @@ -75,12 +75,12 @@ void Actor::join(double timeout) void Actor::set_auto_restart(bool autorestart) { simgrid::simix::simcall([this, autorestart]() { - xbt_assert(autorestart && not pimpl_->auto_restart_); // FIXME: handle all cases + xbt_assert(autorestart && not pimpl_->has_to_auto_restart()); // FIXME: handle all cases pimpl_->set_auto_restart(autorestart); - simgrid::kernel::actor::ProcessArg* arg = new simgrid::kernel::actor::ProcessArg(pimpl_->host_, pimpl_); + simgrid::kernel::actor::ProcessArg* arg = new simgrid::kernel::actor::ProcessArg(pimpl_->get_host(), pimpl_); XBT_DEBUG("Adding Process %s to the actors_at_boot_ list of Host %s", arg->name.c_str(), arg->host->get_cname()); - pimpl_->host_->pimpl_->actors_at_boot_.emplace_back(arg); + pimpl_->get_host()->pimpl_->actors_at_boot_.emplace_back(arg); }); } @@ -115,7 +115,7 @@ void Actor::migrate(Host* new_host) s4u::Host* Actor::get_host() { - return this->pimpl_->host_; + return this->pimpl_->get_host(); } void Actor::daemonize() @@ -140,12 +140,12 @@ const char* Actor::get_cname() const aid_t Actor::get_pid() const { - return this->pimpl_->pid_; + return this->pimpl_->get_pid(); } aid_t Actor::get_ppid() const { - return this->pimpl_->ppid_; + return this->pimpl_->get_ppid(); } void Actor::suspend() @@ -162,7 +162,7 @@ void Actor::resume() bool Actor::is_suspended() { - return simgrid::simix::simcall([this] { return pimpl_->suspended_; }); + return simgrid::simix::simcall([this] { return pimpl_->is_suspended(); }); } void Actor::set_kill_time(double kill_time) @@ -173,7 +173,7 @@ void Actor::set_kill_time(double kill_time) /** @brief Get the kill time of an actor(or 0 if unset). */ double Actor::get_kill_time() { - return SIMIX_timer_get_date(pimpl_->kill_timer); + return pimpl_->get_kill_time(); } void Actor::kill(aid_t pid) // deprecated @@ -356,12 +356,12 @@ ExecPtr exec_async(double flops) aid_t get_pid() { - return SIMIX_process_self()->pid_; + return SIMIX_process_self()->get_pid(); } aid_t get_ppid() { - return SIMIX_process_self()->ppid_; + return SIMIX_process_self()->get_ppid(); } std::string get_name() @@ -376,7 +376,7 @@ const char* get_cname() Host* get_host() { - return SIMIX_process_self()->host_; + return SIMIX_process_self()->get_host(); } void suspend() diff --git a/src/s4u/s4u_Host.cpp b/src/s4u/s4u_Host.cpp index 572ee4ada9..16f419a05b 100644 --- a/src/s4u/s4u_Host.cpp +++ b/src/s4u/s4u_Host.cpp @@ -76,10 +76,10 @@ Host* Host::by_name_or_null(const std::string& name) Host* Host::current() { - smx_actor_t smx_proc = SIMIX_process_self(); - if (smx_proc == nullptr) + smx_actor_t self = SIMIX_process_self(); + if (self == nullptr) xbt_die("Cannot call Host::current() from the maestro context"); - return smx_proc->host_; + return self->get_host(); } void Host::turn_on() @@ -636,7 +636,7 @@ void sg_host_get_actor_list(sg_host_t host, xbt_dynar_t whereto) sg_host_t sg_host_self() { smx_actor_t process = SIMIX_process_self(); - return (process == nullptr) ? nullptr : process->host_; + return (process == nullptr) ? nullptr : process->get_host(); } double sg_host_load(sg_host_t host) diff --git a/src/simix/ActorImpl.cpp b/src/simix/ActorImpl.cpp index 5c38159d3e..67dbfcdffc 100644 --- a/src/simix/ActorImpl.cpp +++ b/src/simix/ActorImpl.cpp @@ -60,9 +60,9 @@ void SIMIX_process_cleanup(smx_actor_t process) simix_global->mutex.lock(); - simix_global->process_list.erase(process->pid_); - if (process->host_ && process->host_process_list_hook.is_linked()) - simgrid::xbt::intrusive_erase(process->host_->pimpl_->process_list_, *process); + simix_global->process_list.erase(process->get_pid()); + if (process->get_host() && process->host_process_list_hook.is_linked()) + simgrid::xbt::intrusive_erase(process->get_host()->pimpl_->process_list_, *process); if (not process->smx_destroy_list_hook.is_linked()) { #if SIMGRID_HAVE_MC xbt_dynar_push_as(simix_global->dead_actors_vector, smx_actor_t, process); @@ -78,7 +78,7 @@ namespace simgrid { namespace kernel { namespace actor { -ActorImpl::ActorImpl(simgrid::xbt::string name, simgrid::s4u::Host* host) : name_(name), host_(host), piface_(this) +ActorImpl::ActorImpl(simgrid::xbt::string name, s4u::Host* host) : host_(host), name_(name), piface_(this) { pid_ = simix_process_maxpid++; simcall.issuer = this; @@ -116,7 +116,7 @@ void ActorImpl::exit() } else if (comm != nullptr) { comms.remove(waiting_synchro); comm->cancel(); - // Remove first occurrence of &process->simcall: + // Remove first occurrence of &actor->simcall: auto i = boost::range::find(waiting_synchro->simcalls_, &simcall); if (i != waiting_synchro->simcalls_.end()) waiting_synchro->simcalls_.remove(&simcall); @@ -138,10 +138,10 @@ void ActorImpl::exit() } } -void ActorImpl::kill(smx_actor_t actor) +void ActorImpl::kill(ActorImpl* actor) { if (actor->finished_) { - XBT_DEBUG("Ignoring request to kill process %s@%s that is already dead", actor->get_cname(), + XBT_DEBUG("Ignoring request to kill actor %s@%s that is already dead", actor->get_cname(), actor->host_->get_cname()); return; } @@ -170,13 +170,18 @@ void ActorImpl::set_kill_time(double kill_time) { if (kill_time <= SIMIX_get_clock()) return; - XBT_DEBUG("Set kill time %f for process %s@%s", kill_time, get_cname(), host_->get_cname()); + XBT_DEBUG("Set kill time %f for actor %s@%s", kill_time, get_cname(), host_->get_cname()); kill_timer = SIMIX_timer_set(kill_time, [this] { this->exit(); kill_timer = nullptr; }); } +double ActorImpl::get_kill_time() +{ + return SIMIX_timer_get_date(kill_timer); +} + static void dying_daemon(int /*exit_status*/, void* data) { std::vector* vect = &simix_global->daemons; @@ -226,7 +231,7 @@ void ActorImpl::yield() } } -/** This process will be terminated automatically when the last non-daemon process finishes */ +/** This actor will be terminated automatically when the last non-daemon actor finishes */ void ActorImpl::daemonize() { if (not daemon_) { @@ -236,17 +241,17 @@ void ActorImpl::daemonize() } } -simgrid::s4u::Actor* ActorImpl::restart() +s4u::Actor* ActorImpl::restart() { - XBT_DEBUG("Restarting process %s on %s", get_cname(), host_->get_cname()); + XBT_DEBUG("Restarting actor %s on %s", get_cname(), host_->get_cname()); - // retrieve the arguments of the old process - simgrid::kernel::actor::ProcessArg arg = ProcessArg(host_, this); + // retrieve the arguments of the old actor + ProcessArg arg = ProcessArg(host_, this); - // kill the old process + // kill the old actor (this == simix_global->maestro_process) ? this->exit() : SIMIX_process_self()->kill(this); - // start the new process + // start the new actor ActorImplPtr actor = ActorImpl::create(arg.name, std::move(arg.code), arg.data, arg.host, arg.properties.get(), nullptr); actor->set_kill_time(arg.kill_time); @@ -255,7 +260,7 @@ simgrid::s4u::Actor* ActorImpl::restart() return actor->ciface(); } -smx_activity_t ActorImpl::suspend(ActorImpl* issuer) +activity::ActivityImplPtr ActorImpl::suspend(ActorImpl* issuer) { if (suspended_) { XBT_DEBUG("Actor '%s' is already suspended", get_cname()); @@ -296,9 +301,9 @@ void ActorImpl::resume() XBT_OUT(); } -smx_activity_t ActorImpl::join(smx_actor_t actor, double timeout) +activity::ActivityImplPtr ActorImpl::join(smx_actor_t actor, double timeout) { - smx_activity_t res = this->sleep(timeout); + activity::ActivityImplPtr res = this->sleep(timeout); intrusive_ptr_add_ref(res.get()); SIMIX_process_on_exit(actor, [](int, void* arg) { @@ -310,7 +315,8 @@ smx_activity_t ActorImpl::join(smx_actor_t actor, double timeout) res.get()); return res; } -smx_activity_t ActorImpl::sleep(double duration) + +activity::ActivityImplPtr ActorImpl::sleep(double duration) { if (not host_->is_on()) throw_exception(std::make_exception_ptr(simgrid::HostFailureException( @@ -330,20 +336,17 @@ void ActorImpl::throw_exception(std::exception_ptr e) /* cancel the blocking synchro if any */ if (waiting_synchro) { - simgrid::kernel::activity::ExecImplPtr exec = - boost::dynamic_pointer_cast(waiting_synchro); + activity::ExecImplPtr exec = boost::dynamic_pointer_cast(waiting_synchro); if (exec != nullptr) exec->cancel(); - simgrid::kernel::activity::CommImplPtr comm = - boost::dynamic_pointer_cast(waiting_synchro); + activity::CommImplPtr comm = boost::dynamic_pointer_cast(waiting_synchro); if (comm != nullptr) { comms.remove(comm); comm->cancel(); } - simgrid::kernel::activity::SleepImplPtr sleep = - boost::dynamic_pointer_cast(waiting_synchro); + activity::SleepImplPtr sleep = boost::dynamic_pointer_cast(waiting_synchro); if (sleep != nullptr) { SIMIX_process_sleep_destroy(waiting_synchro); if (std::find(begin(simix_global->actors_to_run), end(simix_global->actors_to_run), this) == @@ -354,14 +357,12 @@ void ActorImpl::throw_exception(std::exception_ptr e) } } - simgrid::kernel::activity::RawImplPtr raw = - boost::dynamic_pointer_cast(waiting_synchro); + activity::RawImplPtr raw = boost::dynamic_pointer_cast(waiting_synchro); if (raw != nullptr) { SIMIX_synchro_stop_waiting(this, &simcall); } - simgrid::kernel::activity::IoImplPtr io = - boost::dynamic_pointer_cast(waiting_synchro); + activity::IoImplPtr io = boost::dynamic_pointer_cast(waiting_synchro); if (io != nullptr) { io->cancel(); } @@ -369,15 +370,15 @@ void ActorImpl::throw_exception(std::exception_ptr e) waiting_synchro = nullptr; } -void ActorImpl::set_host(sg_host_t dest) +void ActorImpl::set_host(s4u::Host* dest) { simgrid::xbt::intrusive_erase(host_->pimpl_->process_list_, *this); host_ = dest; dest->pimpl_->process_list_.push_back(*this); } -ActorImplPtr ActorImpl::create(std::string name, simgrid::simix::ActorCode code, void* data, simgrid::s4u::Host* host, - std::unordered_map* properties, smx_actor_t parent_actor) +ActorImplPtr ActorImpl::create(std::string name, simix::ActorCode code, void* data, s4u::Host* host, + std::unordered_map* properties, ActorImpl* parent_actor) { XBT_DEBUG("Start actor %s@'%s'", name.c_str(), host->get_cname()); @@ -387,7 +388,7 @@ ActorImplPtr ActorImpl::create(std::string name, simgrid::simix::ActorCode code, return nullptr; } - ActorImpl* actor = new simgrid::kernel::actor::ActorImpl(simgrid::xbt::string(name), host); + ActorImpl* actor = new ActorImpl(simgrid::xbt::string(name), host); xbt_assert(code && host != nullptr, "Invalid parameters"); /* actor data */ @@ -395,7 +396,7 @@ ActorImplPtr ActorImpl::create(std::string name, simgrid::simix::ActorCode code, actor->code = code; if (parent_actor != nullptr) - actor->ppid_ = parent_actor->pid_; + actor->set_ppid(parent_actor->get_pid()); XBT_VERB("Create context %s", actor->get_cname()); actor->context_ = SIMIX_context_new(std::move(code), &SIMIX_process_cleanup, actor); @@ -405,30 +406,30 @@ ActorImplPtr ActorImpl::create(std::string name, simgrid::simix::ActorCode code, for (auto const& kv : *properties) actor->set_property(kv.first, kv.second); - /* Add the process to its host's process list */ + /* Add the actor to its host's actor list */ host->pimpl_->process_list_.push_back(*actor); XBT_DEBUG("Start context '%s'", actor->get_cname()); - /* Now insert it in the global process list and in the process to run list */ - simix_global->process_list[actor->pid_] = actor; + /* Now insert it in the global actor list and in the actor to run list */ + simix_global->process_list[actor->get_pid()] = actor; XBT_DEBUG("Inserting [%p] %s(%s) in the to_run list", actor, actor->get_cname(), host->get_cname()); simix_global->actors_to_run.push_back(actor); intrusive_ptr_add_ref(actor); /* The on_creation() signal must be delayed until there, where the pid and everything is set */ - simgrid::s4u::Actor::on_creation(actor->iface()); + s4u::Actor::on_creation(actor->iface()); return ActorImplPtr(actor); } -void create_maestro(simgrid::simix::ActorCode code) +void create_maestro(simix::ActorCode code) { - /* Create maestro process and initialize it */ - smx_actor_t maestro = new simgrid::kernel::actor::ActorImpl(simgrid::xbt::string(""), /*host*/ nullptr); + /* Create maestro actor and initialize it */ + ActorImpl* maestro = new ActorImpl(xbt::string(""), /*host*/ nullptr); if (not code) { - maestro->context_ = SIMIX_context_new(simgrid::simix::ActorCode(), nullptr, maestro); + maestro->context_ = SIMIX_context_new(simix::ActorCode(), nullptr, maestro); } else { maestro->context_ = simix_global->context_factory->create_maestro(code, maestro); } @@ -461,7 +462,7 @@ smx_actor_t SIMIX_process_attach(const char* name, void* data, const char* hostn actor->code = nullptr; if (parent_process != nullptr) - actor->ppid_ = parent_process->pid_; + actor->set_ppid(parent_process->get_pid()); XBT_VERB("Create context %s", actor->get_cname()); xbt_assert(simix_global != nullptr, "simix is not initialized, please call MSG_init first"); @@ -476,7 +477,7 @@ smx_actor_t SIMIX_process_attach(const char* name, void* data, const char* hostn host->pimpl_->process_list_.push_back(*actor); /* Now insert it in the global process list and in the process to run list */ - simix_global->process_list[actor->pid_] = actor; + simix_global->process_list[actor->get_pid()] = actor; XBT_DEBUG("Inserting [%p] %s(%s) in the to_run list", actor, actor->get_cname(), host->get_cname()); simix_global->actors_to_run.push_back(actor); intrusive_ptr_add_ref(actor); @@ -509,7 +510,7 @@ void SIMIX_process_throw(smx_actor_t actor, xbt_errcat_t cat, int value, const c { SMX_EXCEPTION(actor, cat, value, msg); - if (actor->suspended_) + if (actor->is_suspended()) actor->resume(); /* cancel the blocking synchro if any */ diff --git a/src/simix/ActorImpl.hpp b/src/simix/ActorImpl.hpp index 404278f70e..1667712db0 100644 --- a/src/simix/ActorImpl.hpp +++ b/src/simix/ActorImpl.hpp @@ -23,33 +23,49 @@ namespace simgrid { namespace kernel { namespace actor { -class ActorImpl : public simgrid::surf::PropertyHolder { +class ActorImpl : public surf::PropertyHolder { + s4u::Host* host_ = nullptr; /* the host on which the actor is running */ + void* userdata_ = nullptr; /* kept for compatibility, it should be replaced with moddata */ + aid_t pid_ = 0; + aid_t ppid_ = -1; + bool daemon_ = false; /* Daemon actors are automatically killed when the last non-daemon leaves */ + bool auto_restart_ = false; + public: - ActorImpl(simgrid::xbt::string name, simgrid::s4u::Host* host); + xbt::string name_; + ActorImpl(xbt::string name, s4u::Host* host); ~ActorImpl(); - void set_auto_restart(bool autorestart) { auto_restart_ = autorestart; } + double get_kill_time(); void set_kill_time(double kill_time); boost::intrusive::list_member_hook<> host_process_list_hook; /* simgrid::simix::Host::process_list */ boost::intrusive::list_member_hook<> smx_destroy_list_hook; /* simix_global->actors_to_destroy */ boost::intrusive::list_member_hook<> smx_synchro_hook; /* {mutex,cond,sem}->sleeping */ - aid_t pid_ = 0; - aid_t ppid_ = -1; - simgrid::xbt::string name_; - const simgrid::xbt::string& get_name() const { return name_; } + const xbt::string& get_name() const { return name_; } const char* get_cname() const { return name_.c_str(); } - s4u::Host* host_ = nullptr; /* the host on which the process is running */ - smx_context_t context_ = nullptr; /* the context (uctx/raw/thread) that executes the user function */ + + // Accessors to private fields + s4u::Host* get_host() { return host_; } + void set_host(s4u::Host* dest); + void* get_user_data() { return userdata_; } + void set_user_data(void* data) { userdata_ = data; } + aid_t get_pid() const { return pid_; } + aid_t get_ppid() const { return ppid_; } + void set_ppid(aid_t ppid) { ppid_ = ppid; } + bool is_daemon() { return daemon_; } /** Whether this actor has been daemonized */ + bool has_to_auto_restart() { return auto_restart_; } + void set_auto_restart(bool autorestart) { auto_restart_ = autorestart; } + + context::Context* context_ = nullptr; /* the context (uctx/raw/thread) that executes the user function */ std::exception_ptr exception_; - bool finished_ = false; - bool blocked_ = false; - bool suspended_ = false; - bool auto_restart_ = false; + bool finished_ = false; + bool blocked_ = false; /* FIXME this field is never set to true. Either use it or remove it. */ + bool suspended_ = false; - smx_activity_t waiting_synchro = nullptr; /* the current blocking synchro if any */ - std::list comms; /* the current non-blocking communication synchros */ + activity::ActivityImplPtr waiting_synchro = nullptr; /* the current blocking synchro if any */ + std::list comms; /* the current non-blocking communication synchros */ s_smx_simcall simcall; std::vector on_exit; /* list of functions executed when the process dies */ @@ -57,7 +73,6 @@ public: smx_timer_t kill_timer = nullptr; private: - void* userdata_ = nullptr; /* kept for compatibility, it should be replaced with moddata */ /* Refcounting */ std::atomic_int_fast32_t refcount_{0}; @@ -83,35 +98,27 @@ public: /* S4U/implem interfaces */ private: - simgrid::s4u::Actor piface_; // Our interface is part of ourselves + s4u::Actor piface_; // Our interface is part of ourselves public: - simgrid::s4u::ActorPtr iface() { return s4u::ActorPtr(&piface_); } - simgrid::s4u::Actor* ciface() { return &piface_; } + s4u::ActorPtr iface() { return s4u::ActorPtr(&piface_); } + s4u::Actor* ciface() { return &piface_; } - /* Daemon actors are automatically killed when the last non-daemon leaves */ -private: - bool daemon_ = false; -public: static ActorImplPtr create(std::string name, simix::ActorCode code, void* data, s4u::Host* host, - std::unordered_map* properties, smx_actor_t parent_actor); + std::unordered_map* properties, ActorImpl* parent_actor); void exit(); - void kill(smx_actor_t actor); + void kill(ActorImpl* actor); void kill_all(); void yield(); void daemonize(); - bool is_daemon() { return daemon_; } /** Whether this actor has been daemonized */ bool is_suspended() { return suspended_; } - simgrid::s4u::Actor* restart(); - smx_activity_t suspend(ActorImpl* issuer); + s4u::Actor* restart(); + activity::ActivityImplPtr suspend(ActorImpl* issuer); void resume(); - smx_activity_t join(smx_actor_t actor, double timeout); - smx_activity_t sleep(double duration); - void set_user_data(void* data) { userdata_ = data; } - void* get_user_data() { return userdata_; } + activity::ActivityImplPtr join(ActorImpl* actor, double timeout); + activity::ActivityImplPtr sleep(double duration); /** Ask the actor to throw an exception right away */ void throw_exception(std::exception_ptr e); - void set_host(sg_host_t dest); }; class ProcessArg { @@ -143,8 +150,8 @@ public: , code(std::move(actor->code)) , data(actor->get_user_data()) , host(host) - , kill_time(SIMIX_timer_get_date(actor->kill_timer)) - , auto_restart(actor->auto_restart_) + , kill_time(actor->get_kill_time()) + , auto_restart(actor->has_to_auto_restart()) , daemon_(actor->is_daemon()) { properties.reset(actor->get_properties(), [](decltype(actor->get_properties())) {}); @@ -157,12 +164,10 @@ typedef boost::intrusive::list code); -} +} // namespace actor } // namespace kernel } // namespace simgrid -typedef simgrid::kernel::actor::ActorImpl* smx_actor_t; - XBT_PRIVATE void SIMIX_process_cleanup(smx_actor_t arg); extern void (*SMPI_switch_data_segment)(simgrid::s4u::ActorPtr actor); diff --git a/src/simix/popping_generated.cpp b/src/simix/popping_generated.cpp index 28af3fdf56..c5cd0daebd 100644 --- a/src/simix/popping_generated.cpp +++ b/src/simix/popping_generated.cpp @@ -174,7 +174,7 @@ case SIMCALL_RUN_BLOCKING: break; case SIMCALL_NONE: THROWF(arg_error, 0, "Asked to do the noop syscall on %s@%s", simcall->issuer->get_cname(), - sg_host_get_name(simcall->issuer->host_)); + sg_host_get_name(simcall->issuer->get_host())); break; default: THROW_IMPOSSIBLE; diff --git a/src/simix/simcalls.py b/src/simix/simcalls.py index 508015c67b..44871e4d42 100755 --- a/src/simix/simcalls.py +++ b/src/simix/simcalls.py @@ -350,7 +350,7 @@ if __name__ == '__main__': fd.write(' break;\n') fd.write(' case SIMCALL_NONE:\n') fd.write(' THROWF(arg_error, 0, "Asked to do the noop syscall on %s@%s", simcall->issuer->get_cname(),\n') - fd.write(' sg_host_get_name(simcall->issuer->host_));\n') + fd.write(' sg_host_get_name(simcall->issuer->get_host()));\n') fd.write(' break;\n') fd.write(' default:\n') fd.write(' THROW_IMPOSSIBLE;\n') diff --git a/src/simix/smx_global.cpp b/src/simix/smx_global.cpp index ff85b0e7c1..99f9d1cec9 100644 --- a/src/simix/smx_global.cpp +++ b/src/simix/smx_global.cpp @@ -606,12 +606,13 @@ void SIMIX_display_process_status() if (boost::dynamic_pointer_cast(process->waiting_synchro) != nullptr) synchro_description = "I/O"; - XBT_INFO("Process %ld (%s@%s): waiting for %s synchro %p (%s) in state %d to finish", process->pid_, - process->get_cname(), process->host_->get_cname(), synchro_description, process->waiting_synchro.get(), - process->waiting_synchro->get_cname(), (int)process->waiting_synchro->state_); + XBT_INFO("Process %ld (%s@%s): waiting for %s synchro %p (%s) in state %d to finish", process->get_pid(), + process->get_cname(), process->get_host()->get_cname(), synchro_description, + process->waiting_synchro.get(), process->waiting_synchro->get_cname(), + (int)process->waiting_synchro->state_); } else { - XBT_INFO("Process %ld (%s@%s)", process->pid_, process->get_cname(), process->host_->get_cname()); + XBT_INFO("Process %ld (%s@%s)", process->get_pid(), process->get_cname(), process->get_host()->get_cname()); } } } diff --git a/src/simix/smx_host.cpp b/src/simix/smx_host.cpp index 02430211c0..33d574972f 100644 --- a/src/simix/smx_host.cpp +++ b/src/simix/smx_host.cpp @@ -105,7 +105,7 @@ void SIMIX_execution_finish(smx_activity_t synchro) break; case SIMIX_FAILED: - XBT_DEBUG("SIMIX_execution_finished: host '%s' failed", simcall->issuer->host_->get_cname()); + XBT_DEBUG("SIMIX_execution_finished: host '%s' failed", simcall->issuer->get_host()->get_cname()); simcall->issuer->context_->iwannadie = true; simcall->issuer->exception_ = std::make_exception_ptr(simgrid::HostFailureException(XBT_THROW_POINT, "Host failed")); @@ -130,7 +130,7 @@ void SIMIX_execution_finish(smx_activity_t synchro) simcall_execution_wait__set__result(simcall, exec->state_); /* Fail the process if the host is down */ - if (simcall->issuer->host_->is_on()) + if (simcall->issuer->get_host()->is_on()) SIMIX_simcall_answer(simcall); else simcall->issuer->context_->iwannadie = true; diff --git a/src/simix/smx_io.cpp b/src/simix/smx_io.cpp index 37ec6790ab..62e482f7c2 100644 --- a/src/simix/smx_io.cpp +++ b/src/simix/smx_io.cpp @@ -55,7 +55,7 @@ void SIMIX_io_finish(smx_activity_t synchro) } simcall->issuer->waiting_synchro = nullptr; - if (simcall->issuer->host_->is_on()) + if (simcall->issuer->get_host()->is_on()) SIMIX_simcall_answer(simcall); else simcall->issuer->context_->iwannadie = true; diff --git a/src/simix/smx_network.cpp b/src/simix/smx_network.cpp index 5314480de5..828235a065 100644 --- a/src/simix/smx_network.cpp +++ b/src/simix/smx_network.cpp @@ -227,7 +227,7 @@ void simcall_HANDLER_comm_wait(smx_simcall_t simcall, smx_activity_t synchro, do if (synchro->state_ != SIMIX_WAITING && synchro->state_ != SIMIX_RUNNING) { SIMIX_comm_finish(synchro); } else { /* we need a sleep action (even when there is no timeout) to be notified of host failures */ - simgrid::kernel::resource::Action* sleep = simcall->issuer->host_->pimpl_cpu->sleep(timeout); + simgrid::kernel::resource::Action* sleep = simcall->issuer->get_host()->pimpl_cpu->sleep(timeout); sleep->set_data(synchro.get()); simgrid::kernel::activity::CommImplPtr comm = @@ -389,7 +389,7 @@ void SIMIX_comm_finish(smx_activity_t synchro) /* Check out for errors */ - if (not simcall->issuer->host_->is_on()) { + if (not simcall->issuer->get_host()->is_on()) { simcall->issuer->context_->iwannadie = true; simcall->issuer->exception_ = std::make_exception_ptr(simgrid::HostFailureException(XBT_THROW_POINT, "Host failed")); @@ -430,9 +430,9 @@ void SIMIX_comm_finish(smx_activity_t synchro) 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.get(), comm->src_actor_ ? comm->src_actor_->host_->get_cname() : nullptr, - comm->dst_actor_ ? comm->dst_actor_->host_->get_cname() : nullptr, simcall->issuer->get_cname(), - simcall->issuer, comm->detached); + synchro.get(), comm->src_actor_ ? comm->src_actor_->get_host()->get_cname() : nullptr, + comm->dst_actor_ ? comm->dst_actor_->get_host()->get_cname() : nullptr, + simcall->issuer->get_cname(), simcall->issuer, comm->detached); if (comm->src_actor_ == simcall->issuer) { XBT_DEBUG("I'm source"); } else if (comm->dst_actor_ == simcall->issuer) { @@ -507,7 +507,7 @@ void SIMIX_comm_finish(smx_activity_t synchro) } } - if (simcall->issuer->host_->is_on()) + if (simcall->issuer->get_host()->is_on()) SIMIX_simcall_answer(simcall); else simcall->issuer->context_->iwannadie = true; diff --git a/src/smpi/mpi/smpi_comm.cpp b/src/smpi/mpi/smpi_comm.cpp index c60d088dc7..5e03b53bd5 100644 --- a/src/smpi/mpi/smpi_comm.cpp +++ b/src/smpi/mpi/smpi_comm.cpp @@ -321,7 +321,7 @@ void Comm::init_smp(){ int intra_comm_size = 0; int min_index = INT_MAX; // the minimum index will be the leader for (auto& actor : process_list) { - int index = actor.pid_; + int index = actor.get_pid(); if (this->group()->rank(actor.iface()) != MPI_UNDEFINED) { // Is this process in the current group? intra_comm_size++; if (index < min_index) diff --git a/src/surf/HostImpl.cpp b/src/surf/HostImpl.cpp index 8983db795e..caec7b645c 100644 --- a/src/surf/HostImpl.cpp +++ b/src/surf/HostImpl.cpp @@ -13,7 +13,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_host, surf, "Logging specific to the SURF h simgrid::surf::HostModel *surf_host_model = nullptr; /************* - * Callbacks * + * Callbacks *t *************/ namespace simgrid { @@ -109,7 +109,7 @@ void HostImpl::turn_on() if (arg->kill_time >= 0) actor->set_kill_time(arg->kill_time); if (arg->auto_restart) - actor->auto_restart_ = arg->auto_restart; + actor->set_auto_restart(arg->auto_restart); if (arg->daemon_) actor->daemonize(); } @@ -121,7 +121,7 @@ void HostImpl::turn_off() if (not process_list_.empty()) { for (auto& actor : process_list_) { XBT_DEBUG("Killing Actor %s@%s on behalf of %s which turned off that host.", actor.get_cname(), - actor.host_->get_cname(), SIMIX_process_self()->get_cname()); + actor.get_host()->get_cname(), SIMIX_process_self()->get_cname()); SIMIX_process_self()->kill(&actor); } } -- 2.20.1