From 4c98af3dcf6ab83a095d195accad6943379ab220 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Wed, 11 Apr 2018 09:21:16 +0200 Subject: [PATCH] further cut include files --- include/simgrid/s4u/Actor.hpp | 16 +---- include/simgrid/s4u/Comm.hpp | 55 ++++------------- include/simgrid/s4u/ConditionVariable.hpp | 13 +--- include/simgrid/s4u/Exec.hpp | 1 - include/simgrid/s4u/Mutex.hpp | 24 ++------ include/xbt/xbt_os_thread.h | 5 +- src/include/xbt/parmap.hpp | 11 +--- src/kernel/context/ContextBoost.hpp | 1 - src/kernel/context/ContextRaw.cpp | 2 +- src/kernel/context/ContextRaw.hpp | 5 -- src/s4u/s4u_comm.cpp | 75 ++++++++++++++++------- src/s4u/s4u_mailbox.cpp | 4 +- src/s4u/s4u_mutex.cpp | 11 ++++ src/surf/cpu_cas01.hpp | 3 +- src/surf/plugins/dirty_page_tracking.cpp | 2 - src/surf/plugins/host_dvfs.cpp | 10 +-- src/surf/plugins/host_energy.cpp | 5 -- src/surf/plugins/host_load.cpp | 10 --- src/surf/plugins/link_energy.cpp | 1 - 19 files changed, 95 insertions(+), 159 deletions(-) diff --git a/include/simgrid/s4u/Actor.hpp b/include/simgrid/s4u/Actor.hpp index 25f2ede6ec..a91b18bb08 100644 --- a/include/simgrid/s4u/Actor.hpp +++ b/include/simgrid/s4u/Actor.hpp @@ -6,23 +6,11 @@ #ifndef SIMGRID_S4U_ACTOR_HPP #define SIMGRID_S4U_ACTOR_HPP -#include -#include -#include -#include -#include -#include -#include -#include -#include - +#include #include #include -#include #include - -#include -#include +#include namespace simgrid { namespace s4u { diff --git a/include/simgrid/s4u/Comm.hpp b/include/simgrid/s4u/Comm.hpp index b39f8ba4cf..be8ccf375f 100644 --- a/include/simgrid/s4u/Comm.hpp +++ b/include/simgrid/s4u/Comm.hpp @@ -6,14 +6,8 @@ #ifndef SIMGRID_S4U_COMM_HPP #define SIMGRID_S4U_COMM_HPP -#include -#include -#include - #include #include -#include -#include #include #include @@ -37,35 +31,10 @@ public: * The return value is the rank of the first finished CommPtr. */ static int wait_any(std::vector * comms) { return wait_any_for(comms, -1); } /*! Same as wait_any, but with a timeout. If the timeout occurs, parameter last is returned.*/ - static int wait_any_for(std::vector * comms_in, double timeout) - { - // Map to dynar: - xbt_dynar_t comms = xbt_dynar_new(sizeof(simgrid::kernel::activity::ActivityImpl*), [](void*ptr){ - intrusive_ptr_release(*(simgrid::kernel::activity::ActivityImpl**)ptr); - }); - for (auto const& comm : *comms_in) { - if (comm->state_ == Activity::State::inited) - comm->start(); - xbt_assert(comm->state_ == Activity::State::started); - simgrid::kernel::activity::ActivityImpl* ptr = comm->pimpl_.get(); - intrusive_ptr_add_ref(ptr); - xbt_dynar_push_as(comms, simgrid::kernel::activity::ActivityImpl*, ptr); - } - // Call the underlying simcall: - int idx = simcall_comm_waitany(comms, timeout); - xbt_dynar_free(&comms); - return idx; - } + static int wait_any_for(std::vector* comms_in, double timeout); /*! take a vector s4u::CommPtr and return when all of them is finished. */ - static void wait_all(std::vector * comms) - { - // TODO: this should be a simcall or something - // TODO: we are missing a version with timeout - for (CommPtr comm : *comms) { - comm->wait(); - } - } + static void wait_all(std::vector* comms); /*! take a vector s4u::CommPtr and return the rank of the first finished one (or -1 if none is done). */ static int test_any(std::vector * comms); @@ -78,7 +47,7 @@ public: /** Start the comm, and ignore its result. It can be completely forgotten after that. */ Activity* detach(void (*cleanFunction)(void*)) { - cleanFunction_ = cleanFunction; + clean_fun_ = cleanFunction; return detach(); } @@ -134,16 +103,16 @@ public: private: double rate_ = -1; - void* dstBuff_ = nullptr; - size_t dstBuffSize_ = 0; - void* srcBuff_ = nullptr; - size_t srcBuffSize_ = sizeof(void*); + void* dst_buff_ = nullptr; + size_t dst_buff_size_ = 0; + void* src_buff_ = nullptr; + size_t src_buff_size_ = sizeof(void*); /* FIXME: expose these elements in the API */ int detached_ = 0; - int (*matchFunction_)(void*, void*, simgrid::kernel::activity::CommImpl*) = nullptr; - void (*cleanFunction_)(void*) = nullptr; - void (*copyDataFunction_)(smx_activity_t, void*, size_t) = nullptr; + int (*match_fun_)(void*, void*, simgrid::kernel::activity::CommImpl*) = nullptr; + void (*clean_fun_)(void*) = nullptr; + void (*copy_data_function_)(smx_activity_t, void*, size_t) = nullptr; smx_actor_t sender_ = nullptr; smx_actor_t receiver_ = nullptr; @@ -151,7 +120,7 @@ private: std::atomic_int_fast32_t refcount_{0}; }; -} -} // namespace simgrid::s4u +} // namespace s4u +} // namespace simgrid #endif /* SIMGRID_S4U_COMM_HPP */ diff --git a/include/simgrid/s4u/ConditionVariable.hpp b/include/simgrid/s4u/ConditionVariable.hpp index 1bd6e119eb..77811c0d03 100644 --- a/include/simgrid/s4u/ConditionVariable.hpp +++ b/include/simgrid/s4u/ConditionVariable.hpp @@ -6,19 +6,10 @@ #ifndef SIMGRID_S4U_COND_VARIABLE_HPP #define SIMGRID_S4U_COND_VARIABLE_HPP -#include -#include -#include -#include -#include // std::swap - -#include - -#include - #include #include -#include + +#include namespace simgrid { namespace s4u { diff --git a/include/simgrid/s4u/Exec.hpp b/include/simgrid/s4u/Exec.hpp index b62467b151..a023a74dcc 100644 --- a/include/simgrid/s4u/Exec.hpp +++ b/include/simgrid/s4u/Exec.hpp @@ -8,7 +8,6 @@ #include #include -#include #include diff --git a/include/simgrid/s4u/Mutex.hpp b/include/simgrid/s4u/Mutex.hpp index ce19858b40..f9cd035c85 100644 --- a/include/simgrid/s4u/Mutex.hpp +++ b/include/simgrid/s4u/Mutex.hpp @@ -6,13 +6,8 @@ #ifndef SIMGRID_S4U_MUTEX_HPP #define SIMGRID_S4U_MUTEX_HPP -#include -#include - -#include - -#include -#include +#include +#include namespace simgrid { namespace s4u { @@ -39,17 +34,10 @@ class XBT_PUBLIC Mutex { simgrid::kernel::activity::MutexImpl* mutex_; explicit Mutex(simgrid::kernel::activity::MutexImpl * mutex) : mutex_(mutex) {} - /* refcounting of the intrusive_ptr is delegated to the implementation object */ - friend void intrusive_ptr_add_ref(Mutex* mutex) - { - xbt_assert(mutex); - SIMIX_mutex_ref(mutex->mutex_); - } - friend void intrusive_ptr_release(Mutex* mutex) - { - xbt_assert(mutex); - SIMIX_mutex_unref(mutex->mutex_); - } + /* refcounting */ + friend void intrusive_ptr_add_ref(Mutex* mutex); + friend void intrusive_ptr_release(Mutex* mutex); + public: using Ptr = boost::intrusive_ptr; diff --git a/include/xbt/xbt_os_thread.h b/include/xbt/xbt_os_thread.h index 9c8c05e04c..a3355148cf 100644 --- a/include/xbt/xbt_os_thread.h +++ b/include/xbt/xbt_os_thread.h @@ -8,12 +8,13 @@ #ifndef XBT_OS_THREAD_H #define XBT_OS_THREAD_H -SG_BEGIN_DECL() - #include +#include #include +SG_BEGIN_DECL() + typedef pthread_key_t xbt_os_thread_key_t; /** @addtogroup XBT_thread diff --git a/src/include/xbt/parmap.hpp b/src/include/xbt/parmap.hpp index 3aeaf196df..5f91ac4175 100644 --- a/src/include/xbt/parmap.hpp +++ b/src/include/xbt/parmap.hpp @@ -1,7 +1,6 @@ /* A thread pool (C++ version). */ -/* Copyright (c) 2004-2018 The SimGrid Team. - * All rights reserved. */ +/* Copyright (c) 2004-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. */ @@ -11,16 +10,10 @@ #include "src/internal_config.h" // HAVE_FUTEX_H #include "src/kernel/context/Context.hpp" -#include + #include -#include -#include -#include -#include -#include #if HAVE_FUTEX_H -#include #include #include #endif diff --git a/src/kernel/context/ContextBoost.hpp b/src/kernel/context/ContextBoost.hpp index 1ce2b1d5ab..90d6cc768c 100644 --- a/src/kernel/context/ContextBoost.hpp +++ b/src/kernel/context/ContextBoost.hpp @@ -24,7 +24,6 @@ #include "Context.hpp" #include "src/internal_config.h" -#include "src/simix/smx_private.hpp" namespace simgrid { namespace kernel { diff --git a/src/kernel/context/ContextRaw.cpp b/src/kernel/context/ContextRaw.cpp index 85639e2a75..354d1e3162 100644 --- a/src/kernel/context/ContextRaw.cpp +++ b/src/kernel/context/ContextRaw.cpp @@ -4,8 +4,8 @@ * under the terms of the license (GNU LGPL) which comes with this package. */ #include "ContextRaw.hpp" - #include "mc/mc.h" +#include "src/simix/smx_private.hpp" XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix_context); diff --git a/src/kernel/context/ContextRaw.hpp b/src/kernel/context/ContextRaw.hpp index 2126f38cf0..3ade7105e7 100644 --- a/src/kernel/context/ContextRaw.hpp +++ b/src/kernel/context/ContextRaw.hpp @@ -11,14 +11,9 @@ #include #include -#include #include #include -#include "Context.hpp" -#include "src/internal_config.h" -#include "src/simix/smx_private.hpp" - namespace simgrid { namespace kernel { namespace context { diff --git a/src/s4u/s4u_comm.cpp b/src/s4u/s4u_comm.cpp index 693f0620e1..cbbb9c4597 100644 --- a/src/s4u/s4u_comm.cpp +++ b/src/s4u/s4u_comm.cpp @@ -25,6 +25,35 @@ Comm::~Comm() } } +int Comm::wait_any_for(std::vector* comms_in, double timeout) +{ + // Map to dynar: + xbt_dynar_t comms = xbt_dynar_new(sizeof(simgrid::kernel::activity::ActivityImpl*), [](void* ptr) { + intrusive_ptr_release(*(simgrid::kernel::activity::ActivityImpl**)ptr); + }); + for (auto const& comm : *comms_in) { + if (comm->state_ == Activity::State::inited) + comm->start(); + xbt_assert(comm->state_ == Activity::State::started); + simgrid::kernel::activity::ActivityImpl* ptr = comm->pimpl_.get(); + intrusive_ptr_add_ref(ptr); + xbt_dynar_push_as(comms, simgrid::kernel::activity::ActivityImpl*, ptr); + } + // Call the underlying simcall: + int idx = simcall_comm_waitany(comms, timeout); + xbt_dynar_free(&comms); + return idx; +} + +void Comm::wait_all(std::vector* comms) +{ + // TODO: this should be a simcall or something + // TODO: we are missing a version with timeout + for (CommPtr comm : *comms) { + comm->wait(); + } +} + Activity* Comm::set_rate(double rate) { xbt_assert(state_ == State::inited); @@ -35,44 +64,44 @@ Activity* Comm::set_rate(double rate) Activity* Comm::set_src_data(void* buff) { xbt_assert(state_ == State::inited); - xbt_assert(dstBuff_ == nullptr, "Cannot set the src and dst buffers at the same time"); - srcBuff_ = buff; + xbt_assert(dst_buff_ == nullptr, "Cannot set the src and dst buffers at the same time"); + src_buff_ = buff; return this; } Activity* Comm::set_src_data_size(size_t size) { xbt_assert(state_ == State::inited); - srcBuffSize_ = size; + src_buff_size_ = size; return this; } Activity* Comm::set_src_data(void* buff, size_t size) { xbt_assert(state_ == State::inited); - xbt_assert(dstBuff_ == nullptr, "Cannot set the src and dst buffers at the same time"); - srcBuff_ = buff; - srcBuffSize_ = size; + xbt_assert(dst_buff_ == nullptr, "Cannot set the src and dst buffers at the same time"); + src_buff_ = buff; + src_buff_size_ = size; return this; } Activity* Comm::set_dst_data(void** buff) { xbt_assert(state_ == State::inited); - xbt_assert(srcBuff_ == nullptr, "Cannot set the src and dst buffers at the same time"); - dstBuff_ = buff; + xbt_assert(src_buff_ == nullptr, "Cannot set the src and dst buffers at the same time"); + dst_buff_ = buff; return this; } size_t Comm::get_dst_data_size() { xbt_assert(state_ == State::finished); - return dstBuffSize_; + return dst_buff_size_; } Activity* Comm::set_dst_data(void** buff, size_t size) { xbt_assert(state_ == State::inited); - xbt_assert(srcBuff_ == nullptr, "Cannot set the src and dst buffers at the same time"); - dstBuff_ = buff; - dstBuffSize_ = size; + xbt_assert(src_buff_ == nullptr, "Cannot set the src and dst buffers at the same time"); + dst_buff_ = buff; + dst_buff_size_ = size; return this; } @@ -80,13 +109,13 @@ Activity* Comm::start() { xbt_assert(state_ == State::inited); - if (srcBuff_ != nullptr) { // Sender side - pimpl_ = simcall_comm_isend(sender_, mailbox_->get_impl(), remains_, rate_, srcBuff_, srcBuffSize_, matchFunction_, - cleanFunction_, copyDataFunction_, user_data_, detached_); - } else if (dstBuff_ != nullptr) { // Receiver side + if (src_buff_ != nullptr) { // Sender side + pimpl_ = simcall_comm_isend(sender_, mailbox_->get_impl(), remains_, rate_, src_buff_, src_buff_size_, match_fun_, + clean_fun_, copy_data_function_, user_data_, detached_); + } else if (dst_buff_ != nullptr) { // Receiver side xbt_assert(not detached_, "Receive cannot be detached"); - pimpl_ = simcall_comm_irecv(receiver_, mailbox_->get_impl(), dstBuff_, &dstBuffSize_, matchFunction_, - copyDataFunction_, user_data_, rate_); + pimpl_ = simcall_comm_irecv(receiver_, mailbox_->get_impl(), dst_buff_, &dst_buff_size_, match_fun_, + copy_data_function_, user_data_, rate_); } else { xbt_die("Cannot start a communication before specifying whether we are the sender or the receiver"); @@ -114,11 +143,11 @@ Activity* Comm::wait(double timeout) return this; case State::inited: // It's not started yet. Do it in one simcall - if (srcBuff_ != nullptr) { - simcall_comm_send(sender_, mailbox_->get_impl(), remains_, rate_, srcBuff_, srcBuffSize_, matchFunction_, - copyDataFunction_, user_data_, timeout); + if (src_buff_ != nullptr) { + simcall_comm_send(sender_, mailbox_->get_impl(), remains_, rate_, src_buff_, src_buff_size_, match_fun_, + copy_data_function_, user_data_, timeout); } else { // Receiver - simcall_comm_recv(receiver_, mailbox_->get_impl(), dstBuff_, &dstBuffSize_, matchFunction_, copyDataFunction_, + simcall_comm_recv(receiver_, mailbox_->get_impl(), dst_buff_, &dst_buff_size_, match_fun_, copy_data_function_, user_data_, timeout, rate_); } state_ = State::finished; @@ -148,7 +177,7 @@ int Comm::test_any(std::vector* comms) Activity* Comm::detach() { xbt_assert(state_ == State::inited, "You cannot detach communications once they are started (not implemented)."); - xbt_assert(srcBuff_ != nullptr && srcBuffSize_ != 0, "You can only detach sends, not recvs"); + xbt_assert(src_buff_ != nullptr && src_buff_size_ != 0, "You can only detach sends, not recvs"); detached_ = true; return start(); } diff --git a/src/s4u/s4u_mailbox.cpp b/src/s4u/s4u_mailbox.cpp index b8d0cf143d..8d981638af 100644 --- a/src/s4u/s4u_mailbox.cpp +++ b/src/s4u/s4u_mailbox.cpp @@ -80,8 +80,8 @@ s4u::CommPtr Mailbox::put_init(void* data, uint64_t simulatedSize) { s4u::CommPtr res = put_init(); res->set_remaining(simulatedSize); - res->srcBuff_ = data; - res->srcBuffSize_ = sizeof(void*); + res->src_buff_ = data; + res->src_buff_size_ = sizeof(void*); return res; } s4u::CommPtr Mailbox::put_async(void* payload, uint64_t simulatedSize) diff --git a/src/s4u/s4u_mutex.cpp b/src/s4u/s4u_mutex.cpp index 1fda582142..09d36548e0 100644 --- a/src/s4u/s4u_mutex.cpp +++ b/src/s4u/s4u_mutex.cpp @@ -40,5 +40,16 @@ MutexPtr Mutex::createMutex() return MutexPtr(&mutex->mutex(), false); } +/* refcounting of the intrusive_ptr is delegated to the implementation object */ +void intrusive_ptr_add_ref(Mutex* mutex) +{ + xbt_assert(mutex); + SIMIX_mutex_ref(mutex->mutex_); +} +void intrusive_ptr_release(Mutex* mutex) +{ + xbt_assert(mutex); + SIMIX_mutex_unref(mutex->mutex_); +} } } diff --git a/src/surf/cpu_cas01.hpp b/src/surf/cpu_cas01.hpp index ae104a08e2..38a81954c0 100644 --- a/src/surf/cpu_cas01.hpp +++ b/src/surf/cpu_cas01.hpp @@ -3,9 +3,8 @@ /* 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 - #include "cpu_interface.hpp" +#include "xbt/base.h" /*********** * Classes * diff --git a/src/surf/plugins/dirty_page_tracking.cpp b/src/surf/plugins/dirty_page_tracking.cpp index 39d879ad80..b14dbc6ad9 100644 --- a/src/surf/plugins/dirty_page_tracking.cpp +++ b/src/surf/plugins/dirty_page_tracking.cpp @@ -4,9 +4,7 @@ * under the terms of the license (GNU LGPL) which comes with this package. */ #include "simgrid/plugins/live_migration.h" -#include "simgrid/s4u.hpp" #include "src/plugins/vm/VirtualMachineImpl.hpp" -#include namespace simgrid { namespace vm { diff --git a/src/surf/plugins/host_dvfs.cpp b/src/surf/plugins/host_dvfs.cpp index a57868b4ca..9dac3372ee 100644 --- a/src/surf/plugins/host_dvfs.cpp +++ b/src/surf/plugins/host_dvfs.cpp @@ -5,18 +5,10 @@ #include "simgrid/plugins/dvfs.h" #include "simgrid/plugins/load.h" -#include "simgrid/simix.hpp" #include "src/plugins/vm/VirtualMachineImpl.hpp" -#include "src/surf/cpu_interface.hpp" +#include #include -#include -#include -#include -#include -#include -#include -#include /** @addtogroup SURF_plugin_load diff --git a/src/surf/plugins/host_energy.cpp b/src/surf/plugins/host_energy.cpp index 44736f3fed..0b3ca1d3b5 100644 --- a/src/surf/plugins/host_energy.cpp +++ b/src/surf/plugins/host_energy.cpp @@ -5,17 +5,12 @@ #include "simgrid/plugins/energy.h" #include "simgrid/plugins/load.h" -#include "simgrid/simix.hpp" #include "src/plugins/vm/VirtualMachineImpl.hpp" #include "src/surf/cpu_interface.hpp" - #include "simgrid/s4u/Engine.hpp" #include #include -#include -#include -#include /** @addtogroup plugin_energy diff --git a/src/surf/plugins/host_load.cpp b/src/surf/plugins/host_load.cpp index 5f54170b88..039f23cda7 100644 --- a/src/surf/plugins/host_load.cpp +++ b/src/surf/plugins/host_load.cpp @@ -4,17 +4,7 @@ * under the terms of the license (GNU LGPL) which comes with this package. */ #include "simgrid/plugins/load.h" -#include "simgrid/simix.hpp" #include "src/plugins/vm/VirtualMachineImpl.hpp" -#include "src/surf/cpu_interface.hpp" - -#include "simgrid/s4u/Engine.hpp" - -#include -#include -#include -#include -#include /** @addtogroup plugin_load diff --git a/src/surf/plugins/link_energy.cpp b/src/surf/plugins/link_energy.cpp index 062502b16d..74873ca501 100644 --- a/src/surf/plugins/link_energy.cpp +++ b/src/surf/plugins/link_energy.cpp @@ -10,7 +10,6 @@ #include #include -#include /** @addtogroup SURF_plugin_energy -- 2.20.1