Commit 173e6cb3 authored by Fred Suter's avatar Fred Suter

Improve self (less SIMIX more kernel)

parent df0be021
......@@ -32,9 +32,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_process, simix, "Logging specific to SIMIX
*/
smx_actor_t SIMIX_process_self()
{
simgrid::kernel::context::Context* self_context = simgrid::kernel::context::Context::self();
return (self_context != nullptr) ? self_context->get_actor() : nullptr;
return simgrid::kernel::actor::ActorImpl::self();
}
namespace simgrid {
......@@ -47,6 +45,13 @@ int get_maxpid()
return maxpid;
}
ActorImpl* ActorImpl::self()
{
context::Context* self_context = context::Context::self();
return (self_context != nullptr) ? self_context->get_actor() : nullptr;
}
ActorImpl::ActorImpl(simgrid::xbt::string name, s4u::Host* host) : host_(host), name_(std::move(name)), piface_(this)
{
pid_ = maxpid++;
......@@ -496,7 +501,7 @@ ActorImplPtr ActorImpl::create(const std::string& name, const simix::ActorCode&
if (parent_actor != nullptr)
actor = parent_actor->init(xbt::string(name), host);
else
actor = SIMIX_process_self()->init(xbt::string(name), host);
actor = self()->init(xbt::string(name), host);
/* actor data */
actor->set_user_data(data);
......@@ -537,7 +542,7 @@ int SIMIX_process_count() // XBT_ATTRIB_DEPRECATED_v329
// XBT_DEPRECATED_v329
void* SIMIX_process_self_get_data()
{
smx_actor_t self = SIMIX_process_self();
smx_actor_t self = simgrid::kernel::actor::ActorImpl::self();
if (self == nullptr) {
return nullptr;
......@@ -548,14 +553,14 @@ void* SIMIX_process_self_get_data()
// XBT_DEPRECATED_v329
void SIMIX_process_self_set_data(void* data)
{
SIMIX_process_self()->set_user_data(data);
simgrid::kernel::actor::ActorImpl::self()->set_user_data(data);
}
/* needs to be public and without simcall because it is called
by exceptions and logging events */
const char* SIMIX_process_self_get_name()
{
return SIMIX_is_maestro() ? "maestro" : SIMIX_process_self()->get_cname();
return SIMIX_is_maestro() ? "maestro" : simgrid::kernel::actor::ActorImpl::self()->get_cname();
}
/**
......@@ -604,7 +609,7 @@ void SIMIX_process_on_exit(smx_actor_t actor,
smx_actor_t simcall_process_create(const std::string& name, const simgrid::simix::ActorCode& code, void* data,
sg_host_t host, std::unordered_map<std::string, std::string>* properties)
{
smx_actor_t self = SIMIX_process_self();
smx_actor_t self = simgrid::kernel::actor::ActorImpl::self();
return simgrid::kernel::actor::simcall([&name, &code, data, host, properties, self] {
return simgrid::kernel::actor::ActorImpl::create(name, code, data, host, properties, self).get();
});
......
......@@ -35,6 +35,7 @@ public:
ActorImpl& operator=(const ActorImpl&) = delete;
~ActorImpl();
static ActorImpl* self();
double get_kill_time();
void set_kill_time(double kill_time);
boost::intrusive::list_member_hook<> host_actor_list_hook; /* simgrid::simix::Host::process_list */
......
......@@ -60,21 +60,21 @@ void VirtualMachine::start()
{
on_start(*this);
simgrid::kernel::actor::simcall([this]() {
simgrid::vm::VmHostExt::ensureVmExtInstalled();
kernel::actor::simcall([this]() {
vm::VmHostExt::ensureVmExtInstalled();
simgrid::s4u::Host* pm = this->pimpl_vm_->get_physical_host();
if (pm->extension<simgrid::vm::VmHostExt>() == nullptr)
pm->extension_set(new simgrid::vm::VmHostExt());
Host* pm = this->pimpl_vm_->get_physical_host();
if (pm->extension<vm::VmHostExt>() == nullptr)
pm->extension_set(new vm::VmHostExt());
long pm_ramsize = pm->extension<simgrid::vm::VmHostExt>()->ramsize;
int pm_overcommit = pm->extension<simgrid::vm::VmHostExt>()->overcommit;
long pm_ramsize = pm->extension<vm::VmHostExt>()->ramsize;
int pm_overcommit = pm->extension<vm::VmHostExt>()->overcommit;
long vm_ramsize = this->get_ramsize();
if (pm_ramsize && not pm_overcommit) { /* Only verify that we don't overcommit on need */
/* Retrieve the memory occupied by the VMs on that host. Yep, we have to traverse all VMs of all hosts for that */
long total_ramsize_of_vms = 0;
for (simgrid::s4u::VirtualMachine* const& ws_vm : simgrid::vm::VirtualMachineImpl::allVms_)
for (VirtualMachine* const& ws_vm : vm::VirtualMachineImpl::allVms_)
if (pm == ws_vm->get_pm())
total_ramsize_of_vms += ws_vm->get_ramsize();
......@@ -96,8 +96,8 @@ void VirtualMachine::start()
void VirtualMachine::suspend()
{
on_suspend(*this);
smx_actor_t issuer = SIMIX_process_self();
simgrid::kernel::actor::simcall([this, issuer]() { pimpl_vm_->suspend(issuer); });
kernel::actor::ActorImpl* issuer = kernel::actor::ActorImpl::self();
kernel::actor::simcall([this, issuer]() { pimpl_vm_->suspend(issuer); });
}
void VirtualMachine::resume()
......@@ -108,8 +108,8 @@ void VirtualMachine::resume()
void VirtualMachine::shutdown()
{
smx_actor_t issuer = SIMIX_process_self();
simgrid::kernel::actor::simcall([this, issuer]() { pimpl_vm_->shutdown(issuer); });
kernel::actor::ActorImpl* issuer = kernel::actor::ActorImpl::self();
kernel::actor::simcall([this, issuer]() { pimpl_vm_->shutdown(issuer); });
on_shutdown(*this);
}
......@@ -129,12 +129,12 @@ simgrid::s4u::Host* VirtualMachine::get_pm()
void VirtualMachine::set_pm(simgrid::s4u::Host* pm)
{
simgrid::kernel::actor::simcall([this, pm]() { pimpl_vm_->set_physical_host(pm); });
kernel::actor::simcall([this, pm]() { pimpl_vm_->set_physical_host(pm); });
}
VirtualMachine::state VirtualMachine::get_state()
{
return simgrid::kernel::actor::simcall([this]() { return pimpl_vm_->get_state(); });
return kernel::actor::simcall([this]() { return pimpl_vm_->get_state(); });
}
size_t VirtualMachine::get_ramsize()
......@@ -174,7 +174,7 @@ void VirtualMachine::set_ramsize(size_t ramsize)
*/
void VirtualMachine::set_bound(double bound)
{
simgrid::kernel::actor::simcall([this, bound]() { pimpl_vm_->set_bound(bound); });
kernel::actor::simcall([this, bound]() { pimpl_vm_->set_bound(bound); });
}
} // namespace simgrid
......
......@@ -46,7 +46,7 @@ Actor* Actor::self()
ActorPtr Actor::init(const std::string& name, s4u::Host* host)
{
kernel::actor::ActorImpl* self = SIMIX_process_self();
kernel::actor::ActorImpl* self = kernel::actor::ActorImpl::self();
kernel::actor::ActorImpl* actor =
kernel::actor::simcall([self, &name, host] { return self->init(name, host).get(); });
return actor->iface();
......@@ -60,7 +60,7 @@ ActorPtr Actor::start(const std::function<void()>& code)
ActorPtr Actor::create(const std::string& name, s4u::Host* host, const std::function<void()>& code)
{
kernel::actor::ActorImpl* self = SIMIX_process_self();
kernel::actor::ActorImpl* self = kernel::actor::ActorImpl::self();
kernel::actor::ActorImpl* actor =
kernel::actor::simcall([self, &name, host, &code] { return self->init(name, host)->start(code); });
......@@ -96,7 +96,7 @@ void Actor::join()
void Actor::join(double timeout)
{
kernel::actor::ActorImpl* issuer = SIMIX_process_self();
kernel::actor::ActorImpl* issuer = kernel::actor::ActorImpl::self();
kernel::actor::ActorImpl* target = pimpl_;
kernel::actor::simcall_blocking<void>([issuer, target, timeout] {
if (target->finished_) {
......@@ -202,7 +202,7 @@ aid_t Actor::get_ppid() const
void Actor::suspend()
{
kernel::actor::ActorImpl* issuer = SIMIX_process_self();
kernel::actor::ActorImpl* issuer = kernel::actor::ActorImpl::self();
kernel::actor::ActorImpl* target = pimpl_;
s4u::Actor::on_suspend(*this);
kernel::actor::simcall_blocking<void>([issuer, target]() {
......@@ -238,7 +238,7 @@ double Actor::get_kill_time()
void Actor::kill()
{
kernel::actor::ActorImpl* self = SIMIX_process_self();
kernel::actor::ActorImpl* self = kernel::actor::ActorImpl::self();
kernel::actor::simcall([this, self] { self->kill(pimpl_); });
}
......@@ -255,7 +255,7 @@ ActorPtr Actor::by_pid(aid_t pid)
void Actor::kill_all()
{
kernel::actor::ActorImpl* self = SIMIX_process_self();
kernel::actor::ActorImpl* self = kernel::actor::ActorImpl::self();
kernel::actor::simcall([self] { self->kill_all(); });
}
......@@ -303,7 +303,7 @@ void sleep_for(double duration)
xbt_assert(std::isfinite(duration), "duration is not finite!");
if (duration > 0) {
kernel::actor::ActorImpl* issuer = SIMIX_process_self();
kernel::actor::ActorImpl* issuer = kernel::actor::ActorImpl::self();
Actor::on_sleep(*issuer->ciface());
kernel::actor::simcall_blocking<void>([issuer, duration]() {
......@@ -394,52 +394,52 @@ ExecPtr exec_async(double flops)
aid_t get_pid()
{
return SIMIX_process_self()->get_pid();
return simgrid::kernel::actor::ActorImpl::self()->get_pid();
}
aid_t get_ppid()
{
return SIMIX_process_self()->get_ppid();
return simgrid::kernel::actor::ActorImpl::self()->get_ppid();
}
std::string get_name()
{
return SIMIX_process_self()->get_name();
return simgrid::kernel::actor::ActorImpl::self()->get_name();
}
const char* get_cname()
{
return SIMIX_process_self()->get_cname();
return simgrid::kernel::actor::ActorImpl::self()->get_cname();
}
Host* get_host()
{
return SIMIX_process_self()->get_host();
return simgrid::kernel::actor::ActorImpl::self()->get_host();
}
void suspend()
{
kernel::actor::ActorImpl* self = SIMIX_process_self();
kernel::actor::ActorImpl* self = simgrid::kernel::actor::ActorImpl::self();
s4u::Actor::on_suspend(*self->ciface());
kernel::actor::simcall_blocking<void>([self] { self->suspend(); });
}
void resume()
{
kernel::actor::ActorImpl* self = SIMIX_process_self();
kernel::actor::ActorImpl* self = simgrid::kernel::actor::ActorImpl::self();
kernel::actor::simcall([self] { self->resume(); });
Actor::on_resume(*self->ciface());
}
void exit()
{
kernel::actor::ActorImpl* self = SIMIX_process_self();
kernel::actor::ActorImpl* self = simgrid::kernel::actor::ActorImpl::self();
simgrid::kernel::actor::simcall([self] { self->exit(); });
}
void on_exit(const std::function<void(bool)>& fun)
{
SIMIX_process_self()->iface()->on_exit(fun);
simgrid::kernel::actor::ActorImpl::self()->iface()->on_exit(fun);
}
/** @brief Moves the current actor to another host
......@@ -448,7 +448,7 @@ void on_exit(const std::function<void(bool)>& fun)
*/
void set_host(Host* new_host)
{
SIMIX_process_self()->iface()->set_host(new_host);
simgrid::kernel::actor::ActorImpl::self()->iface()->set_host(new_host);
}
void migrate(Host* new_host) // deprecated
{
......
......@@ -75,7 +75,7 @@ Host* Host::by_name_or_null(const std::string& name)
Host* Host::current()
{
kernel::actor::ActorImpl* self = SIMIX_process_self();
kernel::actor::ActorImpl* self = kernel::actor::ActorImpl::self();
if (self == nullptr)
xbt_die("Cannot call Host::current() from the maestro context");
return self->get_host();
......@@ -96,7 +96,7 @@ void Host::turn_on()
void Host::turn_off()
{
if (is_on()) {
kernel::actor::ActorImpl* self = SIMIX_process_self();
kernel::actor::ActorImpl* self = kernel::actor::ActorImpl::self();
kernel::actor::simcall([this, self] {
for (VirtualMachine* const& vm : vm::VirtualMachineImpl::allVms_)
if (vm->get_pm() == this) {
......@@ -654,13 +654,13 @@ void sg_host_get_actor_list(sg_host_t host, xbt_dynar_t whereto)
sg_host_t sg_host_self()
{
return SIMIX_is_maestro() ? nullptr : SIMIX_process_self()->get_host();
return SIMIX_is_maestro() ? nullptr : simgrid::kernel::actor::ActorImpl::self()->get_host();
}
/* needs to be public and without simcall for exceptions and logging events */
const char* sg_host_self_get_name()
{
return SIMIX_is_maestro() ? "" : SIMIX_process_self()->get_host()->get_cname();
return SIMIX_is_maestro() ? "" : simgrid::kernel::actor::ActorImpl::self()->get_host()->get_cname();
}
double sg_host_load(sg_host_t host)
......
......@@ -77,7 +77,7 @@ ActorPtr Mailbox::get_receiver()
CommPtr Mailbox::put_init()
{
CommPtr res = CommPtr(new s4u::Comm());
res->sender_ = SIMIX_process_self();
res->sender_ = kernel::actor::ActorImpl::self();
res->mailbox_ = this;
return res;
}
......@@ -121,7 +121,7 @@ void Mailbox::put(void* payload, uint64_t simulated_size_in_bytes, double timeou
s4u::CommPtr Mailbox::get_init()
{
CommPtr res = CommPtr(new s4u::Comm());
res->receiver_ = SIMIX_process_self();
res->receiver_ = kernel::actor::ActorImpl::self();
res->mailbox_ = this;
return res;
}
......
......@@ -46,7 +46,7 @@ unsigned int simcall_execution_waitany_for(simgrid::kernel::activity::ExecImpl*
void simcall_process_join(smx_actor_t process, double timeout) // XBT_DEPRECATED_v328
{
SIMIX_process_self()->join(process, timeout);
simgrid::kernel::actor::ActorImpl::self()->join(process, timeout);
}
void simcall_process_suspend(smx_actor_t process) // XBT_DEPRECATED_v328
......@@ -56,7 +56,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);
simgrid::kernel::actor::ActorImpl::self()->sleep(duration);
return simgrid::kernel::activity::State::DONE;
}
......@@ -309,13 +309,13 @@ e_smx_state_t simcall_io_wait(const smx_activity_t& io)
void simcall_run_kernel(std::function<void()> const& code, simgrid::mc::SimcallInspector* t)
{
SIMIX_process_self()->simcall.inspector_ = t;
simgrid::kernel::actor::ActorImpl::self()->simcall.inspector_ = t;
simcall_BODY_run_kernel(&code);
}
void simcall_run_blocking(std::function<void()> const& code, simgrid::mc::SimcallInspector* t = nullptr)
{
SIMIX_process_self()->simcall.inspector_ = t;
simgrid::kernel::actor::ActorImpl::self()->simcall.inspector_ = t;
simcall_BODY_run_blocking(&code);
}
......
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