From 27fe833c49802fa5fbb1e44dc7b99d119fe3aa4b Mon Sep 17 00:00:00 2001 From: Frederic Suter Date: Tue, 12 Mar 2019 14:12:52 +0100 Subject: [PATCH 1/1] use consistent namespaces Storage is a resource, it goes in simgrid::kernel::resource --- include/simgrid/forward.h | 6 +++--- include/simgrid/s4u/Storage.hpp | 18 ++++++++-------- src/include/surf/surf.hpp | 2 -- src/kernel/activity/IoImpl.cpp | 10 ++++----- src/kernel/activity/IoImpl.hpp | 10 ++++----- src/s4u/s4u_Storage.cpp | 16 +++++++------- src/surf/HostImpl.hpp | 4 ++-- src/surf/StorageImpl.cpp | 10 +++++---- src/surf/StorageImpl.hpp | 37 +++++++++++++++++++-------------- src/surf/sg_platf.cpp | 12 +++++------ src/surf/storage_n11.cpp | 21 ++++++++++--------- src/surf/storage_n11.hpp | 12 +++++------ src/surf/surf_interface.cpp | 4 ++-- 13 files changed, 84 insertions(+), 78 deletions(-) diff --git a/include/simgrid/forward.h b/include/simgrid/forward.h index b486383474..fa40a14903 100644 --- a/include/simgrid/forward.h +++ b/include/simgrid/forward.h @@ -140,6 +140,9 @@ class Resource; class NetworkModel; class LinkImpl; class NetworkAction; +class StorageImpl; +class StorageType; +class StorageModel; } namespace routing { class ClusterCreationArgs; @@ -163,9 +166,6 @@ namespace surf { class CpuModel; class HostImpl; class HostModel; - class StorageImpl; - class StorageType; - class StorageModel; } namespace mc { class CommunicationDeterminismChecker; diff --git a/include/simgrid/s4u/Storage.hpp b/include/simgrid/s4u/Storage.hpp index 767a8ac958..4ac16660d7 100644 --- a/include/simgrid/s4u/Storage.hpp +++ b/include/simgrid/s4u/Storage.hpp @@ -26,22 +26,22 @@ namespace s4u { */ class XBT_PUBLIC Storage : public simgrid::xbt::Extendable { - friend simgrid::s4u::Engine; - friend simgrid::s4u::Io; - friend simgrid::surf::StorageImpl; + friend Engine; + friend Io; + friend kernel::resource::StorageImpl; public: - explicit Storage(const std::string& name, surf::StorageImpl* pimpl); + explicit Storage(const std::string& name, kernel::resource::StorageImpl* pimpl); protected: virtual ~Storage() = default; public: /** @brief Callback signal fired when a new Storage is created */ - static simgrid::xbt::signal on_creation; + static xbt::signal on_creation; /** @brief Callback signal fired when a Storage is destroyed */ - static simgrid::xbt::signal on_destruction; + static xbt::signal on_destruction; /** @brief Callback signal fired when a Storage's state changes */ - static simgrid::xbt::signal on_state_change; + static xbt::signal on_state_change; /** Retrieve a Storage by its name. It must exist in the platform file */ static Storage* by_name(const std::string& name); @@ -70,7 +70,7 @@ public: IoPtr write_async(sg_size_t size); sg_size_t write(sg_size_t size); - surf::StorageImpl* get_impl() { return pimpl_; } + kernel::resource::StorageImpl* get_impl() { return pimpl_; } // Deprecated functions #ifndef DOXYGEN @@ -115,7 +115,7 @@ public: private: Host* attached_to_ = nullptr; - surf::StorageImpl* const pimpl_; + kernel::resource::StorageImpl* const pimpl_; std::string name_; void* userdata_ = nullptr; }; diff --git a/src/include/surf/surf.hpp b/src/include/surf/surf.hpp index e6699b11a3..b5b027e67a 100644 --- a/src/include/surf/surf.hpp +++ b/src/include/surf/surf.hpp @@ -18,8 +18,6 @@ XBT_PUBLIC_DATA simgrid::surf::CpuModel* surf_cpu_model_pm; */ XBT_PUBLIC_DATA simgrid::surf::CpuModel* surf_cpu_model_vm; -XBT_PUBLIC_DATA simgrid::surf::StorageModel* surf_storage_model; - /** @ingroup SURF_models * @brief The host model * diff --git a/src/kernel/activity/IoImpl.cpp b/src/kernel/activity/IoImpl.cpp index c76752f8aa..7647a18349 100644 --- a/src/kernel/activity/IoImpl.cpp +++ b/src/kernel/activity/IoImpl.cpp @@ -37,7 +37,7 @@ namespace simgrid { namespace kernel { namespace activity { -IoImpl::IoImpl(const std::string& name, surf::StorageImpl* storage) : ActivityImpl(name), storage_(storage) +IoImpl::IoImpl(const std::string& name, resource::StorageImpl* storage) : ActivityImpl(name), storage_(storage) { this->state_ = SIMIX_RUNNING; @@ -51,13 +51,13 @@ IoImpl::~IoImpl() XBT_DEBUG("Destroy io %p", this); } -IoImpl* IoImpl::start(sg_size_t size, simgrid::s4u::Io::OpType type) +IoImpl* IoImpl::start(sg_size_t size, s4u::Io::OpType type) { surf_action_ = storage_->io_start(size, type); surf_action_->set_data(this); XBT_DEBUG("Create IO synchro %p %s", this, get_cname()); - simgrid::kernel::activity::IoImpl::on_start(this); + IoImpl::on_start(this); return this; } @@ -79,10 +79,10 @@ void IoImpl::post() { performed_ioops_ = surf_action_->get_cost(); switch (surf_action_->get_state()) { - case simgrid::kernel::resource::Action::State::FAILED: + case resource::Action::State::FAILED: state_ = SIMIX_FAILED; break; - case simgrid::kernel::resource::Action::State::FINISHED: + case resource::Action::State::FINISHED: state_ = SIMIX_DONE; break; default: diff --git a/src/kernel/activity/IoImpl.hpp b/src/kernel/activity/IoImpl.hpp index 0577069f23..653d191517 100644 --- a/src/kernel/activity/IoImpl.hpp +++ b/src/kernel/activity/IoImpl.hpp @@ -17,19 +17,19 @@ namespace activity { class XBT_PUBLIC IoImpl : public ActivityImpl { public: ~IoImpl() override; - explicit IoImpl(const std::string& name, surf::StorageImpl* storage); + explicit IoImpl(const std::string& name, resource::StorageImpl* storage); - IoImpl* start(sg_size_t size, simgrid::s4u::Io::OpType type); + IoImpl* start(sg_size_t size, s4u::Io::OpType type); void post() override; void finish() override; void cancel(); double get_remaining(); sg_size_t get_performed_ioops() { return performed_ioops_; } - surf::StorageImpl* storage_ = nullptr; + resource::StorageImpl* storage_ = nullptr; sg_size_t performed_ioops_ = 0; - static simgrid::xbt::signal on_start; - static simgrid::xbt::signal on_completion; + static xbt::signal on_start; + static xbt::signal on_completion; }; } } diff --git a/src/s4u/s4u_Storage.cpp b/src/s4u/s4u_Storage.cpp index 5aaf6ebff5..09fb1063bc 100644 --- a/src/s4u/s4u_Storage.cpp +++ b/src/s4u/s4u_Storage.cpp @@ -13,17 +13,17 @@ namespace simgrid { namespace xbt { template class Extendable; -} +} // namespace xbt namespace s4u { -simgrid::xbt::signal Storage::on_creation; -simgrid::xbt::signal Storage::on_destruction; -simgrid::xbt::signal Storage::on_state_change; +xbt::signal Storage::on_creation; +xbt::signal Storage::on_destruction; +xbt::signal Storage::on_state_change; -Storage::Storage(const std::string& name, surf::StorageImpl* pimpl) : pimpl_(pimpl), name_(name) +Storage::Storage(const std::string& name, kernel::resource::StorageImpl* pimpl) : pimpl_(pimpl), name_(name) { - simgrid::s4u::Engine::get_instance()->storage_register(name_, this); + Engine::get_instance()->storage_register(name_, this); } Storage* Storage::by_name(const std::string& name) @@ -82,8 +82,8 @@ sg_size_t Storage::write(sg_size_t size) return IoPtr(io_init(size, Io::OpType::WRITE))->start()->wait()->get_performed_ioops(); } -} /* namespace s4u */ -} /* namespace simgrid */ +} // namespace s4u +} // namespace simgrid /* **************************** Public C interface *************************** */ diff --git a/src/surf/HostImpl.hpp b/src/surf/HostImpl.hpp index 1b480a59ae..d1fff38817 100644 --- a/src/surf/HostImpl.hpp +++ b/src/surf/HostImpl.hpp @@ -50,8 +50,8 @@ public: /** @brief Get the vector of storages (by names) attached to the Host */ virtual std::vector get_attached_storages(); - std::map storage_; - simgrid::s4u::Host* piface_ = nullptr; + std::map storage_; + s4u::Host* piface_ = nullptr; void turn_on(); void turn_off(); diff --git a/src/surf/StorageImpl.cpp b/src/surf/StorageImpl.cpp index 7870a89968..18c9ac67d4 100644 --- a/src/surf/StorageImpl.cpp +++ b/src/surf/StorageImpl.cpp @@ -11,10 +11,11 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_storage, surf, "Logging specific to the SURF storage module"); -simgrid::surf::StorageModel* surf_storage_model = nullptr; +simgrid::kernel::resource::StorageModel* surf_storage_model = nullptr; namespace simgrid { -namespace surf { +namespace kernel { +namespace resource { /********* * Model * @@ -104,5 +105,6 @@ void StorageAction::set_state(Action::State state) Action::set_state(state); on_state_change(this, old, state); } -} -} +} // namespace resource +} // namespace kernel +} // namespace simgrid diff --git a/src/surf/StorageImpl.hpp b/src/surf/StorageImpl.hpp index 083c020a10..70d8e4b618 100644 --- a/src/surf/StorageImpl.hpp +++ b/src/surf/StorageImpl.hpp @@ -17,9 +17,15 @@ #ifndef STORAGE_INTERFACE_HPP_ #define STORAGE_INTERFACE_HPP_ -namespace simgrid { -namespace surf { +/********* + * Model * + *********/ + +XBT_PUBLIC_DATA simgrid::kernel::resource::StorageModel* surf_storage_model; +namespace simgrid { +namespace kernel { +namespace resource { /*********** * Classes * ***********/ @@ -66,12 +72,11 @@ public: * @brief SURF storage interface class * @details A Storage represent a storage unit (e.g.: hard drive, usb key) */ -class StorageImpl : public kernel::resource::Resource, public PropertyHolder { +class StorageImpl : public Resource, public surf::PropertyHolder { public: /** @brief Storage constructor */ - StorageImpl(kernel::resource::Model* model, const std::string& name, kernel::lmm::System* maxmin_system, double bread, - double bwrite, const std::string& type_id, const std::string& content_name, sg_size_t size, - const std::string& attach); + StorageImpl(Model* model, const std::string& name, kernel::lmm::System* maxmin_system, double bread, double bwrite, + const std::string& type_id, const std::string& content_name, sg_size_t size, const std::string& attach); StorageImpl(const StorageImpl&) = delete; StorageImpl& operator=(const StorageImpl&) = delete; @@ -83,13 +88,13 @@ public: /** @brief Check if the Storage is used (if an action currently uses its resources) */ bool is_used() override; - void apply_event(simgrid::kernel::profile::Event* event, double value) override; + void apply_event(profile::Event* event, double value) override; void turn_on() override; 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; + virtual Action* io_start(sg_size_t size, s4u::Io::OpType type) = 0; /** * @brief Read a file * @@ -107,8 +112,8 @@ public: virtual StorageAction* write(sg_size_t size) = 0; virtual std::string getHost() { return attach_; } - kernel::lmm::Constraint* constraintWrite_; /* Constraint for maximum write bandwidth*/ - kernel::lmm::Constraint* constraintRead_; /* Constraint for maximum write bandwidth*/ + lmm::Constraint* constraintWrite_; /* Constraint for maximum write bandwidth*/ + lmm::Constraint* constraintRead_; /* Constraint for maximum write bandwidth*/ std::string typeId_; std::string content_name; // Only used at parsing time then goes to the FileSystemExtension @@ -128,10 +133,9 @@ private: /** @ingroup SURF_storage_interface * @brief SURF storage action interface class */ -class StorageAction : public kernel::resource::Action { +class StorageAction : public Action { public: - static xbt::signal - on_state_change; + static xbt::signal on_state_change; /** * @brief StorageAction constructor @@ -142,7 +146,7 @@ public: * @param storage The Storage associated to this StorageAction * @param type [description] */ - StorageAction(kernel::resource::Model* model, double cost, bool failed, StorageImpl* storage, s4u::Io::OpType type) + StorageAction(Model* model, double cost, bool failed, StorageImpl* storage, s4u::Io::OpType type) : Action(model, cost, failed), type_(type), storage_(storage){}; /** @@ -180,7 +184,8 @@ public: { } }; -} -} +} // namespace resource +} // namespace kernel +} // namespace simgrid #endif /* STORAGE_INTERFACE_HPP_ */ diff --git a/src/surf/sg_platf.cpp b/src/surf/sg_platf.cpp index 4070803849..dc1d5c30e3 100644 --- a/src/surf/sg_platf.cpp +++ b/src/surf/sg_platf.cpp @@ -27,7 +27,7 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_parse); -XBT_PRIVATE std::map mount_list; +XBT_PRIVATE std::map mount_list; XBT_PRIVATE std::vector known_storages; namespace simgrid { @@ -38,7 +38,7 @@ simgrid::xbt::signal on_cluster; } static int surf_parse_models_setup_already_called = 0; -std::map storage_types; +std::map storage_types; /** The current AS in the parsing */ static simgrid::kernel::routing::NetZoneImpl* current_routing = nullptr; @@ -333,7 +333,7 @@ void sg_platf_new_storage(simgrid::kernel::routing::StorageCreationArgs* storage xbt_assert(std::find(known_storages.begin(), known_storages.end(), storage->id) == known_storages.end(), "Refusing to add a second storage named \"%s\"", storage->id.c_str()); - simgrid::surf::StorageType* stype; + simgrid::kernel::resource::StorageType* stype; auto st = storage_types.find(storage->type_id); if (st != storage_types.end()) { stype = st->second; @@ -373,9 +373,9 @@ void sg_platf_new_storage_type(simgrid::kernel::routing::StorageTypeCreationArgs xbt_assert(storage_types.find(storage_type->id) == storage_types.end(), "Reading a storage type, processing unit \"%s\" already exists", storage_type->id.c_str()); - simgrid::surf::StorageType* stype = - new simgrid::surf::StorageType(storage_type->id, storage_type->model, storage_type->content, - storage_type->properties, storage_type->model_properties, storage_type->size); + simgrid::kernel::resource::StorageType* stype = new simgrid::kernel::resource::StorageType( + storage_type->id, storage_type->model, storage_type->content, storage_type->properties, + storage_type->model_properties, storage_type->size); XBT_DEBUG("Create a storage type id '%s' with model '%s', content '%s'", storage_type->id.c_str(), storage_type->model.c_str(), storage_type->content.c_str()); diff --git a/src/surf/storage_n11.cpp b/src/surf/storage_n11.cpp index c13aa4629f..82aa54a851 100644 --- a/src/surf/storage_n11.cpp +++ b/src/surf/storage_n11.cpp @@ -15,7 +15,7 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_storage); /************* * CallBacks * *************/ -extern std::map storage_types; +extern std::map storage_types; void check_disk_attachment() { @@ -35,11 +35,12 @@ void check_disk_attachment() void surf_storage_model_init_default() { - surf_storage_model = new simgrid::surf::StorageN11Model(); + surf_storage_model = new simgrid::kernel::resource::StorageN11Model(); } namespace simgrid { -namespace surf { +namespace kernel { +namespace resource { StorageN11Model::StorageN11Model() { @@ -78,7 +79,7 @@ void StorageN11Model::update_actions_state(double /*now*/, double delta) if (((action.get_remains_no_update() <= 0) && (action.get_variable()->get_weight() > 0)) || ((action.get_max_duration() != NO_MAX_DURATION) && (action.get_max_duration() <= 0))) { - action.finish(kernel::resource::Action::State::FINISHED); + action.finish(Action::State::FINISHED); } } } @@ -87,13 +88,13 @@ void StorageN11Model::update_actions_state(double /*now*/, double delta) * Resource * ************/ -StorageN11::StorageN11(StorageModel* model, const std::string& name, kernel::lmm::System* maxminSystem, double bread, +StorageN11::StorageN11(StorageModel* model, const std::string& name, lmm::System* maxminSystem, double bread, double bwrite, const std::string& type_id, const std::string& content_name, sg_size_t size, const std::string& attach) : StorageImpl(model, name, maxminSystem, bread, bwrite, type_id, content_name, size, attach) { XBT_DEBUG("Create resource with Bread '%f' Bwrite '%f' and Size '%llu'", bread, bwrite, size); - simgrid::s4u::Storage::on_creation(this->piface_); + s4u::Storage::on_creation(this->piface_); } StorageAction* StorageN11::io_start(sg_size_t size, s4u::Io::OpType type) @@ -115,8 +116,7 @@ StorageAction* StorageN11::write(sg_size_t size) * Action * **********/ -StorageN11Action::StorageN11Action(kernel::resource::Model* model, double cost, bool failed, StorageImpl* storage, - s4u::Io::OpType type) +StorageN11Action::StorageN11Action(Model* model, double cost, bool failed, StorageImpl* storage, 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); @@ -169,5 +169,6 @@ void StorageN11Action::update_remains_lazy(double /*now*/) { THROW_IMPOSSIBLE; } -} -} +} // namespace resource +} // namespace kernel +} // namespace simgrid diff --git a/src/surf/storage_n11.hpp b/src/surf/storage_n11.hpp index 66827083ad..4d4f67c336 100644 --- a/src/surf/storage_n11.hpp +++ b/src/surf/storage_n11.hpp @@ -11,7 +11,8 @@ #define STORAGE_N11_HPP_ namespace simgrid { -namespace surf { +namespace kernel { +namespace resource { /*********** * Classes * @@ -55,8 +56,7 @@ public: class StorageN11Action : public StorageAction { public: - StorageN11Action(kernel::resource::Model* model, double cost, bool failed, StorageImpl* storage, - s4u::Io::OpType type); + StorageN11Action(Model* model, double cost, bool failed, StorageImpl* storage, s4u::Io::OpType type); void suspend() override; void cancel() override; void resume() override; @@ -65,7 +65,7 @@ public: void update_remains_lazy(double now) override; }; -} -} - +} // namespace resource +} // namespace kernel +} // namespace simgrid #endif /* STORAGE_N11_HPP_ */ diff --git a/src/surf/surf_interface.cpp b/src/surf/surf_interface.cpp index 71a9f87f1e..8beb759567 100644 --- a/src/surf/surf_interface.cpp +++ b/src/surf/surf_interface.cpp @@ -34,7 +34,7 @@ simgrid::kernel::profile::FutureEvtSet future_evt_set; std::vector surf_path; /** set of hosts for which one want to be notified if they ever restart. */ std::set watched_hosts; -extern std::map storage_types; +extern std::map storage_types; s_surf_model_description_t* surf_plugin_description = nullptr; XBT_PUBLIC void simgrid_add_plugin_description(const char* name, const char* description, void_f_void_t init_fun) @@ -305,7 +305,7 @@ void surf_exit() { simgrid::s4u::Engine::shutdown(); for (auto const& e : storage_types) { - simgrid::surf::StorageType* stype = e.second; + simgrid::kernel::resource::StorageType* stype = e.second; delete stype->properties; delete stype->model_properties; delete stype; -- 2.20.1