* More importantly, this enforces a deterministic/reproducible ordering
* of the operation with respect to other simcalls.
*/
-template<class F>
-typename std::result_of<F()>::type kernelImmediate(F&& code)
+template <class F> typename std::result_of<F()>::type simcall(F&& code)
{
// If we are in the maestro, we take the fast path and execute the
// code directly without simcall mashalling/unmarshalling/dispatch:
typedef decltype(code().get()) T;
// Execute the code in the kernel and get the kernel future:
- simgrid::kernel::Future<T> future =
- simgrid::simix::kernelImmediate(std::move(code));
+ simgrid::kernel::Future<T> future = simgrid::simix::simcall(std::move(code));
// Wrap the kernel future in a actor future:
return simgrid::simix::Future<T>(std::move(future));
this->process_->suspended = 0;
this->iwannadie = false;
- simgrid::simix::kernelImmediate([this] { SIMIX_process_cleanup(this->process_); });
+ simgrid::simix::simcall([this] { SIMIX_process_cleanup(this->process_); });
this->iwannadie = true;
}
/** @brief creates a semaphore object of the given initial capacity */
msg_sem_t MSG_sem_init(int initial_value) {
- return simgrid::simix::kernelImmediate([initial_value] { return SIMIX_sem_init(initial_value); });
+ return simgrid::simix::simcall([initial_value] { return SIMIX_sem_init(initial_value); });
}
/** @brief locks on a semaphore object */
/** @brief releases the semaphore object */
void MSG_sem_release(msg_sem_t sem) {
- simgrid::simix::kernelImmediate([sem] { SIMIX_sem_release(sem); });
+ simgrid::simix::simcall([sem] { SIMIX_sem_release(sem); });
}
int MSG_sem_get_capacity(msg_sem_t sem) {
- return simgrid::simix::kernelImmediate([sem] { return SIMIX_sem_get_capacity(sem); });
+ return simgrid::simix::simcall([sem] { return SIMIX_sem_get_capacity(sem); });
}
void MSG_sem_destroy(msg_sem_t sem) {
* But that's a classical semaphore issue, and SimGrid's semaphore are not different to usual ones here.
*/
int MSG_sem_would_block(msg_sem_t sem) {
- return simgrid::simix::kernelImmediate([sem] { return SIMIX_sem_would_block(sem); });
+ return simgrid::simix::simcall([sem] { return SIMIX_sem_would_block(sem); });
}
/*-**** barrier related functions ****-*/
{
on_start(*this);
- simgrid::simix::kernelImmediate([this]() {
+ simgrid::simix::simcall([this]() {
simgrid::vm::VmHostExt::ensureVmExtInstalled();
simgrid::s4u::Host* pm = this->pimpl_vm_->getPm();
total_ramsize_of_vms += ws_vm->getRamsize();
if (vm_ramsize > pm_ramsize - total_ramsize_of_vms) {
- XBT_WARN("cannnot start %s@%s due to memory shortage: vm_ramsize %ld, free %ld, pm_ramsize %ld (bytes).",
+ XBT_WARN("cannot start %s@%s due to memory shortage: vm_ramsize %ld, free %ld, pm_ramsize %ld (bytes).",
this->get_cname(), pm->get_cname(), vm_ramsize, pm_ramsize - total_ramsize_of_vms, pm_ramsize);
THROWF(vm_error, 0, "Memory shortage on host '%s', VM '%s' cannot be started", pm->get_cname(),
this->get_cname());
{
on_suspend(*this);
smx_actor_t issuer = SIMIX_process_self();
- simgrid::simix::kernelImmediate([this, issuer]() { pimpl_vm_->suspend(issuer); });
+ simgrid::simix::simcall([this, issuer]() { pimpl_vm_->suspend(issuer); });
}
void VirtualMachine::resume()
void VirtualMachine::shutdown()
{
smx_actor_t issuer = SIMIX_process_self();
- simgrid::simix::kernelImmediate([this, issuer]() { pimpl_vm_->shutdown(issuer); });
+ simgrid::simix::simcall([this, issuer]() { pimpl_vm_->shutdown(issuer); });
on_shutdown(*this);
}
void VirtualMachine::setPm(simgrid::s4u::Host* pm)
{
- simgrid::simix::kernelImmediate([this, pm]() { pimpl_vm_->setPm(pm); });
+ simgrid::simix::simcall([this, pm]() { pimpl_vm_->setPm(pm); });
}
e_surf_vm_state_t VirtualMachine::getState()
{
- return simgrid::simix::kernelImmediate([this]() { return pimpl_vm_->getState(); });
+ return simgrid::simix::simcall([this]() { return pimpl_vm_->getState(); });
}
size_t VirtualMachine::getRamsize()
*/
void VirtualMachine::setBound(double bound)
{
- simgrid::simix::kernelImmediate([this, bound]() { pimpl_vm_->setBound(bound); });
+ simgrid::simix::simcall([this, bound]() { pimpl_vm_->setBound(bound); });
}
} // namespace simgrid
void Actor::set_auto_restart(bool autorestart)
{
- simgrid::simix::kernelImmediate([this, autorestart]() { pimpl_->auto_restart = autorestart; });
+ simgrid::simix::simcall([this, autorestart]() { pimpl_->auto_restart = autorestart; });
}
void Actor::on_exit(int_f_pvoid_pvoid_t fun, void* data)
{
- simgrid::simix::kernelImmediate([this, fun, data] { SIMIX_process_on_exit(pimpl_, fun, data); });
+ simgrid::simix::simcall([this, fun, data] { SIMIX_process_on_exit(pimpl_, fun, data); });
}
/** @brief Moves the actor to another host
{
s4u::Actor::on_migration_start(this);
- simgrid::simix::kernelImmediate([this, new_host]() {
+ simgrid::simix::simcall([this, new_host]() {
if (pimpl_->waiting_synchro != nullptr) {
// The actor is blocked on an activity. If it's an exec, migrate it too.
// FIXME: implement the migration of other kind of activities
void Actor::daemonize()
{
- simgrid::simix::kernelImmediate([this]() { pimpl_->daemonize(); });
+ simgrid::simix::simcall([this]() { pimpl_->daemonize(); });
}
bool Actor::is_daemon() const
void Actor::resume()
{
- simgrid::simix::kernelImmediate([this] { pimpl_->resume(); });
+ simgrid::simix::simcall([this] { pimpl_->resume(); });
s4u::Actor::on_resume(this);
}
int Actor::is_suspended()
{
- return simgrid::simix::kernelImmediate([this] { return pimpl_->suspended; });
+ return simgrid::simix::simcall([this] { return pimpl_->suspended; });
}
void Actor::set_kill_time(double time)
smx_actor_t killer = SIMIX_process_self();
smx_actor_t process = SIMIX_process_from_PID(pid);
if (process != nullptr) {
- simgrid::simix::kernelImmediate([killer, process] { SIMIX_process_kill(process, killer); });
+ simgrid::simix::simcall([killer, process] { SIMIX_process_kill(process, killer); });
} else {
std::ostringstream oss;
oss << "kill: (" << pid << ") - No such actor" << std::endl;
void Actor::kill()
{
smx_actor_t process = SIMIX_process_self();
- simgrid::simix::kernelImmediate(
+ simgrid::simix::simcall(
[this, process] { SIMIX_process_kill(pimpl_, (pimpl_ == simix_global->maestro_process) ? pimpl_ : process); });
}
void Actor::kill_all()
{
smx_actor_t self = SIMIX_process_self();
- simgrid::simix::kernelImmediate([&self] { SIMIX_process_killall(self); });
+ simgrid::simix::simcall([&self] { SIMIX_process_killall(self); });
}
std::map<std::string, std::string>* Actor::get_properties()
{
- return simgrid::simix::kernelImmediate([this] { return this->pimpl_->getProperties(); });
+ return simgrid::simix::simcall([this] { return this->pimpl_->getProperties(); });
}
/** Retrieve the property value (or nullptr if not set) */
const char* Actor::get_property(const char* key)
{
- return simgrid::simix::kernelImmediate([this, key] { return pimpl_->getProperty(key); });
+ return simgrid::simix::simcall([this, key] { return pimpl_->getProperty(key); });
}
void Actor::set_property(const char* key, const char* value)
{
- simgrid::simix::kernelImmediate([this, key, value] { pimpl_->setProperty(key, value); });
+ simgrid::simix::simcall([this, key, value] { pimpl_->setProperty(key, value); });
}
Actor* Actor::restart()
{
- return simgrid::simix::kernelImmediate([this]() { return pimpl_->restart(); });
+ return simgrid::simix::simcall([this]() { return pimpl_->restart(); });
}
// ***** this_actor *****
void yield()
{
- simgrid::simix::kernelImmediate([] { /* do nothing*/ });
+ simgrid::simix::simcall([] { /* do nothing*/ });
}
XBT_PUBLIC void sleep_until(double timeout)
void resume()
{
smx_actor_t process = SIMIX_process_self();
- simgrid::simix::kernelImmediate([process] { process->resume(); });
+ simgrid::simix::simcall([process] { process->resume(); });
simgrid::s4u::Actor::on_resume(process->iface());
}
bool is_suspended()
{
smx_actor_t process = SIMIX_process_self();
- return simgrid::simix::kernelImmediate([process] { return process->suspended; });
+ return simgrid::simix::simcall([process] { return process->suspended; });
}
void kill()
{
smx_actor_t process = SIMIX_process_self();
- simgrid::simix::kernelImmediate([process] { SIMIX_process_kill(process, process); });
+ simgrid::simix::simcall([process] { SIMIX_process_kill(process, process); });
}
void on_exit(int_f_pvoid_pvoid_t fun, void* data)
*/
void ConditionVariable::notify_one()
{
- simgrid::simix::kernelImmediate([this]() { cond_->signal(); });
+ simgrid::simix::simcall([this]() { cond_->signal(); });
}
void ConditionVariable::notify_all()
{
- simgrid::simix::kernelImmediate([this]() { cond_->broadcast(); });
+ simgrid::simix::simcall([this]() { cond_->broadcast(); });
}
void intrusive_ptr_add_ref(ConditionVariable* cond)
/** @brief Register a new netpoint to the system */
void Engine::netpoint_register(simgrid::kernel::routing::NetPoint* point)
{
- // simgrid::simix::kernelImmediate([&]{ FIXME: this segfaults in set_thread
+ // simgrid::simix::simcall([&]{ FIXME: this segfaults in set_thread
pimpl->netpoints_[point->get_name()] = point;
// });
}
/** @brief Unregister a given netpoint */
void Engine::netpoint_unregister(simgrid::kernel::routing::NetPoint* point)
{
- simgrid::simix::kernelImmediate([this, point] {
+ simgrid::simix::simcall([this, point] {
pimpl->netpoints_.erase(point->get_name());
delete point;
});
/** @brief Returns the amount of flops that remain to be done */
double Exec::get_remaining()
{
- return simgrid::simix::kernelImmediate(
+ return simgrid::simix::simcall(
[this]() { return boost::static_pointer_cast<simgrid::kernel::activity::ExecImpl>(pimpl_)->get_remaining(); });
}
*/
double Exec::get_remaining_ratio()
{
- return simgrid::simix::kernelImmediate([this]() {
+ return simgrid::simix::simcall([this]() {
return boost::static_pointer_cast<simgrid::kernel::activity::ExecImpl>(pimpl_)->get_remaining_ratio();
});
}
void Host::turnOn()
{
if (isOff()) {
- simgrid::simix::kernelImmediate([this] {
+ simgrid::simix::simcall([this] {
this->extension<simgrid::simix::Host>()->turnOn();
this->pimpl_cpu->turn_on();
onStateChange(*this);
{
if (isOn()) {
smx_actor_t self = SIMIX_process_self();
- simgrid::simix::kernelImmediate([this, self] {
+ simgrid::simix::simcall([this, self] {
SIMIX_host_off(this, self);
onStateChange(*this);
});
/** Get the properties assigned to a host */
std::map<std::string, std::string>* Host::getProperties()
{
- return simgrid::simix::kernelImmediate([this] { return this->pimpl_->getProperties(); });
+ return simgrid::simix::simcall([this] { return this->pimpl_->getProperties(); });
}
/** Retrieve the property value (or nullptr if not set) */
void Host::setProperty(std::string key, std::string value)
{
- simgrid::simix::kernelImmediate([this, key, value] { this->pimpl_->setProperty(key, value); });
+ simgrid::simix::simcall([this, key, value] { this->pimpl_->setProperty(key, value); });
}
/** Get the processes attached to the host */
/** @brief Get the peak processor speed (in flops/s), at the specified pstate */
double Host::getPstateSpeed(int pstate_index)
{
- return simgrid::simix::kernelImmediate(
- [this, pstate_index] { return this->pimpl_cpu->getPstateSpeed(pstate_index); });
+ return simgrid::simix::simcall([this, pstate_index] { return this->pimpl_cpu->getPstateSpeed(pstate_index); });
}
/** @brief Get the peak processor speed (under full load (=1.0), in flops/s), at the current pstate */
/** @brief Set the pstate at which the host should run */
void Host::setPstate(int pstate_index)
{
- simgrid::simix::kernelImmediate([this, pstate_index] { this->pimpl_cpu->setPState(pstate_index); });
+ simgrid::simix::simcall([this, pstate_index] { this->pimpl_cpu->setPState(pstate_index); });
}
/** @brief Retrieve the pstate at which the host is currently running */
int Host::getPstate()
*/
std::vector<const char*> Host::get_attached_storages()
{
- return simgrid::simix::kernelImmediate([this] { return this->pimpl_->get_attached_storages(); });
+ return simgrid::simix::simcall([this] { return this->pimpl_->get_attached_storages(); });
}
void Host::getAttachedStorages(std::vector<const char*>* storages)
{
std::vector<const char*> local_storages =
- simgrid::simix::kernelImmediate([this] { return this->pimpl_->get_attached_storages(); });
+ simgrid::simix::simcall([this] { return this->pimpl_->get_attached_storages(); });
for (auto elm : local_storages)
storages->push_back(elm);
}
void Link::turnOn()
{
- simgrid::simix::kernelImmediate([this]() { this->pimpl_->turn_on(); });
+ simgrid::simix::simcall([this]() { this->pimpl_->turn_on(); });
}
void Link::turnOff()
{
- simgrid::simix::kernelImmediate([this]() { this->pimpl_->turn_off(); });
+ simgrid::simix::simcall([this]() { this->pimpl_->turn_off(); });
}
void* Link::getData()
}
void Link::setData(void* d)
{
- simgrid::simix::kernelImmediate([this, d]() { this->pimpl_->setData(d); });
+ simgrid::simix::simcall([this, d]() { this->pimpl_->setData(d); });
}
void Link::setStateTrace(tmgr_trace_t trace)
{
- simgrid::simix::kernelImmediate([this, trace]() { this->pimpl_->setStateTrace(trace); });
+ simgrid::simix::simcall([this, trace]() { this->pimpl_->setStateTrace(trace); });
}
void Link::setBandwidthTrace(tmgr_trace_t trace)
{
- simgrid::simix::kernelImmediate([this, trace]() { this->pimpl_->setBandwidthTrace(trace); });
+ simgrid::simix::simcall([this, trace]() { this->pimpl_->setBandwidthTrace(trace); });
}
void Link::setLatencyTrace(tmgr_trace_t trace)
{
- simgrid::simix::kernelImmediate([this, trace]() { this->pimpl_->setLatencyTrace(trace); });
+ simgrid::simix::simcall([this, trace]() { this->pimpl_->setLatencyTrace(trace); });
}
const char* Link::getProperty(const char* key)
}
void Link::setProperty(std::string key, std::string value)
{
- simgrid::simix::kernelImmediate([this, key, value] { this->pimpl_->setProperty(key, value); });
+ simgrid::simix::simcall([this, key, value] { this->pimpl_->setProperty(key, value); });
}
} // namespace s4u
} // namespace simgrid
{
kernel::activity::MailboxImpl* mbox = kernel::activity::MailboxImpl::byNameOrNull(name);
if (mbox == nullptr) {
- mbox = simix::kernelImmediate([name] { return kernel::activity::MailboxImpl::byNameOrCreate(name); });
+ mbox = simix::simcall([name] { return kernel::activity::MailboxImpl::byNameOrCreate(name); });
}
return MailboxPtr(&mbox->piface_, true);
}
void Mailbox::setReceiver(ActorPtr actor)
{
- simix::kernelImmediate([this, actor]() { this->pimpl_->setReceiver(actor); });
+ simix::simcall([this, actor]() { this->pimpl_->setReceiver(actor); });
}
/** @brief get the receiver (process associated to the mailbox) */
std::unordered_map<std::string, std::string>* NetZone::getProperties()
{
- return simgrid::simix::kernelImmediate([this] { return &properties_; });
+ return simgrid::simix::simcall([this] { return &properties_; });
}
/** Retrieve the property value (or nullptr if not set) */
}
void NetZone::setProperty(const char* key, const char* value)
{
- simgrid::simix::kernelImmediate([this, key, value] { properties_[key] = value; });
+ simgrid::simix::simcall([this, key, value] { properties_[key] = value; });
}
/** @brief Returns the list of direct children (no grand-children)
std::map<std::string, std::string>* Storage::getProperties()
{
- return simgrid::simix::kernelImmediate([this] { return pimpl_->getProperties(); });
+ return simgrid::simix::simcall([this] { return pimpl_->getProperties(); });
}
const char* Storage::getProperty(std::string key)
void Storage::setProperty(std::string key, std::string value)
{
- simgrid::simix::kernelImmediate([this, key, value] { this->pimpl_->setProperty(key, value); });
+ simgrid::simix::simcall([this, key, value] { this->pimpl_->setProperty(key, value); });
}
sg_size_t Storage::read(sg_size_t size)
if (name == nullptr)
name = "";
smx_actor_t self = SIMIX_process_self();
- return simgrid::simix::kernelImmediate([name, code, data, host, properties, self] {
+ return simgrid::simix::simcall([name, code, data, host, properties, self] {
return SIMIX_process_create(name, std::move(code), data, host, properties, self);
});
}
xbt_assert(std::isfinite(flops_amount), "flops_amount is not finite!");
xbt_assert(std::isfinite(priority), "priority is not finite!");
- return simgrid::simix::kernelImmediate([name, flops_amount, priority, bound, host] {
+ return simgrid::simix::simcall([name, flops_amount, priority, bound, host] {
return SIMIX_execution_start(name, flops_amount, priority, bound, host);
});
}
xbt_assert(std::isfinite(rate), "rate is not finite!");
- return simgrid::simix::kernelImmediate([name, host_nb, host_list, flops_amount, bytes_amount, rate, timeout] {
+ return simgrid::simix::simcall([name, host_nb, host_list, flops_amount, bytes_amount, rate, timeout] {
return SIMIX_execution_parallel_start(name, host_nb, host_list, flops_amount, bytes_amount, rate, timeout);
});
}
boost::static_pointer_cast<simgrid::kernel::activity::ExecImpl>(execution);
if (exec->surf_action_ == nullptr) // FIXME: One test fails if I remove this, but I don't get why...
return;
- simgrid::simix::kernelImmediate([exec] {
- exec->cancel();
- });
+ simgrid::simix::simcall([exec] { exec->cancel(); });
}
/**
{
/* checking for infinite values */
xbt_assert(std::isfinite(priority), "priority is not finite!");
- simgrid::simix::kernelImmediate([execution, priority] {
+ simgrid::simix::simcall([execution, priority] {
simgrid::kernel::activity::ExecImplPtr exec =
boost::static_pointer_cast<simgrid::kernel::activity::ExecImpl>(execution);
*/
void simcall_execution_set_bound(smx_activity_t execution, double bound)
{
- simgrid::simix::kernelImmediate([execution, bound] {
+ simgrid::simix::simcall([execution, bound] {
simgrid::kernel::activity::ExecImplPtr exec =
boost::static_pointer_cast<simgrid::kernel::activity::ExecImpl>(execution);
exec->set_bound(bound);
*/
void simcall_process_set_data(smx_actor_t process, void *data)
{
- simgrid::simix::kernelImmediate([process, data] { process->setUserData(data); });
+ simgrid::simix::simcall([process, data] { process->setUserData(data); });
}
/**
*/
void simcall_comm_cancel(smx_activity_t synchro)
{
- simgrid::simix::kernelImmediate([synchro] {
+ simgrid::simix::simcall([synchro] {
simgrid::kernel::activity::CommImplPtr comm =
boost::static_pointer_cast<simgrid::kernel::activity::CommImpl>(synchro);
comm->cancel();
if (category == nullptr) {
return;
}
- simgrid::simix::kernelImmediate([synchro, category] { SIMIX_set_category(synchro, category); });
+ simgrid::simix::simcall([synchro, category] { SIMIX_set_category(synchro, category); });
}
/**
fprintf(stderr,"You must run MSG_init before using MSG\n"); // We can't use xbt_die since we may get there before the initialization
xbt_abort();
}
- return simgrid::simix::kernelImmediate([] { return new simgrid::kernel::activity::MutexImpl(); });
+ return simgrid::simix::simcall([] { return new simgrid::kernel::activity::MutexImpl(); });
}
/**
*/
smx_cond_t simcall_cond_init()
{
- return simgrid::simix::kernelImmediate([] { return new simgrid::kernel::activity::ConditionVariableImpl(); });
+ return simgrid::simix::simcall([] { return new simgrid::kernel::activity::ConditionVariableImpl(); });
}
/**
smpi_bench_end();
// FIXME: should kill all processes in comm instead
smx_actor_t process = SIMIX_process_self();
- simgrid::simix::kernelImmediate([process] { SIMIX_process_kill(process, process); });
+ simgrid::simix::simcall([process] { SIMIX_process_kill(process, process); });
return MPI_SUCCESS;
}
double HostEnergy::getConsumedEnergy()
{
if (last_updated < surf_get_clock()) // We need to simcall this as it modifies the environment
- simgrid::simix::kernelImmediate(std::bind(&HostEnergy::update, this));
+ simgrid::simix::simcall(std::bind(&HostEnergy::update, this));
return total_energy;
}
*/
void sg_host_energy_update_all()
{
- simgrid::simix::kernelImmediate([]() {
+ simgrid::simix::simcall([]() {
std::vector<simgrid::s4u::Host*> list = simgrid::s4u::Engine::get_instance()->get_all_hosts();
for (auto const& host : list)
if (dynamic_cast<simgrid::s4u::VirtualMachine*>(host) == nullptr) // Ignore virtual machines
double LinkEnergy::getConsumedEnergy()
{
if (lastUpdated_ < surf_get_clock()) // We need to simcall this as it modifies the environment
- simgrid::simix::kernelImmediate(std::bind(&LinkEnergy::update, this));
+ simgrid::simix::simcall(std::bind(&LinkEnergy::update, this));
return this->totalEnergy_;
}
}
{
// Test the simple immediate execution:
XBT_INFO("Start");
- simgrid::simix::kernelImmediate([] { XBT_INFO("kernel"); });
+ simgrid::simix::simcall([] { XBT_INFO("kernel"); });
XBT_INFO("kernel, returned");
// Synchronize on a successful Future<void>: