Activity* cancel() override;
double get_remaining() override;
+ sg_size_t get_performed_ioops();
IoPtr set_io_type(OpType type);
private:
void set_data(void* data) { userdata_ = data; }
void* get_data() { return userdata_; }
- static IoPtr io_init(sg_size_t size);
+ IoPtr io_init(sg_size_t size);
sg_size_t read(sg_size_t size);
sg_size_t write(sg_size_t size);
XBT_PUBLIC void simcall_sem_acquire(smx_sem_t sem);
XBT_PUBLIC int simcall_sem_acquire_timeout(smx_sem_t sem, double max_duration);
-/***************************** Storage **********************************/
-XBT_PUBLIC sg_size_t simcall_storage_read(surf_storage_t st, sg_size_t size);
-XBT_PUBLIC sg_size_t simcall_storage_write(surf_storage_t fd, sg_size_t size);
+/***************************** Io **************************************/
+XBT_PUBLIC e_smx_state_t simcall_io_wait(smx_activity_t io);
/************************** MC simcalls **********************************/
XBT_PUBLIC int simcall_mc_random(int min, int max);
simgrid::kernel::activity::IoImpl::~IoImpl()
{
- if (surf_action_)
+ if (surf_action_ != nullptr)
surf_action_->unref();
XBT_DEBUG("Destroy exec %p", this);
}
void simgrid::kernel::activity::IoImpl::post()
{
- for (smx_simcall_t const& simcall : simcalls_) {
- switch (simcall->call) {
- case SIMCALL_STORAGE_WRITE:
- simcall_storage_write__set__result(simcall, surf_action_->get_cost());
- break;
- case SIMCALL_STORAGE_READ:
- simcall_storage_read__set__result(simcall, surf_action_->get_cost());
- break;
- default:
- break;
- }
- }
-
+ performed_ioops_ = surf_action_->get_cost();
switch (surf_action_->get_state()) {
case simgrid::kernel::resource::Action::State::FAILED:
state_ = SIMIX_FAILED;
THROW_IMPOSSIBLE;
break;
}
-
SIMIX_io_finish(this);
}
/*************
void post() override;
void cancel();
double get_remaining();
+ sg_size_t get_performed_ioops() { return performed_ioops_; }
s4u::Storage* storage_ = nullptr;
simgrid::kernel::resource::Action* surf_action_ = nullptr;
-
+ sg_size_t performed_ioops_ = 0;
static simgrid::xbt::signal<void(kernel::activity::IoImplPtr)> on_creation;
static simgrid::xbt::signal<void(kernel::activity::IoImplPtr)> on_completion;
};
Activity* Io::wait()
{
- // simcall_execution_wait(pimpl_);
+ simcall_io_wait(pimpl_);
state_ = State::FINISHED;
return this;
}
THROW_UNIMPLEMENTED;
return this;
}
-//
-///** @brief Returns whether the state of the exec is finished */
-// bool Exec::test()
-//{
-// xbt_assert(state_ == State::INITED || state_ == State::STARTED || state_ == State::FINISHED);
-//
-// if (state_ == State::FINISHED)
-// return true;
-//
-// if (state_ == State::INITED)
-// this->start();
-//
-// if (simcall_execution_test(pimpl_)) {
-// state_ = State::FINISHED;
-// return true;
-// }
-//
-// return false;
-//}
/** @brief Returns the amount of flops that remain to be done */
double Io::get_remaining()
{
return simgrid::simix::simcall(
- [this]() { return boost::static_pointer_cast<simgrid::kernel::activity::IoImpl>(pimpl_)->get_remaining(); });
+ [this]() { return boost::static_pointer_cast<kernel::activity::IoImpl>(pimpl_)->get_remaining(); });
+}
+
+sg_size_t Io::get_performed_ioops()
+{
+ return simgrid::simix::simcall(
+ [this]() { return boost::static_pointer_cast<kernel::activity::IoImpl>(pimpl_)->get_performed_ioops(); });
}
IoPtr Io::set_io_type(OpType type)
return this;
}
-// double Io::get_remaining_ratio()
-//{
-// return simgrid::simix::simcall([this]() {
-// return boost::static_pointer_cast<simgrid::kernel::activity::IoImpl>(pimpl_)->get_remaining_ratio();
-// });
-//}
-
-void intrusive_ptr_release(simgrid::s4u::Io* e)
+void intrusive_ptr_release(simgrid::s4u::Io* i)
{
- if (e->refcount_.fetch_sub(1, std::memory_order_release) == 1) {
+ if (i->refcount_.fetch_sub(1, std::memory_order_release) == 1) {
std::atomic_thread_fence(std::memory_order_acquire);
- delete e;
+ delete i;
}
}
-void intrusive_ptr_add_ref(simgrid::s4u::Io* e)
+void intrusive_ptr_add_ref(simgrid::s4u::Io* i)
{
- e->refcount_.fetch_add(1, std::memory_order_relaxed);
+ i->refcount_.fetch_add(1, std::memory_order_relaxed);
}
} // namespace s4u
} // namespace simgrid
{
IoPtr res = IoPtr(new Io());
res->size_ = size;
+ res->storage_ = this;
res->set_remaining(size);
return res;
}
sg_size_t Storage::read(sg_size_t size)
{
- return simcall_storage_read(pimpl_, size);
+ IoPtr i = io_init(size);
+ i->set_io_type(Io::OpType::READ);
+ i->start()->wait();
+ return i->get_performed_ioops();
}
sg_size_t Storage::write(sg_size_t size)
{
- return simcall_storage_write(pimpl_, size);
+ IoPtr i = io_init(size);
+ i->set_io_type(Io::OpType::WRITE);
+ i->start()->wait();
+ return i->get_performed_ioops();
}
// Deprecated functions
return simcall_BODY_sem_acquire_timeout(sem, timeout);
}
-sg_size_t simcall_storage_read(surf_storage_t st, sg_size_t size)
+e_smx_state_t simcall_io_wait(smx_activity_t io)
{
- return simcall_BODY_storage_read(st, size);
-}
-
-sg_size_t simcall_storage_write(surf_storage_t st, sg_size_t size)
-{
- return simcall_BODY_storage_write(st, size);
+ return (e_smx_state_t)simcall_BODY_io_wait(io);
}
void simcall_run_kernel(std::function<void()> const& code)
simgrid::simix::marshal<int>(simcall->result, result);
}
-static inline surf_storage_t simcall_storage_read__get__st(smx_simcall_t simcall)
-{
- return simgrid::simix::unmarshal<surf_storage_t>(simcall->args[0]);
-}
-static inline surf_storage_t simcall_storage_read__getraw__st(smx_simcall_t simcall)
-{
- return simgrid::simix::unmarshal_raw<surf_storage_t>(simcall->args[0]);
-}
-static inline void simcall_storage_read__set__st(smx_simcall_t simcall, surf_storage_t arg)
-{
- simgrid::simix::marshal<surf_storage_t>(simcall->args[0], arg);
-}
-static inline sg_size_t simcall_storage_read__get__size(smx_simcall_t simcall)
-{
- return simgrid::simix::unmarshal<sg_size_t>(simcall->args[1]);
-}
-static inline sg_size_t simcall_storage_read__getraw__size(smx_simcall_t simcall)
-{
- return simgrid::simix::unmarshal_raw<sg_size_t>(simcall->args[1]);
-}
-static inline void simcall_storage_read__set__size(smx_simcall_t simcall, sg_size_t arg)
-{
- simgrid::simix::marshal<sg_size_t>(simcall->args[1], arg);
-}
-static inline sg_size_t simcall_storage_read__get__result(smx_simcall_t simcall)
-{
- return simgrid::simix::unmarshal<sg_size_t>(simcall->result);
-}
-static inline sg_size_t simcall_storage_read__getraw__result(smx_simcall_t simcall)
-{
- return simgrid::simix::unmarshal_raw<sg_size_t>(simcall->result);
-}
-static inline void simcall_storage_read__set__result(smx_simcall_t simcall, sg_size_t result)
-{
- simgrid::simix::marshal<sg_size_t>(simcall->result, result);
-}
-
-static inline surf_storage_t simcall_storage_write__get__st(smx_simcall_t simcall)
-{
- return simgrid::simix::unmarshal<surf_storage_t>(simcall->args[0]);
-}
-static inline surf_storage_t simcall_storage_write__getraw__st(smx_simcall_t simcall)
-{
- return simgrid::simix::unmarshal_raw<surf_storage_t>(simcall->args[0]);
-}
-static inline void simcall_storage_write__set__st(smx_simcall_t simcall, surf_storage_t arg)
-{
- simgrid::simix::marshal<surf_storage_t>(simcall->args[0], arg);
-}
-static inline sg_size_t simcall_storage_write__get__size(smx_simcall_t simcall)
+static inline boost::intrusive_ptr<simgrid::kernel::activity::ActivityImpl>
+simcall_io_wait__get__io(smx_simcall_t simcall)
{
- return simgrid::simix::unmarshal<sg_size_t>(simcall->args[1]);
+ return simgrid::simix::unmarshal<boost::intrusive_ptr<simgrid::kernel::activity::ActivityImpl>>(simcall->args[0]);
}
-static inline sg_size_t simcall_storage_write__getraw__size(smx_simcall_t simcall)
+static inline simgrid::kernel::activity::ActivityImpl* simcall_io_wait__getraw__io(smx_simcall_t simcall)
{
- return simgrid::simix::unmarshal_raw<sg_size_t>(simcall->args[1]);
+ return simgrid::simix::unmarshal_raw<simgrid::kernel::activity::ActivityImpl*>(simcall->args[0]);
}
-static inline void simcall_storage_write__set__size(smx_simcall_t simcall, sg_size_t arg)
+static inline void simcall_io_wait__set__io(smx_simcall_t simcall,
+ boost::intrusive_ptr<simgrid::kernel::activity::ActivityImpl> arg)
{
- simgrid::simix::marshal<sg_size_t>(simcall->args[1], arg);
+ simgrid::simix::marshal<boost::intrusive_ptr<simgrid::kernel::activity::ActivityImpl>>(simcall->args[0], arg);
}
-static inline sg_size_t simcall_storage_write__get__result(smx_simcall_t simcall)
+static inline sg_size_t simcall_io_wait__get__result(smx_simcall_t simcall)
{
return simgrid::simix::unmarshal<sg_size_t>(simcall->result);
}
-static inline sg_size_t simcall_storage_write__getraw__result(smx_simcall_t simcall)
+static inline sg_size_t simcall_io_wait__getraw__result(smx_simcall_t simcall)
{
return simgrid::simix::unmarshal_raw<sg_size_t>(simcall->result);
}
-static inline void simcall_storage_write__set__result(smx_simcall_t simcall, sg_size_t result)
+static inline void simcall_io_wait__set__result(smx_simcall_t simcall, sg_size_t result)
{
simgrid::simix::marshal<sg_size_t>(simcall->result, result);
}
XBT_PRIVATE void simcall_HANDLER_cond_wait_timeout(smx_simcall_t simcall, smx_cond_t cond, smx_mutex_t mutex, double timeout);
XBT_PRIVATE void simcall_HANDLER_sem_acquire(smx_simcall_t simcall, smx_sem_t sem);
XBT_PRIVATE void simcall_HANDLER_sem_acquire_timeout(smx_simcall_t simcall, smx_sem_t sem, double timeout);
-XBT_PRIVATE void simcall_HANDLER_storage_read(smx_simcall_t simcall, surf_storage_t st, sg_size_t size);
-XBT_PRIVATE void simcall_HANDLER_storage_write(smx_simcall_t simcall, surf_storage_t st, sg_size_t size);
+XBT_PRIVATE void simcall_HANDLER_io_wait(smx_simcall_t simcall,
+ boost::intrusive_ptr<simgrid::kernel::activity::ActivityImpl> io);
XBT_PRIVATE int simcall_HANDLER_mc_random(smx_simcall_t simcall, int min, int max);
\ No newline at end of file
return simcall<int, smx_sem_t, double>(SIMCALL_SEM_ACQUIRE_TIMEOUT, sem, timeout);
}
-inline static sg_size_t simcall_BODY_storage_read(surf_storage_t st, sg_size_t size)
+inline static sg_size_t simcall_BODY_io_wait(boost::intrusive_ptr<simgrid::kernel::activity::ActivityImpl> io)
{
if (0) /* Go to that function to follow the code flow through the simcall barrier */
- simcall_HANDLER_storage_read(&SIMIX_process_self()->simcall, st, size);
- return simcall<sg_size_t, surf_storage_t, sg_size_t>(SIMCALL_STORAGE_READ, st, size);
-}
-
-inline static sg_size_t simcall_BODY_storage_write(surf_storage_t st, sg_size_t size)
-{
- if (0) /* Go to that function to follow the code flow through the simcall barrier */
- simcall_HANDLER_storage_write(&SIMIX_process_self()->simcall, st, size);
- return simcall<sg_size_t, surf_storage_t, sg_size_t>(SIMCALL_STORAGE_WRITE, st, size);
+ simcall_HANDLER_io_wait(&SIMIX_process_self()->simcall, io);
+ return simcall<sg_size_t, boost::intrusive_ptr<simgrid::kernel::activity::ActivityImpl>>(SIMCALL_IO_WAIT, io);
}
inline static int simcall_BODY_mc_random(int min, int max)
SIMCALL_COND_WAIT_TIMEOUT,
SIMCALL_SEM_ACQUIRE,
SIMCALL_SEM_ACQUIRE_TIMEOUT,
- SIMCALL_STORAGE_READ,
- SIMCALL_STORAGE_WRITE,
+ SIMCALL_IO_WAIT,
SIMCALL_MC_RANDOM,
SIMCALL_RUN_KERNEL,
SIMCALL_RUN_BLOCKING,
/** @brief Simcalls' names (generated from src/simix/simcalls.in) */
const char* simcall_names[] = {
- "SIMCALL_NONE",
- "SIMCALL_PROCESS_SUSPEND",
- "SIMCALL_PROCESS_JOIN",
- "SIMCALL_PROCESS_SLEEP",
- "SIMCALL_EXECUTION_WAIT",
- "SIMCALL_EXECUTION_TEST",
- "SIMCALL_COMM_IPROBE",
- "SIMCALL_COMM_SEND",
- "SIMCALL_COMM_ISEND",
- "SIMCALL_COMM_RECV",
- "SIMCALL_COMM_IRECV",
- "SIMCALL_COMM_WAITANY",
- "SIMCALL_COMM_WAIT",
- "SIMCALL_COMM_TEST",
- "SIMCALL_COMM_TESTANY",
- "SIMCALL_MUTEX_LOCK",
- "SIMCALL_MUTEX_TRYLOCK",
- "SIMCALL_MUTEX_UNLOCK",
- "SIMCALL_COND_WAIT",
- "SIMCALL_COND_WAIT_TIMEOUT",
- "SIMCALL_SEM_ACQUIRE",
- "SIMCALL_SEM_ACQUIRE_TIMEOUT",
- "SIMCALL_STORAGE_READ",
- "SIMCALL_STORAGE_WRITE",
- "SIMCALL_MC_RANDOM",
- "SIMCALL_RUN_KERNEL",
- "SIMCALL_RUN_BLOCKING",
+ "SIMCALL_NONE", "SIMCALL_PROCESS_SUSPEND", "SIMCALL_PROCESS_JOIN", "SIMCALL_PROCESS_SLEEP",
+ "SIMCALL_EXECUTION_WAIT", "SIMCALL_EXECUTION_TEST", "SIMCALL_COMM_IPROBE", "SIMCALL_COMM_SEND",
+ "SIMCALL_COMM_ISEND", "SIMCALL_COMM_RECV", "SIMCALL_COMM_IRECV", "SIMCALL_COMM_WAITANY",
+ "SIMCALL_COMM_WAIT", "SIMCALL_COMM_TEST", "SIMCALL_COMM_TESTANY", "SIMCALL_MUTEX_LOCK",
+ "SIMCALL_MUTEX_TRYLOCK", "SIMCALL_MUTEX_UNLOCK", "SIMCALL_COND_WAIT", "SIMCALL_COND_WAIT_TIMEOUT",
+ "SIMCALL_SEM_ACQUIRE", "SIMCALL_SEM_ACQUIRE_TIMEOUT", "SIMCALL_IO_WAIT", "SIMCALL_MC_RANDOM",
+ "SIMCALL_RUN_KERNEL", "SIMCALL_RUN_BLOCKING",
};
/** @private
simcall_HANDLER_sem_acquire_timeout(simcall, simgrid::simix::unmarshal<smx_sem_t>(simcall->args[0]), simgrid::simix::unmarshal<double>(simcall->args[1]));
break;
-case SIMCALL_STORAGE_READ:
- simcall_HANDLER_storage_read(simcall, simgrid::simix::unmarshal<surf_storage_t>(simcall->args[0]),
- simgrid::simix::unmarshal<sg_size_t>(simcall->args[1]));
- break;
-
-case SIMCALL_STORAGE_WRITE:
- simcall_HANDLER_storage_write(simcall, simgrid::simix::unmarshal<surf_storage_t>(simcall->args[0]),
- simgrid::simix::unmarshal<sg_size_t>(simcall->args[1]));
+case SIMCALL_IO_WAIT:
+ simcall_HANDLER_io_wait(
+ simcall,
+ simgrid::simix::unmarshal<boost::intrusive_ptr<simgrid::kernel::activity::ActivityImpl>>(simcall->args[0]));
break;
case SIMCALL_MC_RANDOM:
void sem_acquire(smx_sem_t sem) [[block]];
int sem_acquire_timeout(smx_sem_t sem, double timeout) [[block]];
-sg_size_t storage_read(surf_storage_t st, sg_size_t size) [[block]];
-sg_size_t storage_write(surf_storage_t st, sg_size_t size) [[block]];
+sg_size_t io_wait(boost::intrusive_ptr<simgrid::kernel::activity::ActivityImpl> io) [[block]];
int mc_random(int min, int max);
/* This program is free software; you can redistribute it and/or modify it
* under the terms of the license (GNU LGPL) which comes with this package. */
+#include "mc/mc.h"
#include "simgrid/s4u/Host.hpp"
#include "simgrid/s4u/Io.hpp"
#include "xbt/ex.hpp"
#include "smx_private.hpp"
#include "src/kernel/activity/IoImpl.hpp"
+#include "src/mc/mc_replay.hpp"
#include "src/simix/smx_io_private.hpp"
#include "src/surf/StorageImpl.hpp"
return io;
}
-void simcall_HANDLER_storage_read(smx_simcall_t simcall, surf_storage_t st, sg_size_t size)
+void simcall_HANDLER_io_wait(smx_simcall_t simcall, smx_activity_t synchro)
{
- smx_activity_t synchro = SIMIX_storage_read(st, size);
- synchro->simcalls_.push_back(simcall);
- simcall->issuer->waiting_synchro = synchro;
-}
-
-smx_activity_t SIMIX_storage_read(surf_storage_t st, sg_size_t size)
-{
- // simgrid::kernel::activity::IoImpl* synchro = new simgrid::kernel::activity::IoImpl();
- // synchro->surf_action_ = st->read(size);
- //
- // synchro->surf_action_->set_data(synchro);
- // XBT_DEBUG("Create io synchro %p", synchro);
- //
- // return synchro;
- return nullptr;
-}
+ XBT_DEBUG("Wait for execution of synchro %p, state %d", synchro.get(), (int)synchro->state_);
-void simcall_HANDLER_storage_write(smx_simcall_t simcall, surf_storage_t st, sg_size_t size)
-{
- smx_activity_t synchro = SIMIX_storage_write(st, size);
+ /* Associate this simcall to the synchro */
synchro->simcalls_.push_back(simcall);
simcall->issuer->waiting_synchro = synchro;
-}
-smx_activity_t SIMIX_storage_write(surf_storage_t st, sg_size_t size)
-{
- // simgrid::kernel::activity::IoImpl* synchro = new simgrid::kernel::activity::IoImpl();
- // synchro->surf_action_ = st->write(size);
- // synchro->surf_action_->set_data(synchro);
- // XBT_DEBUG("Create io synchro %p", synchro);
- //
- // return synchro;
- return nullptr;
+ /* set surf's synchro */
+ if (MC_is_active() || MC_record_replay_is_active()) {
+ synchro->state_ = SIMIX_DONE;
+ SIMIX_io_finish(synchro);
+ return;
+ }
+
+ /* If the synchro is already finished then perform the error handling */
+ if (synchro->state_ != SIMIX_RUNNING)
+ SIMIX_io_finish(synchro);
}
void SIMIX_io_destroy(smx_activity_t synchro)
simcall->issuer->waiting_synchro = nullptr;
SIMIX_simcall_answer(simcall);
}
-
- /* We no longer need it */
- SIMIX_io_destroy(synchro);
}
#include "simgrid/simix.h"
XBT_PRIVATE simgrid::kernel::activity::IoImplPtr SIMIX_io_start(std::string name, sg_size_t size, sg_storage_t storage,
simgrid::s4u::Io::OpType type);
-XBT_PRIVATE smx_activity_t SIMIX_storage_read(surf_storage_t fd, sg_size_t size);
-XBT_PRIVATE smx_activity_t SIMIX_storage_write(surf_storage_t fd, sg_size_t size);
XBT_PRIVATE void SIMIX_io_destroy(smx_activity_t synchro);
XBT_PRIVATE void SIMIX_io_finish(smx_activity_t synchro);