XBT_PUBLIC void intrusive_ptr_release(Exec* e);
XBT_PUBLIC void intrusive_ptr_add_ref(Exec* e);
class Host;
+class Io;
+using IoPtr = boost::intrusive_ptr<Io>;
+XBT_PUBLIC void intrusive_ptr_release(Io* i);
+XBT_PUBLIC void intrusive_ptr_add_ref(Io* i);
class Link;
class Mailbox;
using MailboxPtr = boost::intrusive_ptr<Mailbox>;
friend Exec;
friend XBT_PUBLIC void intrusive_ptr_release(Exec * e);
friend XBT_PUBLIC void intrusive_ptr_add_ref(Exec * e);
+ friend Io;
+ friend XBT_PUBLIC void intrusive_ptr_release(Io* i);
+ friend XBT_PUBLIC void intrusive_ptr_add_ref(Io* i);
protected:
Activity() = default;
--- /dev/null
+/* Copyright (c) 2017-2018. The SimGrid Team. All rights reserved. */
+
+/* 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. */
+
+#ifndef SIMGRID_S4U_IO_HPP
+#define SIMGRID_S4U_IO_HPP
+
+#include <simgrid/forward.h>
+#include <simgrid/s4u/Activity.hpp>
+
+#include <atomic>
+
+namespace simgrid {
+namespace s4u {
+
+class XBT_PUBLIC Io : public Activity {
+ explicit Io(sg_size_t size) : Activity(), size_(size) {}
+public:
+ friend XBT_PUBLIC void intrusive_ptr_release(simgrid::s4u::Io* i);
+ friend XBT_PUBLIC void intrusive_ptr_add_ref(simgrid::s4u::Io* i);
+ friend Storage; // Factory of IOs
+
+ enum class OpType { READ, WRITE };
+ ~Io() = default;
+
+ Activity* start() override;
+ Activity* wait() override;
+ Activity* wait(double timeout) override;
+ Activity* cancel() override;
+
+ double get_remaining() override;
+ sg_size_t get_performed_ioops();
+ IoPtr set_io_type(OpType type);
+
+private:
+ sg_size_t size_ = 0;
+ sg_storage_t storage_ = nullptr;
+ std::string name_ = "";
+ OpType type_ = OpType::READ;
+ std::atomic_int_fast32_t refcount_{0};
+}; // class
+}
+}; // Namespace simgrid::s4u
+
+#endif /* SIMGRID_S4U_IO_HPP */
#include <simgrid/forward.h>
#include <xbt/Extendable.hpp>
#include <xbt/base.h>
+#include <xbt/signal.hpp>
#include <map>
#include <string>
class XBT_PUBLIC Storage : public simgrid::xbt::Extendable<Storage> {
friend s4u::Engine;
+ friend s4u::Io;
friend simgrid::surf::StorageImpl;
public:
protected:
virtual ~Storage() = default;
-
public:
/** @brief Callback signal fired when a new Storage is created */
static simgrid::xbt::signal<void(s4u::Storage&)> on_creation;
void set_data(void* data) { userdata_ = data; }
void* get_data() { return userdata_; }
+ IoPtr io_init(sg_size_t size);
+
sg_size_t read(sg_size_t size);
sg_size_t write(sg_size_t size);
surf::StorageImpl* get_impl() { return pimpl_; }
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);
#include "simgrid/kernel/resource/Action.hpp"
#include "src/simix/smx_io_private.hpp"
+XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix_io);
+
+simgrid::kernel::activity::IoImpl::IoImpl(std::string name, resource::Action* surf_action, s4u::Storage* storage)
+ : ActivityImpl(name), storage_(storage), surf_action_(surf_action)
+{
+ this->state_ = SIMIX_RUNNING;
+
+ surf_action_->set_data(this);
+
+ XBT_DEBUG("Create io %p", this);
+}
+
+simgrid::kernel::activity::IoImpl::~IoImpl()
+{
+ if (surf_action_ != nullptr)
+ surf_action_->unref();
+ XBT_DEBUG("Destroy io %p", this);
+}
+
+void simgrid::kernel::activity::IoImpl::cancel()
+{
+ XBT_VERB("This exec %p is canceled", this);
+ if (surf_action_ != nullptr)
+ surf_action_->cancel();
+}
+
void simgrid::kernel::activity::IoImpl::suspend()
{
if (surf_action_ != nullptr)
surf_action_->resume();
}
-void simgrid::kernel::activity::IoImpl::post()
+double simgrid::kernel::activity::IoImpl::get_remaining()
{
- 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;
- }
- }
+ return surf_action_ ? surf_action_->get_remains() : 0;
+}
+void simgrid::kernel::activity::IoImpl::post()
+{
+ performed_ioops_ = surf_action_->get_cost();
switch (surf_action_->get_state()) {
case simgrid::kernel::resource::Action::State::FAILED:
state_ = SIMIX_FAILED;
THROW_IMPOSSIBLE;
break;
}
+ on_completion(this);
SIMIX_io_finish(this);
}
+/*************
+ * Callbacks *
+ *************/
+simgrid::xbt::signal<void(simgrid::kernel::activity::IoImplPtr)> simgrid::kernel::activity::IoImpl::on_creation;
+simgrid::xbt::signal<void(simgrid::kernel::activity::IoImplPtr)> simgrid::kernel::activity::IoImpl::on_completion;
class XBT_PUBLIC IoImpl : public ActivityImpl {
public:
+ ~IoImpl() override;
+ explicit IoImpl(std::string name, resource::Action* surf_action, s4u::Storage* storage);
+
void suspend() override;
void resume() override;
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;
};
}
}
--- /dev/null
+/* Copyright (c) 2018. The SimGrid Team. All rights reserved. */
+
+/* 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 "simgrid/s4u/Io.hpp"
+#include "simgrid/s4u/Storage.hpp"
+#include "src/kernel/activity/IoImpl.hpp"
+#include "src/simix/smx_io_private.hpp"
+#include "xbt/log.h"
+
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(s4u_io, s4u_activity, "S4U asynchronous IOs");
+
+namespace simgrid {
+namespace s4u {
+
+Activity* Io::start()
+{
+ set_remaining(size_);
+ pimpl_ = simix::simcall([this] { return SIMIX_io_start(name_, size_, storage_, type_); });
+ state_ = State::STARTED;
+ return this;
+}
+
+Activity* Io::cancel()
+{
+ simgrid::simix::simcall([this] { dynamic_cast<kernel::activity::IoImpl*>(pimpl_.get())->cancel(); });
+ state_ = State::CANCELED;
+ return this;
+}
+
+Activity* Io::wait()
+{
+ simcall_io_wait(pimpl_);
+ state_ = State::FINISHED;
+ return this;
+}
+
+Activity* Io::wait(double timeout)
+{
+ THROW_UNIMPLEMENTED;
+ return this;
+}
+
+/** @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<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)
+{
+ xbt_assert(state_ == State::INITED, "Cannot change the name of an exec after its start");
+ type_ = type;
+ return this;
+}
+
+void intrusive_ptr_release(simgrid::s4u::Io* i)
+{
+ if (i->refcount_.fetch_sub(1, std::memory_order_release) == 1) {
+ std::atomic_thread_fence(std::memory_order_acquire);
+ delete i;
+ }
+}
+
+void intrusive_ptr_add_ref(simgrid::s4u::Io* i)
+{
+ i->refcount_.fetch_add(1, std::memory_order_relaxed);
+}
+} // namespace s4u
+} // namespace simgrid
#include "simgrid/s4u/Engine.hpp"
#include "simgrid/s4u/Host.hpp"
+#include "simgrid/s4u/Io.hpp"
#include "simgrid/s4u/Storage.hpp"
#include "simgrid/storage.h"
#include "src/surf/StorageImpl.hpp"
simgrid::simix::simcall([this, key, value] { this->pimpl_->set_property(key, value); });
}
+IoPtr Storage::io_init(sg_size_t size)
+{
+ IoPtr res = IoPtr(new Io(size));
+ res->storage_ = this;
+ 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
SIMIX_synchro_stop_waiting(process, &process->simcall);
} else if (io != nullptr) {
- SIMIX_io_destroy(process->waiting_synchro);
+ delete io.get();
} else {
xbt_die("Unknown type of activity");
}
simgrid::kernel::activity::IoImplPtr io =
boost::dynamic_pointer_cast<simgrid::kernel::activity::IoImpl>(process->waiting_synchro);
if (io != nullptr) {
- SIMIX_io_destroy(process->waiting_synchro);
+ delete io.get();
}
}
process->waiting_synchro = nullptr;
#include "src/kernel/activity/CommImpl.hpp"
#include "src/kernel/activity/ConditionVariableImpl.hpp"
#include "src/kernel/activity/ExecImpl.hpp"
+#include "src/kernel/activity/IoImpl.hpp"
#include "src/kernel/activity/MutexImpl.hpp"
#include "src/mc/mc_replay.hpp"
#include "src/plugins/vm/VirtualMachineImpl.hpp"
#include "src/simix/smx_host_private.hpp"
+#include "src/simix/smx_io_private.hpp"
XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix);
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"
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_io, simix, "Logging specific to SIMIX (io)");
-void simcall_HANDLER_storage_read(smx_simcall_t simcall, surf_storage_t st, sg_size_t size)
+simgrid::kernel::activity::IoImplPtr SIMIX_io_start(std::string name, sg_size_t size, sg_storage_t storage,
+ simgrid::s4u::Io::OpType type)
{
- smx_activity_t synchro = SIMIX_storage_read(st, size);
- synchro->simcalls_.push_back(simcall);
- simcall->issuer->waiting_synchro = synchro;
-}
+ /* set surf's action */
+ simgrid::kernel::resource::Action* surf_action = storage->get_impl()->io_start(size, type);
-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);
+ simgrid::kernel::activity::IoImplPtr io =
+ simgrid::kernel::activity::IoImplPtr(new simgrid::kernel::activity::IoImpl(name, surf_action, storage));
- synchro->surf_action_->set_data(synchro);
- XBT_DEBUG("Create io synchro %p", synchro);
+ XBT_DEBUG("Create IO synchro %p %s", io.get(), name.c_str());
+ simgrid::kernel::activity::IoImpl::on_creation(io);
- return synchro;
+ return io;
}
-void simcall_HANDLER_storage_write(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_write(st, size);
+ XBT_DEBUG("Wait for execution of synchro %p, state %d", synchro.get(), (int)synchro->state_);
+
+ /* 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;
-}
+ /* set surf's synchro */
+ if (MC_is_active() || MC_record_replay_is_active()) {
+ synchro->state_ = SIMIX_DONE;
+ SIMIX_io_finish(synchro);
+ return;
+ }
-void SIMIX_io_destroy(smx_activity_t synchro)
-{
- simgrid::kernel::activity::IoImplPtr io = boost::static_pointer_cast<simgrid::kernel::activity::IoImpl>(synchro);
- XBT_DEBUG("Destroy synchro %p", synchro.get());
- if (io->surf_action_)
- io->surf_action_->unref();
+ /* If the synchro is already finished then perform the error handling */
+ if (synchro->state_ != SIMIX_RUNNING)
+ SIMIX_io_finish(synchro);
}
void SIMIX_io_finish(smx_activity_t synchro)
simcall->issuer->waiting_synchro = nullptr;
SIMIX_simcall_answer(simcall);
}
-
- /* We no longer need it */
- SIMIX_io_destroy(synchro);
}
#define SIMIX_IO_PRIVATE_HPP
#include <xbt/base.h>
+#include "simgrid/s4u/Io.hpp"
-#include "popping_private.hpp"
-#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);
#endif
#include "simgrid/kernel/resource/Action.hpp"
#include "simgrid/kernel/resource/Model.hpp"
#include "simgrid/kernel/resource/Resource.hpp"
+#include "simgrid/s4u/Io.hpp"
#include "simgrid/s4u/Storage.hpp"
#include "src/surf/PropertyHolder.hpp"
#include "src/surf/trace_mgr.hpp"
***********/
class StorageAction;
-
+/** @ingroup SURF_storage_interface
+ * @brief The possible type of action for the storage component
+ */
/*************
* Callbacks *
*************/
void turn_off() override;
void destroy(); // Must be called instead of the destructor
-
+ virtual simgrid::kernel::resource::Action* io_start(sg_size_t size, s4u::Io::OpType type) = 0;
/**
* @brief Read a file
*
* Action *
**********/
-/** @ingroup SURF_storage_interface
- * @brief The possible type of action for the storage component
- */
-enum e_surf_action_storage_type_t {
- READ = 0, /**< Read a file */
- WRITE /**< Write in a file */
-};
-
/** @ingroup SURF_storage_interface
* @brief SURF storage action interface class
*/
* @param storage The Storage associated to this StorageAction
* @param type [description]
*/
- StorageAction(kernel::resource::Model* model, double cost, bool failed, StorageImpl* storage,
- e_surf_action_storage_type_t type)
+ StorageAction(kernel::resource::Model* model, double cost, bool failed, StorageImpl* storage, s4u::Io::OpType type)
: Action(model, cost, failed), type_(type), storage_(storage){};
/**
* @param type [description]
*/
StorageAction(kernel::resource::Model* model, double cost, bool failed, kernel::lmm::Variable* var,
- StorageImpl* storage, e_surf_action_storage_type_t type)
+ StorageImpl* storage, s4u::Io::OpType type)
: Action(model, cost, failed, var), type_(type), storage_(storage){};
void set_state(simgrid::kernel::resource::Action::State state) override;
- e_surf_action_storage_type_t type_;
+ s4u::Io::OpType type_;
StorageImpl* storage_;
};
simgrid::s4u::Storage::on_creation(this->piface_);
}
+StorageAction* StorageN11::io_start(sg_size_t size, s4u::Io::OpType type)
+{
+ return new StorageN11Action(get_model(), size, is_off(), this, type);
+}
+
StorageAction* StorageN11::read(sg_size_t size)
{
- return new StorageN11Action(get_model(), size, is_off(), this, READ);
+ return new StorageN11Action(get_model(), size, is_off(), this, s4u::Io::OpType::READ);
}
StorageAction* StorageN11::write(sg_size_t size)
{
- return new StorageN11Action(get_model(), size, is_off(), this, WRITE);
+ return new StorageN11Action(get_model(), size, is_off(), this, s4u::Io::OpType::WRITE);
}
/**********
**********/
StorageN11Action::StorageN11Action(kernel::resource::Model* model, double cost, bool failed, StorageImpl* storage,
- e_surf_action_storage_type_t type)
+ s4u::Io::OpType type)
: StorageAction(model, cost, failed, model->get_maxmin_system()->variable_new(this, 1.0, -1.0, 3), storage, type)
{
XBT_IN("(%s,%g", storage->get_cname(), cost);
// Must be less than the max bandwidth for all actions
model->get_maxmin_system()->expand(storage->get_constraint(), get_variable(), 1.0);
switch(type) {
- case READ:
- model->get_maxmin_system()->expand(storage->constraintRead_, get_variable(), 1.0);
- break;
- case WRITE:
- model->get_maxmin_system()->expand(storage->constraintWrite_, get_variable(), 1.0);
- break;
- default:
- THROW_UNIMPLEMENTED;
+ case s4u::Io::OpType::READ:
+ model->get_maxmin_system()->expand(storage->constraintRead_, get_variable(), 1.0);
+ break;
+ case s4u::Io::OpType::WRITE:
+ model->get_maxmin_system()->expand(storage->constraintWrite_, get_variable(), 1.0);
+ break;
+ default:
+ THROW_UNIMPLEMENTED;
}
XBT_OUT();
}
StorageN11(StorageModel* model, std::string name, kernel::lmm::System* maxminSystem, double bread, double bwrite,
std::string type_id, std::string content_name, sg_size_t size, std::string attach);
virtual ~StorageN11() = default;
+ StorageAction* io_start(sg_size_t size, s4u::Io::OpType type);
StorageAction* read(sg_size_t size);
StorageAction* write(sg_size_t size);
};
class StorageN11Action : public StorageAction {
public:
StorageN11Action(kernel::resource::Model* model, double cost, bool failed, StorageImpl* storage,
- e_surf_action_storage_type_t type);
+ s4u::Io::OpType type);
void suspend() override;
void cancel() override;
void resume() override;
src/s4u/s4u_Engine.cpp
src/s4u/s4u_Exec.cpp
src/s4u/s4u_Host.cpp
+ src/s4u/s4u_Io.cpp
src/s4u/s4u_Link.cpp
src/s4u/s4u_Mailbox.cpp
src/s4u/s4u_Mutex.cpp
include/simgrid/s4u/Engine.hpp
include/simgrid/s4u/Exec.hpp
include/simgrid/s4u/Host.hpp
+ include/simgrid/s4u/Io.hpp
include/simgrid/s4u/Link.hpp
include/simgrid/s4u/Mailbox.hpp
include/simgrid/s4u/Mutex.hpp