From: mlaurent Date: Wed, 15 Feb 2023 14:05:23 +0000 (+0100) Subject: Merge branch 'master' of https://framagit.org/simgrid/simgrid X-Git-Tag: v3.34~436^2~13 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/2613dece7ac1a22cb1edbed4e2803fc0a3e7db67?hp=3e8cbdbebfce89fb0abf0cb8710c8505e111d097 Merge branch 'master' of https://framagit.org/simgrid/simgrid --- diff --git a/ChangeLog b/ChangeLog index 048fed7a0b..99a7e6a3b3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,8 @@ General: - Remove the Java bindings: they were limited to the MSG interface. - On Windows, you now need to install WSL2 as the native builds are now disabled. It was not really working anyway. + - Support for 32bits architecture is not tested anymore on our CI infrastructure. + It may break in the future, but we think that nobody's using SimGrid on 32 bits. S4U: - Activity::set_remaining() is not public anymore. Use for example diff --git a/MANIFEST.in b/MANIFEST.in index 44e2d4e305..3800775b53 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -2217,6 +2217,8 @@ include src/s4u/s4u_Netzone.cpp include src/s4u/s4u_Semaphore.cpp include src/s4u/s4u_VirtualMachine.cpp include src/simgrid/Exception.cpp +include src/simgrid/module.cpp +include src/simgrid/module.hpp include src/simgrid/sg_config.cpp include src/simgrid/sg_version.cpp include src/simgrid/util.hpp diff --git a/docs/source/Installing_SimGrid.rst b/docs/source/Installing_SimGrid.rst index 3d55d5aabb..86d9a60aed 100644 --- a/docs/source/Installing_SimGrid.rst +++ b/docs/source/Installing_SimGrid.rst @@ -409,30 +409,3 @@ simgrid without downloading the source with pip: .. code-block:: console $ pip install simgrid - -Linux Multi-Arch specific instructions -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -On a multiarch x86_64 Linux, it should be possible to compile a 32-bit -version of SimGrid with something like: - -.. code-block:: console - - $ CFLAGS=-m32 \ - CXXFLAGS=-m32 \ - FFLAGS=-m32 \ - PKG_CONFIG_LIBDIR=/usr/lib/i386-linux-gnu/pkgconfig/ \ - cmake . \ - -DCMAKE_SYSTEM_PROCESSOR=i386 \ - -DCMAKE_Fortran_COMPILER=/some/path/to/i686-linux-gnu-gfortran \ - -DGFORTRAN_EXE=/some/path/to/i686-linux-gnu-gfortran \ - -DSMPI_C_FLAGS=-m32 \ - -DSMPI_CXX_FLAGS=-m32 \ - -DSMPI_Fortran_FLAGS=-m32 - -If needed, implement ``i686-linux-gnu-gfortran`` as a script: - -.. code-block:: shell - - #!/usr/bin/env sh - exec gfortran -m32 "$@" diff --git a/examples/cpp/network-ns3/s4u-network-ns3.cpp b/examples/cpp/network-ns3/s4u-network-ns3.cpp index a8a7f9db66..e1c8b39399 100644 --- a/examples/cpp/network-ns3/s4u-network-ns3.cpp +++ b/examples/cpp/network-ns3/s4u-network-ns3.cpp @@ -32,7 +32,7 @@ static void master(MasterWorkerNamesMap& names, const std::vector& int id = std::stoi(args[3]); // unique id to control statistics /* master and worker names */ - names.emplace(id, MasterWorkerNames{sg4::Host::current()->get_name(), args[2]}); + names.try_emplace(id, MasterWorkerNames{sg4::Host::current()->get_name(), args[2]}); sg4::Mailbox* mbox = sg4::Mailbox::by_name(args[3]); diff --git a/examples/cpp/synchro-semaphore/s4u-synchro-semaphore.cpp b/examples/cpp/synchro-semaphore/s4u-synchro-semaphore.cpp index 4040407811..b9b5e77297 100644 --- a/examples/cpp/synchro-semaphore/s4u-synchro-semaphore.cpp +++ b/examples/cpp/synchro-semaphore/s4u-synchro-semaphore.cpp @@ -14,24 +14,24 @@ namespace sg4 = simgrid::s4u; XBT_LOG_NEW_DEFAULT_CATEGORY(sem_test, "Simple test of the semaphore"); -static void producer(std::string& buffer, sg4::SemaphorePtr sem_empty, sg4::SemaphorePtr sem_full, +static void producer(std::string* buffer, sg4::SemaphorePtr sem_empty, sg4::SemaphorePtr sem_full, const std::vector& args) { for (auto const& str : args) { sem_empty->acquire(); XBT_INFO("Pushing '%s'", str.c_str()); - buffer = str; + *buffer = str; sem_full->release(); } XBT_INFO("Bye!"); } -static void consumer(const std::string& buffer, sg4::SemaphorePtr sem_empty, sg4::SemaphorePtr sem_full) +static void consumer(const std::string* buffer, sg4::SemaphorePtr sem_empty, sg4::SemaphorePtr sem_full) { std::string str; do { sem_full->acquire(); - str = buffer; + str = *buffer; XBT_INFO("Receiving '%s'", str.c_str()); sem_empty->release(); } while (str != ""); @@ -49,9 +49,8 @@ int main(int argc, char **argv) auto sem_empty = sg4::Semaphore::create(1); /* indicates whether the buffer is empty */ auto sem_full = sg4::Semaphore::create(0); /* indicates whether the buffer is full */ - sg4::Actor::create("producer", e.host_by_name("Tremblay"), producer, std::ref(buffer), sem_empty, sem_full, - std::cref(args)); - sg4::Actor::create("consumer", e.host_by_name("Jupiter"), consumer, std::cref(buffer), sem_empty, sem_full); + sg4::Actor::create("producer", e.host_by_name("Tremblay"), producer, &buffer, sem_empty, sem_full, std::cref(args)); + sg4::Actor::create("consumer", e.host_by_name("Jupiter"), consumer, &buffer, sem_empty, sem_full); e.run(); return 0; diff --git a/include/xbt/log.h b/include/xbt/log.h index c2dbd358c7..49adae5a85 100644 --- a/include/xbt/log.h +++ b/include/xbt/log.h @@ -308,8 +308,6 @@ XBT_PUBLIC void _xbt_log_event_log(xbt_log_event_t ev, const char* fmt, ...) XBT XBT_PUBLIC int _xbt_log_cat_init(xbt_log_category_t category, e_xbt_log_priority_t priority); extern s_xbt_log_category_t _XBT_LOGV(XBT_LOG_ROOT_CAT); -extern xbt_log_appender_t xbt_log_default_appender; -extern xbt_log_layout_t xbt_log_default_layout; /* ********************** */ /* Public functions again */ diff --git a/src/include/xbt/xbt_modinter.h b/src/include/xbt/xbt_modinter.h index 50178d64cc..5077da522f 100644 --- a/src/include/xbt/xbt_modinter.h +++ b/src/include/xbt/xbt_modinter.h @@ -14,7 +14,6 @@ SG_BEGIN_DECL /* Modules definitions */ -void xbt_log_preinit(void); void xbt_log_postexit(void); void xbt_dict_preinit(void); diff --git a/src/instr/instr_config.cpp b/src/instr/instr_config.cpp index 19d9e9eb22..c13fdffc99 100644 --- a/src/instr/instr_config.cpp +++ b/src/instr/instr_config.cpp @@ -20,7 +20,7 @@ XBT_LOG_NEW_CATEGORY(instr, "Logging the behavior of the tracing system (used fo XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_config, instr, "Configuration"); std::ofstream tracing_file; -std::map tracing_files; // TI specific +static std::map tracing_files; // TI specific constexpr char OPT_TRACING_BASIC[] = "tracing/basic"; constexpr char OPT_TRACING_COMMENT_FILE[] = "tracing/comment-file"; @@ -206,7 +206,7 @@ void TRACE_help() namespace simgrid::instr { static bool trace_active = false; TraceFormat trace_format = TraceFormat::Paje; -int trace_precision; +static int trace_precision; /************* * Callbacks * diff --git a/src/instr/instr_interface.cpp b/src/instr/instr_interface.cpp index 4ff4120d65..106acd4c31 100644 --- a/src/instr/instr_interface.cpp +++ b/src/instr/instr_interface.cpp @@ -17,11 +17,11 @@ enum class InstrUserVariable { DECLARE, SET, ADD, SUB }; XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_api, instr, "API"); -std::set> created_categories; -std::set> declared_marks; -std::set> user_host_variables; -std::set> user_vm_variables; -std::set> user_link_variables; +static std::set> created_categories; +static std::set> declared_marks; +static std::set> user_host_variables; +static std::set> user_vm_variables; +static std::set> user_link_variables; static void instr_user_variable(double time, const std::string& resource, const std::string& variable_name, const std::string& parent_type, double value, InstrUserVariable what, diff --git a/src/instr/instr_private.hpp b/src/instr/instr_private.hpp index c6b35da74e..091bbccb9e 100644 --- a/src/instr/instr_private.hpp +++ b/src/instr/instr_private.hpp @@ -40,7 +40,6 @@ void dump_header(bool basic, bool display_sizes); */ enum class TraceFormat { Paje, /*TimeIndependent*/ Ti }; extern TraceFormat trace_format; -extern int trace_precision; extern double last_timestamp_to_dump; void init(); @@ -233,12 +232,6 @@ public: XBT_PRIVATE std::string instr_pid(simgrid::s4u::Actor const& proc); -extern XBT_PRIVATE std::set> created_categories; -extern XBT_PRIVATE std::set> declared_marks; -extern XBT_PRIVATE std::set> user_host_variables; -extern XBT_PRIVATE std::set> user_vm_variables; -extern XBT_PRIVATE std::set> user_link_variables; - /* from instr_config.c */ XBT_PRIVATE bool TRACE_needs_platform(); XBT_PRIVATE bool TRACE_is_enabled(); diff --git a/src/kernel/EngineImpl.cpp b/src/kernel/EngineImpl.cpp index e769b07410..c27e814ea9 100644 --- a/src/kernel/EngineImpl.cpp +++ b/src/kernel/EngineImpl.cpp @@ -99,7 +99,7 @@ static void segvhandler(int signum, siginfo_t* siginfo, void* /*context*/) "If you think you've found a bug in SimGrid, please report it along with a\n" "Minimal Working Example (MWE) reproducing your problem and a full backtrace\n" "of the fault captured with gdb or valgrind.\n", - simgrid::kernel::context::stack_size / 1024); + simgrid::kernel::context::Context::stack_size / 1024); } else if (siginfo->si_signo == SIGSEGV) { fprintf(stderr, "Segmentation fault.\n"); #if HAVE_SMPI diff --git a/src/kernel/actor/ActorImpl.cpp b/src/kernel/actor/ActorImpl.cpp index 23c3e71163..148982feb9 100644 --- a/src/kernel/actor/ActorImpl.cpp +++ b/src/kernel/actor/ActorImpl.cpp @@ -38,7 +38,7 @@ ActorImpl::ActorImpl(const std::string& name, s4u::Host* host, aid_t ppid) : ActorIDTrait(name, ppid), host_(host), piface_(this) { simcall_.issuer_ = this; - stacksize_ = context::stack_size; + stacksize_ = context::Context::stack_size; } ActorImpl::~ActorImpl() diff --git a/src/kernel/context/Context.cpp b/src/kernel/context/Context.cpp index 040d783957..022929622a 100644 --- a/src/kernel/context/Context.cpp +++ b/src/kernel/context/Context.cpp @@ -18,64 +18,21 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ker_context, kernel, "Context switching mechanis namespace simgrid::kernel::context { -static e_xbt_parmap_mode_t parallel_synchronization_mode = XBT_PARMAP_DEFAULT; -static int parallel_contexts = 1; -unsigned stack_size; -unsigned guard_size; - -/** @brief Returns whether some parallel threads are used for the user contexts. */ -bool is_parallel() -{ - return parallel_contexts > 1; -} - -/** - * @brief Returns the number of parallel threads used for the user contexts. - * @return the number of threads (1 means no parallelism) - */ -int get_nthreads() -{ - return parallel_contexts; -} - -/** - * @brief Sets the number of parallel threads to use for the user contexts. - * - * This function should be called before initializing SIMIX. - * A value of 1 means no parallelism (1 thread only). - * If the value is greater than 1, the thread support must be enabled. - * - * @param nb_threads the number of threads to use - */ -void set_nthreads(int nb_threads) +void Context::set_nthreads(int nb_threads) { if (nb_threads <= 0) { nb_threads = std::thread::hardware_concurrency(); XBT_INFO("Auto-setting contexts/nthreads to %d", nb_threads); } - parallel_contexts = nb_threads; -} - -/** - * @brief Sets the synchronization mode to use when actors are run in parallel. - * @param mode how to synchronize threads if actors are run in parallel - */ -void set_parallel_mode(e_xbt_parmap_mode_t mode) -{ - parallel_synchronization_mode = mode; -} - -/** - * @brief Returns the synchronization mode used when actors are run in parallel. - * @return how threads are synchronized if actors are run in parallel - */ -e_xbt_parmap_mode_t get_parallel_mode() -{ - return parallel_synchronization_mode; + Context::parallel_contexts = nb_threads; } ContextFactory::~ContextFactory() = default; +e_xbt_parmap_mode_t Context::parallel_mode = XBT_PARMAP_DEFAULT; +int Context::parallel_contexts = 1; +unsigned Context::stack_size; +unsigned Context::guard_size; thread_local Context* Context::current_context_ = nullptr; /* Install or disable alternate signal stack, for SIGSEGV handler. */ diff --git a/src/kernel/context/Context.hpp b/src/kernel/context/Context.hpp index 25d81135b1..196139975d 100644 --- a/src/kernel/context/Context.hpp +++ b/src/kernel/context/Context.hpp @@ -15,8 +15,6 @@ #include namespace simgrid::kernel::context { -extern unsigned stack_size; -extern unsigned guard_size; class XBT_PUBLIC ContextFactory { public: @@ -45,6 +43,7 @@ protected: class XBT_PUBLIC Context { friend ContextFactory; + static int parallel_contexts; static thread_local Context* current_context_; std::function code_; @@ -53,6 +52,10 @@ class XBT_PUBLIC Context { void declare_context(std::size_t size); public: + static e_xbt_parmap_mode_t parallel_mode; + static unsigned stack_size; + static unsigned guard_size; + static int install_sigsegv_stack(bool enable); Context(std::function&& code, actor::ActorImpl* actor, bool maestro); @@ -65,6 +68,22 @@ public: bool has_code() const { return static_cast(code_); } actor::ActorImpl* get_actor() const { return this->actor_; } + /** @brief Returns whether some parallel threads are used for the user contexts. */ + static bool is_parallel() { return parallel_contexts > 1; } + /** @brief Returns the number of parallel threads used for the user contexts (1 means no parallelism). */ + static int get_nthreads() { return parallel_contexts; } + /** + * @brief Sets the number of parallel threads to use for the user contexts. + * + * This function should be called before initializing SIMIX. + * A value of 1 means no parallelism (1 thread only). + * If the value is greater than 1, the thread support must be enabled. + * If the value is less than 1, the optimal number of threads is chosen automatically. + * + * @param nb_threads the number of threads to use + */ + static void set_nthreads(int nb_threads); + // Scheduling methods virtual void stop(); virtual void suspend() = 0; @@ -98,11 +117,6 @@ XBT_PRIVATE ContextFactory* sysv_factory(); XBT_PRIVATE ContextFactory* raw_factory(); XBT_PRIVATE ContextFactory* boost_factory(); -XBT_PUBLIC bool is_parallel(); -XBT_PUBLIC int get_nthreads(); -XBT_PUBLIC void set_nthreads(int nb_threads); -XBT_PUBLIC void set_parallel_mode(e_xbt_parmap_mode_t mode); -XBT_PUBLIC e_xbt_parmap_mode_t get_parallel_mode(); } // namespace simgrid::kernel::context #endif diff --git a/src/kernel/context/ContextSwapped.cpp b/src/kernel/context/ContextSwapped.cpp index 350b686487..a19779195b 100644 --- a/src/kernel/context/ContextSwapped.cpp +++ b/src/kernel/context/ContextSwapped.cpp @@ -191,10 +191,11 @@ void SwappedContextFactory::run_all(std::vector const& actors * stuff It is much easier to understand what happens if you see the working threads as bodies that swap their soul * for the ones of the simulated processes that must run. */ - if (is_parallel()) { + if (Context::is_parallel()) { // We lazily create the parmap so that all options are actually processed when doing so. if (parmap_ == nullptr) - parmap_ = std::make_unique>(get_nthreads(), get_parallel_mode()); + parmap_ = + std::make_unique>(Context::get_nthreads(), Context::parallel_mode); // Usually, Parmap::apply() executes the provided function on all elements of the array. // Here, the executed function does not return the control to the parmap before all the array is processed: diff --git a/src/kernel/context/ContextThread.cpp b/src/kernel/context/ContextThread.cpp index c6901c9628..9106a3cb31 100644 --- a/src/kernel/context/ContextThread.cpp +++ b/src/kernel/context/ContextThread.cpp @@ -24,21 +24,21 @@ namespace simgrid::kernel::context { ThreadContextFactory::ThreadContextFactory() : ContextFactory() { - if (stack_size != 8 * 1024 * 1024) + if (Context::stack_size != 8 * 1024 * 1024) XBT_INFO("Stack size modifications are ignored by thread factory."); - if (is_parallel()) + if (Context::is_parallel()) ParallelThreadContext::initialize(); } ThreadContextFactory::~ThreadContextFactory() { - if (is_parallel()) + if (Context::is_parallel()) ParallelThreadContext::finalize(); } ThreadContext* ThreadContextFactory::create_context(std::function&& code, actor::ActorImpl* actor, bool maestro) { - if (is_parallel()) + if (Context::is_parallel()) return this->new_context(std::move(code), actor, maestro); else return this->new_context(std::move(code), actor, maestro); @@ -46,7 +46,7 @@ ThreadContext* ThreadContextFactory::create_context(std::function&& code void ThreadContextFactory::run_all(std::vector const& actors_list) { - if (is_parallel()) + if (Context::is_parallel()) ParallelThreadContext::run_all(actors_list); else diff --git a/src/kernel/routing/ClusterZone.cpp b/src/kernel/routing/ClusterZone.cpp index bb269eba5a..72f6dca848 100644 --- a/src/kernel/routing/ClusterZone.cpp +++ b/src/kernel/routing/ClusterZone.cpp @@ -7,7 +7,7 @@ #include "simgrid/kernel/routing/NetPoint.hpp" #include "src/kernel/resource/StandardLinkImpl.hpp" -XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ker_routing_cluster, ker_routing, "Kernel Cluster Routing"); +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ker_routing_cluster, ker_platform, "Kernel Cluster Routing"); /* This routing is specifically setup to represent clusters, aka homogeneous sets of machines * Note that a router is created, easing the interconnection with the rest of the world. */ diff --git a/src/kernel/routing/DijkstraZone.cpp b/src/kernel/routing/DijkstraZone.cpp index 06a7d19a60..216961020d 100644 --- a/src/kernel/routing/DijkstraZone.cpp +++ b/src/kernel/routing/DijkstraZone.cpp @@ -13,7 +13,7 @@ #include #include -XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ker_routing_dijkstra, ker_routing, "Kernel Dijkstra Routing"); +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ker_routing_dijkstra, ker_platform, "Kernel Dijkstra Routing"); namespace simgrid { namespace kernel::routing { diff --git a/src/kernel/routing/DragonflyZone.cpp b/src/kernel/routing/DragonflyZone.cpp index e8e4b9a9cc..7afec19616 100644 --- a/src/kernel/routing/DragonflyZone.cpp +++ b/src/kernel/routing/DragonflyZone.cpp @@ -12,7 +12,7 @@ #include #include -XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ker_routing_dragonfly, ker_routing, "Kernel Dragonfly Routing"); +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ker_routing_dragonfly, ker_platform, "Kernel Dragonfly Routing"); namespace simgrid { namespace kernel::routing { diff --git a/src/kernel/routing/EmptyZone.cpp b/src/kernel/routing/EmptyZone.cpp index 26fc80c99b..fc896829e6 100644 --- a/src/kernel/routing/EmptyZone.cpp +++ b/src/kernel/routing/EmptyZone.cpp @@ -9,7 +9,7 @@ #include "simgrid/kernel/routing/EmptyZone.hpp" -XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ker_routing_none, ker_routing, "Kernel No Routing"); +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ker_routing_none, ker_platform, "Kernel No Routing"); namespace simgrid { namespace kernel::routing { diff --git a/src/kernel/routing/FatTreeZone.cpp b/src/kernel/routing/FatTreeZone.cpp index d537bb6a0c..0c33475040 100644 --- a/src/kernel/routing/FatTreeZone.cpp +++ b/src/kernel/routing/FatTreeZone.cpp @@ -17,7 +17,7 @@ #include #include -XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ker_routing_fat_tree, ker_routing, "Kernel Fat-Tree Routing"); +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ker_routing_fat_tree, ker_platform, "Kernel Fat-Tree Routing"); namespace simgrid { namespace kernel::routing { diff --git a/src/kernel/routing/FloydZone.cpp b/src/kernel/routing/FloydZone.cpp index 85ae467105..350ce04177 100644 --- a/src/kernel/routing/FloydZone.cpp +++ b/src/kernel/routing/FloydZone.cpp @@ -11,7 +11,7 @@ #include -XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ker_routing_floyd, ker_routing, "Kernel Floyd Routing"); +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ker_routing_floyd, ker_platform, "Kernel Floyd Routing"); namespace simgrid { namespace kernel::routing { diff --git a/src/kernel/routing/FullZone.cpp b/src/kernel/routing/FullZone.cpp index 4e862ccbfc..1ae50c5368 100644 --- a/src/kernel/routing/FullZone.cpp +++ b/src/kernel/routing/FullZone.cpp @@ -8,7 +8,7 @@ #include "src/kernel/resource/NetworkModel.hpp" -XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ker_routing_full, ker_routing, "Kernel Full Routing"); +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ker_routing_full, ker_platform, "Kernel Full Routing"); namespace simgrid { namespace kernel::routing { diff --git a/src/kernel/routing/NetPoint.cpp b/src/kernel/routing/NetPoint.cpp index d3d72aa8e9..ee3d0dac83 100644 --- a/src/kernel/routing/NetPoint.cpp +++ b/src/kernel/routing/NetPoint.cpp @@ -9,7 +9,7 @@ #include "simgrid/s4u/Host.hpp" #include "xbt/log.h" -XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ker_netpoint, ker_routing, "Kernel implementation of netpoints"); +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ker_netpoint, ker_platform, "Kernel implementation of netpoints"); namespace simgrid { diff --git a/src/kernel/routing/NetZoneImpl.cpp b/src/kernel/routing/NetZoneImpl.cpp index f8db9825ef..fa210c3950 100644 --- a/src/kernel/routing/NetZoneImpl.cpp +++ b/src/kernel/routing/NetZoneImpl.cpp @@ -20,7 +20,7 @@ #include "src/kernel/resource/VirtualMachineImpl.hpp" #include "src/surf/HostImpl.hpp" -XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ker_routing, kernel, "Kernel routing-related information"); +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ker_platform, kernel, "Kernel platform-related information"); namespace simgrid::kernel::routing { @@ -45,24 +45,16 @@ static void surf_config_models_setup() xbt_enforce(not disk_model_name.empty(), "Set a disk model to use with the 'compound' host model"); xbt_enforce(not network_model_name.empty(), "Set a network model to use with the 'compound' host model"); - const auto* cpu_model = find_model_description(surf_cpu_model_description, cpu_model_name); - cpu_model->model_init_preparse(); - - const auto* disk_model = find_model_description(surf_disk_model_description, disk_model_name); - disk_model->model_init_preparse(); - - const auto* network_model = find_model_description(surf_network_model_description, network_model_name); - network_model->model_init_preparse(); + surf_cpu_model_description.by_name(cpu_model_name).init(); + surf_disk_model_description.by_name(disk_model_name).init(); + simgrid_network_models().by_name(network_model_name).init(); } - XBT_DEBUG("Call host_model_init"); - const auto* host_model = find_model_description(surf_host_model_description, host_model_name); - host_model->model_init_preparse(); + surf_host_model_description.by_name(host_model_name).init(); XBT_DEBUG("Call vm_model_init"); - /* ideally we should get back the pointer to CpuModel from model_init_preparse(), but this - * requires changing the declaration of surf_cpu_model_description. - * To be reviewed in the future */ + /* TODO: ideally we should get back the pointer to CpuModel from init(), but this + * requires changing the declaration of surf_cpu_model_description. */ surf_vm_model_init_HL13( simgrid::s4u::Engine::get_instance()->get_netzone_root()->get_impl()->get_cpu_pm_model().get()); } diff --git a/src/kernel/routing/RoutedZone.cpp b/src/kernel/routing/RoutedZone.cpp index d5790d7553..8457254713 100644 --- a/src/kernel/routing/RoutedZone.cpp +++ b/src/kernel/routing/RoutedZone.cpp @@ -12,7 +12,7 @@ #include "xbt/sysdep.h" #include "xbt/asserts.hpp" -XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ker_routing_generic, ker_routing, "Kernel Generic Routing"); +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ker_routing_generic, ker_platform, "Kernel Generic Routing"); /* ***************************************************************** */ /* *********************** GENERIC METHODS ************************* */ diff --git a/src/kernel/routing/StarZone.cpp b/src/kernel/routing/StarZone.cpp index ada9bb6434..3ccb8888ba 100644 --- a/src/kernel/routing/StarZone.cpp +++ b/src/kernel/routing/StarZone.cpp @@ -8,7 +8,7 @@ #include "src/kernel/resource/NetworkModel.hpp" #include "xbt/string.hpp" -XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ker_routing_star, ker_routing, "Kernel Star Routing"); +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ker_routing_star, ker_platform, "Kernel Star Routing"); namespace simgrid { namespace kernel::routing { diff --git a/src/kernel/routing/TorusZone.cpp b/src/kernel/routing/TorusZone.cpp index 4f3652f201..11fd3b4fe3 100644 --- a/src/kernel/routing/TorusZone.cpp +++ b/src/kernel/routing/TorusZone.cpp @@ -14,7 +14,7 @@ #include #include -XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ker_routing_torus, ker_routing, "Kernel Torus Routing"); +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ker_routing_torus, ker_platform, "Kernel Torus Routing"); namespace simgrid { namespace kernel ::routing { diff --git a/src/kernel/routing/VivaldiZone.cpp b/src/kernel/routing/VivaldiZone.cpp index e9c2ccba9a..e7429d8555 100644 --- a/src/kernel/routing/VivaldiZone.cpp +++ b/src/kernel/routing/VivaldiZone.cpp @@ -12,7 +12,7 @@ #include -XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ker_routing_vivaldi, ker_routing, "Kernel Vivaldi Routing"); +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ker_routing_vivaldi, ker_platform, "Kernel Vivaldi Routing"); namespace simgrid { namespace kernel::routing { diff --git a/src/kernel/routing/WifiZone.cpp b/src/kernel/routing/WifiZone.cpp index d6cb94fa82..b6d40835d8 100644 --- a/src/kernel/routing/WifiZone.cpp +++ b/src/kernel/routing/WifiZone.cpp @@ -8,7 +8,7 @@ #include "src/kernel/resource/NetworkModel.hpp" -XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ker_routing_wifi, ker_routing, "Kernel Wifi Routing"); +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ker_routing_wifi, ker_platform, "Kernel Wifi Routing"); namespace simgrid { namespace kernel::routing { diff --git a/src/plugins/chaos_monkey.cpp b/src/plugins/chaos_monkey.cpp index 0e0938f670..45f4df6eac 100644 --- a/src/plugins/chaos_monkey.cpp +++ b/src/plugins/chaos_monkey.cpp @@ -10,7 +10,7 @@ #include #include -#include "src/surf/surf_interface.hpp" // SIMGRID_REGISTER_PLUGIN +#include "src/simgrid/module.hpp" // SIMGRID_REGISTER_PLUGIN namespace sg4 = simgrid::s4u; static simgrid::config::Flag cfg_tell{"cmonkey/tell", "Request the Chaos Monkey to display all timestamps", diff --git a/src/plugins/host_load.cpp b/src/plugins/host_load.cpp index 6c926ad586..2ea7c479f8 100644 --- a/src/plugins/host_load.cpp +++ b/src/plugins/host_load.cpp @@ -10,7 +10,7 @@ #include #include "src/kernel/activity/ExecImpl.hpp" -#include "src/surf/surf_interface.hpp" +#include "src/simgrid/module.hpp" // SIMGRID_REGISTER_PLUGIN // Makes sure that this plugin can be activated from the command line with ``--cfg=plugin:host_load`` SIMGRID_REGISTER_PLUGIN(host_load, "Cpu load", &sg_host_load_plugin_init) @@ -32,7 +32,7 @@ It attaches an extension to each host to store some data, and places callbacks i @endrst */ -XBT_LOG_NEW_DEFAULT_SUBCATEGORY(host_load, kernel, "Logging specific to the HostLoad plugin"); +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(host_load, plugin, "Logging specific to the HostLoad plugin"); namespace simgrid::plugin { diff --git a/src/plugins/link_load.cpp b/src/plugins/link_load.cpp index 025c83f3b4..1afdd6ea2b 100644 --- a/src/plugins/link_load.cpp +++ b/src/plugins/link_load.cpp @@ -8,6 +8,7 @@ #include "src/kernel/activity/CommImpl.hpp" #include "src/kernel/resource/NetworkModel.hpp" +#include "src/simgrid/module.hpp" // SIMGRID_REGISTER_PLUGIN #include diff --git a/src/s4u/s4u_Host.cpp b/src/s4u/s4u_Host.cpp index b762e63859..bfd02d9343 100644 --- a/src/s4u/s4u_Host.cpp +++ b/src/s4u/s4u_Host.cpp @@ -21,7 +21,7 @@ #include XBT_LOG_NEW_DEFAULT_SUBCATEGORY(s4u_host, s4u, "Logging specific to the S4U hosts"); -XBT_LOG_EXTERNAL_CATEGORY(ker_routing); +XBT_LOG_EXTERNAL_CATEGORY(ker_platform); namespace simgrid { @@ -169,11 +169,11 @@ void Host::route_to(const Host* dest, std::vector& links, double* latency void Host::route_to(const Host* dest, std::vector& links, double* latency) const { kernel::routing::NetZoneImpl::get_global_route(pimpl_netpoint_, dest->get_netpoint(), links, latency); - if (XBT_LOG_ISENABLED(ker_routing, xbt_log_priority_debug)) { - XBT_CDEBUG(ker_routing, "Route from '%s' to '%s' (latency: %f):", get_cname(), dest->get_cname(), + if (XBT_LOG_ISENABLED(ker_platform, xbt_log_priority_debug)) { + XBT_CDEBUG(ker_platform, "Route from '%s' to '%s' (latency: %f):", get_cname(), dest->get_cname(), (latency == nullptr ? -1 : *latency)); for (auto const* link : links) - XBT_CDEBUG(ker_routing, " Link '%s'", link->get_cname()); + XBT_CDEBUG(ker_platform, " Link '%s'", link->get_cname()); } } diff --git a/src/simgrid/module.cpp b/src/simgrid/module.cpp new file mode 100644 index 0000000000..f4ee704da5 --- /dev/null +++ b/src/simgrid/module.cpp @@ -0,0 +1,78 @@ +/* Copyright (c) 2004-2023. 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 +#include + +#include "src/simgrid/module.hpp" +#include "src/surf/surf_interface.hpp" + +#include + +XBT_LOG_NEW_CATEGORY(plugin, "Common category for the logging of all plugins"); +XBT_LOG_EXTERNAL_CATEGORY(xbt_help); + +using namespace simgrid; + +ModuleGroup& ModuleGroup::add(const char* id, const char* desc, std::function init) +{ + table_.emplace_back(Module(id, desc, init)); + return *this; +} + +Module const& ModuleGroup::by_name(const std::string& name) const +{ + if (auto pos = std::find_if(table_.begin(), table_.end(), [&name](const Module& item) { return item.name_ == name; }); + pos != table_.end()) + return *pos; + + xbt_die("Unable to find %s '%s'. Valid values are: %s.", kind_.c_str(), name.c_str(), existing_values().c_str()); +} +/** Displays the long description of all registered models, and quit */ +void ModuleGroup::help() const +{ + XBT_HELP("Long description of the %s accepted by this simulator:", kind_.c_str()); + for (auto const& item : table_) + XBT_HELP(" %s: %s", item.name_, item.description_); +} +std::string ModuleGroup::existing_values() const +{ + std::stringstream ss; + std::string sep; + for (auto const& item : table_) { + ss << sep + item.name_; + sep = ", "; + } + return ss.str(); +} + +/* -------------------------------------------------------------------------------------------------------------- */ +simgrid::ModuleGroup surf_optimization_mode_description("optimization mode"); +simgrid::ModuleGroup surf_cpu_model_description("CPU model"); +simgrid::ModuleGroup surf_disk_model_description("disk model"); +simgrid::ModuleGroup surf_host_model_description("host model"); + +void simgrid_create_models() +{ + surf_cpu_model_description.add("Cas01", "Simplistic CPU model (time=size/speed).", &surf_cpu_model_init_Cas01); + surf_disk_model_description.add("S19", "Simplistic disk model.", &surf_disk_model_init_S19); + + surf_host_model_description + .add("default", + "Default host model. Currently, CPU:Cas01, network:LV08 (with cross traffic enabled), and disk:S19", + &surf_host_model_init_current_default) + .add("compound", "Host model that is automatically chosen if you change the CPU, network, and disk models", + &surf_host_model_init_compound) + .add("ptask_L07", "Host model somehow similar to Cas01+CM02+S19 but allowing parallel tasks", + &surf_host_model_init_ptask_L07); + + surf_optimization_mode_description + .add("Lazy", "Lazy action management (partial invalidation in lmm + heap in action remaining).", nullptr) + .add("TI", + "Trace integration. Highly optimized mode when using availability traces (only available for the Cas01 CPU " + "model for now).", + nullptr) + .add("Full", "Full update of remaining and variables. Slow but may be useful when debugging.", nullptr); +} diff --git a/src/simgrid/module.hpp b/src/simgrid/module.hpp new file mode 100644 index 0000000000..2e83c168b5 --- /dev/null +++ b/src/simgrid/module.hpp @@ -0,0 +1,67 @@ +/* Copyright (c) 2004-2023. 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_MODULE_HPP +#define SIMGRID_MODULE_HPP + +#include + +#include +#include +#include + +namespace simgrid { + +struct Module { + const char* name_; + const char* description_; + std::function init; + Module(const char* id, const char* desc, std::function init_fun) + : name_(id), description_(desc), init(init_fun) + { + } +}; + +class ModuleGroup { + std::vector table_; + const std::string kind_; // either 'plugin' or 'CPU model' or whatever. Used in error messages only +public: + ModuleGroup(std::string kind) : kind_(kind) {} + + ModuleGroup& add(const char* id, const char* desc, std::function init); + Module const& by_name(const std::string& name) const; + void help() const; + const std::string get_kind() const { return kind_; } + std::string existing_values() const; +}; + +}; // namespace simgrid + +#define SIMGRID_REGISTER_PLUGIN(id, desc, init) \ + static void XBT_ATTRIB_CONSTRUCTOR(800) _XBT_CONCAT3(simgrid_, id, _plugin_register)() \ + { \ + simgrid_plugins().add(_XBT_STRINGIFY(id), (desc), (init)); \ + } + +/** @brief The list of all available plugins */ +inline auto& simgrid_plugins() // Function to avoid static initialization order fiasco +{ + static simgrid::ModuleGroup plugins("plugin"); + return plugins; +} + +#define SIMGRID_REGISTER_NETWORK_MODEL(id, desc, init) \ + static void XBT_ATTRIB_CONSTRUCTOR(800) _XBT_CONCAT3(simgrid_, id, _network_model_register)() \ + { \ + simgrid_network_models().add(_XBT_STRINGIFY(id), (desc), (init)); \ + } +/** @brief The list of all available network model (pick one with --cfg=network/model) */ +inline auto& simgrid_network_models() // Function to avoid static initialization order fiasco +{ + static simgrid::ModuleGroup plugins("network model"); + return plugins; +} + +#endif \ No newline at end of file diff --git a/src/simgrid/sg_config.cpp b/src/simgrid/sg_config.cpp index 1e25468e3e..fa7446e55c 100644 --- a/src/simgrid/sg_config.cpp +++ b/src/simgrid/sg_config.cpp @@ -19,12 +19,13 @@ #include "src/kernel/resource/NetworkModel.hpp" #include "src/mc/mc_config.hpp" #include "src/mc/mc_replay.hpp" +#include "src/simgrid/module.hpp" #include "src/smpi/include/smpi_config.hpp" #include "src/surf/surf_interface.hpp" #include -XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_config, surf, "About the configuration of SimGrid"); +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(config, kernel, "About the configuration of SimGrid"); static simgrid::config::Flag cfg_continue_after_help {"help-nostop", "Do not stop the execution when --help is found", false}; @@ -94,14 +95,13 @@ static void sg_config_cmd_line(int *argc, char **argv) XBT_HELP("Please consider using the recent names"); shall_exit = true; } else if (parse_args && not strcmp(argv[i], "--help-models")) { - model_help("host", surf_host_model_description); + surf_host_model_description.help(); XBT_HELP("%s", ""); - model_help("CPU", surf_cpu_model_description); + surf_cpu_model_description.help(); XBT_HELP("%s", ""); - model_help("network", surf_network_model_description); + simgrid_network_models().help(); XBT_HELP("\nLong description of all optimization levels accepted by the models of this simulator:"); - for (auto const& item : surf_optimization_mode_description) - XBT_HELP(" %s: %s", item.name, item.description); + surf_optimization_mode_description.help(); XBT_HELP("Both network and CPU models have 'Lazy' as default optimization level\n"); shall_exit = true; } else if (parse_args && not strcmp(argv[i], "--help-tracing")) { @@ -128,12 +128,11 @@ static void _sg_cfg_cb__plugin(const std::string& value) return; if (value == "help") { - model_help("plugin", surf_plugin_description()); + simgrid_plugins().help(); exit(0); } - const auto* plugin = find_model_description(surf_plugin_description(), value); - plugin->model_init_preparse(); + simgrid_plugins().by_name(value).init(); } /* callback of the host/model variable */ @@ -142,12 +141,12 @@ static void _sg_cfg_cb__host_model(const std::string& value) xbt_assert(_sg_cfg_init_status < 2, "Cannot change the model after the initialization"); if (value == "help") { - model_help("host", surf_host_model_description); + surf_host_model_description.help(); exit(0); } /* Make sure that the model exists */ - find_model_description(surf_host_model_description, value); + surf_host_model_description.by_name(value); } /* callback of the cpu/model variable */ @@ -156,12 +155,12 @@ static void _sg_cfg_cb__cpu_model(const std::string& value) xbt_assert(_sg_cfg_init_status < 2, "Cannot change the model after the initialization"); if (value == "help") { - model_help("CPU", surf_cpu_model_description); + surf_cpu_model_description.help(); exit(0); } - /* New Module missing */ - find_model_description(surf_cpu_model_description, value); + /* Make sure that the model exists */ + surf_cpu_model_description.by_name(value); } /* callback of the cpu/model variable */ @@ -170,12 +169,12 @@ static void _sg_cfg_cb__optimization_mode(const std::string& value) xbt_assert(_sg_cfg_init_status < 2, "Cannot change the model after the initialization"); if (value == "help") { - model_help("optimization", surf_optimization_mode_description); + surf_optimization_mode_description.help(); exit(0); } - /* New Module missing */ - find_model_description(surf_optimization_mode_description, value); + /* Make sure that the model exists */ + surf_optimization_mode_description.by_name(value); } static void _sg_cfg_cb__disk_model(const std::string& value) @@ -183,11 +182,11 @@ static void _sg_cfg_cb__disk_model(const std::string& value) xbt_assert(_sg_cfg_init_status < 2, "Cannot change the model after the initialization"); if (value == "help") { - model_help("disk", surf_disk_model_description); + surf_disk_model_description.help(); exit(0); } - find_model_description(surf_disk_model_description, value); + surf_disk_model_description.by_name(value); } /* callback of the network_model variable */ @@ -196,22 +195,21 @@ static void _sg_cfg_cb__network_model(const std::string& value) xbt_assert(_sg_cfg_init_status < 2, "Cannot change the model after the initialization"); if (value == "help") { - model_help("network", surf_network_model_description); + simgrid_network_models().help(); exit(0); } - /* New Module missing */ - find_model_description(surf_network_model_description, value); + simgrid_network_models().by_name(value); // Simply ensure that it exists } static void _sg_cfg_cb_contexts_parallel_mode(std::string_view mode_name) { if (mode_name == "posix") { - simgrid::kernel::context::set_parallel_mode(XBT_PARMAP_POSIX); + simgrid::kernel::context::Context::parallel_mode = XBT_PARMAP_POSIX; } else if (mode_name == "futex") { - simgrid::kernel::context::set_parallel_mode(XBT_PARMAP_FUTEX); + simgrid::kernel::context::Context::parallel_mode = XBT_PARMAP_FUTEX; } else if (mode_name == "busy_wait") { - simgrid::kernel::context::set_parallel_mode(XBT_PARMAP_BUSY_WAIT); + simgrid::kernel::context::Context::parallel_mode = XBT_PARMAP_BUSY_WAIT; } else { xbt_die("Command line setting of the parallel synchronization mode should " "be one of \"posix\", \"futex\" or \"busy_wait\""); @@ -221,15 +219,11 @@ static void _sg_cfg_cb_contexts_parallel_mode(std::string_view mode_name) /* build description line with possible values */ static void declare_model_flag(const std::string& name, const std::string& value, const std::function& callback, - const std::vector& model_description, const std::string& type, + const simgrid::ModuleGroup& model_description, const std::string& type, const std::string& descr) { - std::string description = descr + ". Possible values: "; - std::string sep = ""; - for (auto const& item : model_description) { - description += sep + item.name; - sep = ", "; - } + std::string description = descr + ". Possible values (other compilation flags may activate more " + + model_description.get_kind() + "): " + model_description.existing_values(); description += ".\n (use 'help' as a value to see the long description of each " + type + ")"; simgrid::config::declare_flag(name, description, value, callback); } @@ -242,9 +236,9 @@ void sg_config_init(int *argc, char **argv) XBT_WARN("Call to sg_config_init() after initialization ignored"); return; } - + simgrid_create_models(); /* Plugins configuration */ - declare_model_flag("plugin", "", &_sg_cfg_cb__plugin, surf_plugin_description(), "plugin", "The plugins"); + declare_model_flag("plugin", "", &_sg_cfg_cb__plugin, simgrid_plugins(), "plugin", "The plugins"); declare_model_flag("cpu/model", "Cas01", &_sg_cfg_cb__cpu_model, surf_cpu_model_description, "model", "The model to use for the CPU"); @@ -252,7 +246,7 @@ void sg_config_init(int *argc, char **argv) declare_model_flag("disk/model", "S19", &_sg_cfg_cb__disk_model, surf_disk_model_description, "model", "The model to use for the disk"); - declare_model_flag("network/model", "LV08", &_sg_cfg_cb__network_model, surf_network_model_description, "model", + declare_model_flag("network/model", "LV08", &_sg_cfg_cb__network_model, simgrid_network_models(), "model", "The model to use for the network"); declare_model_flag("network/optim", "Lazy", &_sg_cfg_cb__optimization_mode, surf_optimization_mode_description, @@ -304,7 +298,7 @@ void sg_config_init(int *argc, char **argv) static simgrid::config::Flag cfg_context_stack_size{ "contexts/stack-size", "Stack size of contexts in KiB (not with threads)", 8 * 1024, - [](int value) { simgrid::kernel::context::stack_size = value * 1024; }}; + [](int value) { simgrid::kernel::context::Context::stack_size = value * 1024; }}; /* guard size for contexts stacks in memory pages */ #if (PTH_STACKGROWTH != -1) @@ -314,7 +308,7 @@ void sg_config_init(int *argc, char **argv) #endif static simgrid::config::Flag cfg_context_guard_size{ "contexts/guard-size", "Guard size for contexts stacks in memory pages", default_guard_size, - [](int value) { simgrid::kernel::context::guard_size = value * xbt_pagesize; }}; + [](int value) { simgrid::kernel::context::Context::guard_size = value * xbt_pagesize; }}; static simgrid::config::Flag cfg_context_nthreads{ "contexts/nthreads", "Number of parallel threads used to execute user contexts", 1, [](int nthreads) { @@ -324,7 +318,7 @@ void sg_config_init(int *argc, char **argv) "Parallel simulation is forbidden in the verified program, as there is no protection against race " "conditions in mmalloc itself. Please don't be so greedy and show some mercy for our implementation."); #endif - simgrid::kernel::context::set_nthreads(nthreads); + simgrid::kernel::context::Context::set_nthreads(nthreads); }}; /* synchronization mode for parallel user contexts */ @@ -354,7 +348,7 @@ void sg_config_init(int *argc, char **argv) sg_config_cmd_line(argc, argv); - xbt_mallocator_initialization_is_done(simgrid::kernel::context::is_parallel()); + xbt_mallocator_initialization_is_done(simgrid::kernel::context::Context::is_parallel()); } void sg_config_finalize() diff --git a/src/simgrid/sg_version.cpp b/src/simgrid/sg_version.cpp index 54352903cf..3452c3b96a 100644 --- a/src/simgrid/sg_version.cpp +++ b/src/simgrid/sg_version.cpp @@ -9,8 +9,6 @@ #include "xbt/misc.h" #include "xbt/sysdep.h" -XBT_LOG_NEW_DEFAULT_SUBCATEGORY(sg_version, surf, "About the versioning of SimGrid"); - void sg_version_check(int lib_version_major, int lib_version_minor, int lib_version_patch) { if ((lib_version_major != SIMGRID_VERSION_MAJOR) || (lib_version_minor != SIMGRID_VERSION_MINOR)) { diff --git a/src/simix/libsmx.cpp b/src/simix/libsmx.cpp index 8840045f10..febed111d6 100644 --- a/src/simix/libsmx.cpp +++ b/src/simix/libsmx.cpp @@ -175,7 +175,7 @@ void simcall_run_object_access(std::function const& code, simgrid::kerne // We only need a simcall if the order of the setters is important (parallel run or MC execution). // Otherwise, just call the function with no simcall - if (simgrid::kernel::context::is_parallel() + if (simgrid::kernel::context::Context::is_parallel() #if SIMGRID_HAVE_MC || MC_is_active() || MC_record_replay_is_active() #endif diff --git a/src/smpi/include/private.hpp b/src/smpi/include/private.hpp index 7174872d37..2133849028 100644 --- a/src/smpi/include/private.hpp +++ b/src/smpi/include/private.hpp @@ -54,14 +54,12 @@ constexpr int SMPI_RMA_TAG = -6666; #define MPI_REQUEST_IGNORED ((MPI_Request*)-100) /* Bindings for MPI special values */ -extern XBT_PUBLIC int mpi_in_place_; -extern XBT_PUBLIC int mpi_bottom_; -extern XBT_PUBLIC int mpi_status_ignore_; -extern XBT_PUBLIC int mpi_statuses_ignore_; +extern XBT_PUBLIC const int mpi_in_place_; +extern XBT_PUBLIC const int mpi_bottom_; +extern XBT_PUBLIC const int mpi_status_ignore_; +extern XBT_PUBLIC const int mpi_statuses_ignore_; /* Convert between Fortran and C */ -#define FORT_ADDR(addr, val, val2) \ - (((void *)(addr) == (void*) &(val2)) \ - ? (val) : (void *)(addr)) +#define FORT_ADDR(addr, val, val2) (((const void*)(addr) == (const void*)&(val2)) ? (val) : (void*)(addr)) #define FORT_BOTTOM(addr) FORT_ADDR((addr), MPI_BOTTOM, mpi_bottom_) #define FORT_IN_PLACE(addr) FORT_ADDR((addr), MPI_IN_PLACE, mpi_in_place_) #define FORT_STATUS_IGNORE(addr) static_cast(FORT_ADDR((addr), MPI_STATUS_IGNORE, mpi_status_ignore_)) @@ -120,9 +118,6 @@ XBT_PRIVATE bool smpi_cfg_display_alloc(); // utilities XBT_PRIVATE void smpi_init_options_internal(bool called_by_smpi_main); -extern XBT_PRIVATE char* smpi_data_exe_start; // start of the data+bss segment of the executable -extern XBT_PRIVATE size_t smpi_data_exe_size; // size of the data+bss segment of the executable - XBT_PRIVATE bool smpi_switch_data_segment(simgrid::s4u::ActorPtr actor, const void* addr = nullptr); XBT_PRIVATE void smpi_prepare_global_memory_segment(); diff --git a/src/smpi/internals/smpi_global.cpp b/src/smpi/internals/smpi_global.cpp index 13e44ca460..fce781e94c 100644 --- a/src/smpi/internals/smpi_global.cpp +++ b/src/smpi/internals/smpi_global.cpp @@ -72,7 +72,7 @@ std::map std::unordered_map location2speedup; static int smpi_exit_status = 0; -xbt_os_timer_t global_timer; +static xbt_os_timer_t global_timer; static std::vector privatize_libs_paths; // No instance gets manually created; check also the smpirun.in script as diff --git a/src/smpi/internals/smpi_memory.cpp b/src/smpi/internals/smpi_memory.cpp index b9b81f6bed..d2d121e447 100644 --- a/src/smpi/internals/smpi_memory.cpp +++ b/src/smpi/internals/smpi_memory.cpp @@ -26,9 +26,9 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_memory, smpi, "Memory layout support for SMPI"); -char* smpi_data_exe_start = nullptr; -size_t smpi_data_exe_size = 0; -SmpiPrivStrategies smpi_privatize_global_variables; +static char* smpi_data_exe_start = nullptr; // start of the data+bss segment of the executable +static size_t smpi_data_exe_size = 0; // size of the data+bss segment of the executable +static SmpiPrivStrategies smpi_privatize_global_variables; static void* smpi_data_exe_copy; // Initialized by smpi_prepare_global_memory_segment(). diff --git a/src/smpi/internals/smpi_shared.cpp b/src/smpi/internals/smpi_shared.cpp index 95067dd211..10ab0ad0ae 100644 --- a/src/smpi/internals/smpi_shared.cpp +++ b/src/smpi/internals/smpi_shared.cpp @@ -58,7 +58,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_shared, smpi, "Logging specific to SMPI (shared memory macros)"); -namespace{ +namespace { /** Some location in the source code * * This information is used by SMPI_SHARED_MALLOC to allocate some shared memory for all simulated processes. @@ -94,7 +94,7 @@ std::map> calls; int smpi_shared_malloc_bogusfile = -1; int smpi_shared_malloc_bogusfile_huge_page = -1; unsigned long smpi_shared_malloc_blocksize = 1UL << 20; -} +} // namespace void smpi_shared_destroy() { diff --git a/src/smpi/internals/smpi_utils.cpp b/src/smpi/internals/smpi_utils.cpp index 94060e92e6..46249714c6 100644 --- a/src/smpi/internals/smpi_utils.cpp +++ b/src/smpi/internals/smpi_utils.cpp @@ -19,10 +19,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_utils, smpi, "Logging specific to SMPI (utils)"); -extern std::string surf_parsed_filename; -extern int surf_parse_lineno; - -namespace simgrid::smpi::utils { +namespace { double total_benched_time=0; unsigned long total_malloc_size=0; @@ -41,7 +38,7 @@ struct current_buffer_metadata_t { }; alloc_metadata_t max_malloc; -F2C* current_handle = nullptr; +simgrid::smpi::F2C* current_handle = nullptr; current_buffer_metadata_t current_buffer1; current_buffer_metadata_t current_buffer2; @@ -49,6 +46,10 @@ std::unordered_map allocs; std::unordered_map> collective_calls; +} // namespace + +namespace simgrid::smpi::utils { + void add_benched_time(double time){ total_benched_time += time; } diff --git a/src/smpi/mpi/smpi_f2c.cpp b/src/smpi/mpi/smpi_f2c.cpp index dc4c5f57e8..bdec55b5a2 100644 --- a/src/smpi/mpi/smpi_f2c.cpp +++ b/src/smpi/mpi/smpi_f2c.cpp @@ -8,10 +8,10 @@ #include "src/smpi/include/smpi_actor.hpp" #include "src/instr/instr_smpi.hpp" -int mpi_in_place_; -int mpi_bottom_; -int mpi_status_ignore_; -int mpi_statuses_ignore_; +const int mpi_in_place_ = -222; +const int mpi_bottom_ = -111; +const int mpi_status_ignore_ = 0; +const int mpi_statuses_ignore_ = 0; namespace simgrid::smpi { diff --git a/src/surf/host_clm03.cpp b/src/surf/host_clm03.cpp index 27deae6e59..acac620492 100644 --- a/src/surf/host_clm03.cpp +++ b/src/surf/host_clm03.cpp @@ -23,7 +23,7 @@ void surf_host_model_init_current_default() engine->get_netzone_root()->set_host_model(host_model); surf_cpu_model_init_Cas01(); surf_disk_model_init_S19(); - surf_network_model_init_LegrandVelho(); + simgrid_network_models().by_name("LV08").init(); } void surf_host_model_init_compound() diff --git a/src/surf/network_cm02.cpp b/src/surf/network_cm02.cpp index 5cc26f4585..57a7efd448 100644 --- a/src/surf/network_cm02.cpp +++ b/src/surf/network_cm02.cpp @@ -26,9 +26,9 @@ static simgrid::config::Flag cfg_network_solver("network/solver", "Set linear equations solver used by network model", "maxmin", &simgrid::kernel::lmm::System::validate_solver); -/************************************************************************/ -/* New model based on optimizations discussed during Pedro Velho's thesis*/ -/************************************************************************/ +/******************************************************************************/ +/* Network model based on optimizations discussed during Pedro Velho's thesis */ +/******************************************************************************/ /* @techreport{VELHO:2011:HAL-00646896:1, */ /* url = {http://hal.inria.fr/hal-00646896/en/}, */ /* title = {{Flow-level network models: have we reached the limits?}}, */ @@ -40,21 +40,24 @@ static simgrid::config::Flag cfg_network_solver("network/solver", /* month = Nov, */ /* pdf = {http://hal.inria.fr/hal-00646896/PDF/rr-validity.pdf}, */ /* } */ -void surf_network_model_init_LegrandVelho() -{ - auto net_model = std::make_shared("Network_LegrandVelho"); - auto* engine = simgrid::kernel::EngineImpl::get_instance(); - engine->add_model(net_model); - engine->get_netzone_root()->set_network_model(net_model); - - simgrid::config::set_default("network/latency-factor", "13.01"); - simgrid::config::set_default("network/bandwidth-factor", "0.97"); - simgrid::config::set_default("network/weight-S", 20537); -} - -/***************************************************************************/ -/* The nice TCP sharing model designed by Loris Marchal and Henri Casanova */ -/***************************************************************************/ +SIMGRID_REGISTER_NETWORK_MODEL( + LV08, + "Realistic network analytic model (slow-start modeled by multiplying latency by 13.01, bandwidth by .97; " + "bottleneck sharing uses a payload of S=20537 for evaluating RTT). ", + []() { + auto net_model = std::make_shared("Network_LegrandVelho"); + auto* engine = simgrid::kernel::EngineImpl::get_instance(); + engine->add_model(net_model); + engine->get_netzone_root()->set_network_model(net_model); + + simgrid::config::set_default("network/latency-factor", "13.01"); + simgrid::config::set_default("network/bandwidth-factor", "0.97"); + simgrid::config::set_default("network/weight-S", 20537); + }); + +/****************************************************************************/ +/* The older TCP sharing model designed by Loris Marchal and Henri Casanova */ +/****************************************************************************/ /* @TechReport{ rr-lip2002-40, */ /* author = {Henri Casanova and Loris Marchal}, */ /* institution = {LIP}, */ @@ -63,17 +66,20 @@ void surf_network_model_init_LegrandVelho() /* month = {oct}, */ /* year = {2002} */ /* } */ -void surf_network_model_init_CM02() -{ - simgrid::config::set_default("network/latency-factor", "1.0"); - simgrid::config::set_default("network/bandwidth-factor", "1.0"); - simgrid::config::set_default("network/weight-S", 0.0); - - auto net_model = std::make_shared("Network_CM02"); - auto* engine = simgrid::kernel::EngineImpl::get_instance(); - engine->add_model(net_model); - engine->get_netzone_root()->set_network_model(net_model); -} +SIMGRID_REGISTER_NETWORK_MODEL( + CM02, + "Legacy network analytic model (Very similar to LV08, but without corrective factors. The timings of " + "small messages are thus poorly modeled).", + []() { + simgrid::config::set_default("network/latency-factor", "1.0"); + simgrid::config::set_default("network/bandwidth-factor", "1.0"); + simgrid::config::set_default("network/weight-S", 0.0); + + auto net_model = std::make_shared("Network_CM02"); + auto* engine = simgrid::kernel::EngineImpl::get_instance(); + engine->add_model(net_model); + engine->get_netzone_root()->set_network_model(net_model); + }); /********************************************************************/ /* Model based on LV08 and experimental results of MPI ping-pongs */ @@ -87,21 +93,24 @@ void surf_network_model_init_CM02() /* month=may, */ /* year={2011} */ /* } */ -void surf_network_model_init_SMPI() -{ - auto net_model = std::make_shared("Network_SMPI"); - auto* engine = simgrid::kernel::EngineImpl::get_instance(); - engine->add_model(net_model); - engine->get_netzone_root()->set_network_model(net_model); - - simgrid::config::set_default("network/weight-S", 8775); - simgrid::config::set_default("network/bandwidth-factor", - "65472:0.940694;15424:0.697866;9376:0.58729;5776:1.08739;3484:0.77493;" - "1426:0.608902;732:0.341987;257:0.338112;0:0.812084"); - simgrid::config::set_default("network/latency-factor", - "65472:11.6436;15424:3.48845;9376:2.59299;5776:2.18796;3484:1.88101;" - "1426:1.61075;732:1.9503;257:1.95341;0:2.01467"); -} +SIMGRID_REGISTER_NETWORK_MODEL( + SMPI, + "Realistic network model specifically tailored for HPC settings (accurate modeling of slow start with " + "correction factors on three intervals: < 1KiB, < 64 KiB, >= 64 KiB)", + []() { + auto net_model = std::make_shared("Network_SMPI"); + auto* engine = simgrid::kernel::EngineImpl::get_instance(); + engine->add_model(net_model); + engine->get_netzone_root()->set_network_model(net_model); + + simgrid::config::set_default("network/weight-S", 8775); + simgrid::config::set_default("network/bandwidth-factor", + "65472:0.940694;15424:0.697866;9376:0.58729;5776:1.08739;3484:0.77493;" + "1426:0.608902;732:0.341987;257:0.338112;0:0.812084"); + simgrid::config::set_default("network/latency-factor", + "65472:11.6436;15424:3.48845;9376:2.59299;5776:2.18796;3484:1.88101;" + "1426:1.61075;732:1.9503;257:1.95341;0:2.01467"); + }); namespace simgrid::kernel::resource { diff --git a/src/surf/network_constant.cpp b/src/surf/network_constant.cpp index 2fc1acd317..6183b2da80 100644 --- a/src/surf/network_constant.cpp +++ b/src/surf/network_constant.cpp @@ -15,13 +15,17 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(res_network); /********* * Model * *********/ -void surf_network_model_init_Constant() -{ - auto net_model = std::make_shared("Network_Constant"); - auto* engine = simgrid::kernel::EngineImpl::get_instance(); - engine->add_model(net_model); - engine->get_netzone_root()->set_network_model(net_model); -} +SIMGRID_REGISTER_NETWORK_MODEL( + Constant, + "Simplistic network model where all communication take a constant time (one second). This model " + "provides the lowest realism, but is (marginally) faster. It is mostly useful when studying theoretical " + "distributed algorithms where the network is usually abstracted away.", + []() { + auto net_model = std::make_shared("Network_Constant"); + auto* engine = simgrid::kernel::EngineImpl::get_instance(); + engine->add_model(net_model); + engine->get_netzone_root()->set_network_model(net_model); + }); namespace simgrid::kernel::resource { diff --git a/src/surf/network_ib.cpp b/src/surf/network_ib.cpp index 5d80bd8387..04fba51398 100644 --- a/src/surf/network_ib.cpp +++ b/src/surf/network_ib.cpp @@ -30,20 +30,23 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(res_network); /* month=june, */ /* year={2010} */ /* } */ -void surf_network_model_init_IB() -{ - using simgrid::kernel::resource::NetworkIBModel; - - auto net_model = std::make_shared("Network_IB"); - auto* engine = simgrid::kernel::EngineImpl::get_instance(); - engine->add_model(net_model); - engine->get_netzone_root()->set_network_model(net_model); - - simgrid::s4u::Link::on_communication_state_change_cb(NetworkIBModel::IB_action_state_changed_callback); - simgrid::kernel::activity::CommImpl::on_start.connect(NetworkIBModel::IB_comm_start_callback); - simgrid::s4u::Host::on_creation_cb(NetworkIBModel::IB_create_host_callback); - simgrid::config::set_default("network/weight-S", 8775); -} +SIMGRID_REGISTER_NETWORK_MODEL( + IB, + "Realistic network model specifically tailored for HPC settings, with Infiniband contention model as described in " + "http://mescal.imag.fr/membres/jean-marc.vincent/index.html/PhD/Vienne.pdf", + []() { + using simgrid::kernel::resource::NetworkIBModel; + + auto net_model = std::make_shared("Network_IB"); + auto* engine = simgrid::kernel::EngineImpl::get_instance(); + engine->add_model(net_model); + engine->get_netzone_root()->set_network_model(net_model); + + simgrid::s4u::Link::on_communication_state_change_cb(NetworkIBModel::IB_action_state_changed_callback); + simgrid::kernel::activity::CommImpl::on_start.connect(NetworkIBModel::IB_comm_start_callback); + simgrid::s4u::Host::on_creation_cb(NetworkIBModel::IB_create_host_callback); + simgrid::config::set_default("network/weight-S", 8775); + }); namespace simgrid::kernel::resource { diff --git a/src/surf/network_ns3.cpp b/src/surf/network_ns3.cpp index 5ab5965842..aaa77ed748 100644 --- a/src/surf/network_ns3.cpp +++ b/src/surf/network_ns3.cpp @@ -51,8 +51,6 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(res_ns3, res_network, "Network model based on ns extern std::map> flow_from_sock; extern std::map> sink_from_sock; -static ns3::InternetStackHelper stack; - static int number_of_links = 1; static int number_of_networks = 1; @@ -67,6 +65,7 @@ static std::string transformIpv4Address(ns3::Ipv4Address from) NetPointNs3::NetPointNs3() { + static ns3::InternetStackHelper stack; stack.Install(ns3_node_); } @@ -276,12 +275,16 @@ static void routeCreation_cb(bool symmetrical, const simgrid::kernel::routing::N /********* * Model * *********/ -void surf_network_model_init_NS3() +// We can't use SIMGRID_REGISTER_NETWORK_MODEL here because ns-3 has a dash in its name +static void XBT_ATTRIB_CONSTRUCTOR(800) simgrid_ns3_network_model_register() { - auto net_model = std::make_shared("NS3 network model"); - auto* engine = simgrid::kernel::EngineImpl::get_instance(); - engine->add_model(net_model); - engine->get_netzone_root()->set_network_model(net_model); + simgrid_network_models().add( + "ns-3", "Network pseudo-model using the real ns-3 simulator instead of an analytic model", []() { + auto net_model = std::make_shared("NS3 network model"); + auto* engine = simgrid::kernel::EngineImpl::get_instance(); + engine->add_model(net_model); + engine->get_netzone_root()->set_network_model(net_model); + }); } static simgrid::config::Flag diff --git a/src/surf/sg_platf.cpp b/src/surf/sg_platf.cpp index 59c6007baf..9f2a198685 100644 --- a/src/surf/sg_platf.cpp +++ b/src/surf/sg_platf.cpp @@ -29,7 +29,7 @@ #include #include -XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_parse); +XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(platf_parse); namespace simgrid::kernel::routing { xbt::signal on_cluster_creation; diff --git a/src/surf/surf_interface.cpp b/src/surf/surf_interface.cpp index b0721c77c1..b22836ee09 100644 --- a/src/surf/surf_interface.cpp +++ b/src/surf/surf_interface.cpp @@ -16,99 +16,8 @@ #include #include -XBT_LOG_NEW_CATEGORY(surf, "All SURF categories"); -XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_kernel, surf, "Logging specific to SURF (kernel)"); - /********* * Utils * *********/ -simgrid::kernel::profile::FutureEvtSet future_evt_set; std::vector surf_path; - -const std::vector surf_network_model_description = { - {"LV08", - "Realistic network analytic model (slow-start modeled by multiplying latency by 13.01, bandwidth by .97; " - "bottleneck sharing uses a payload of S=20537 for evaluating RTT). ", - &surf_network_model_init_LegrandVelho}, - {"Constant", - "Simplistic network model where all communication take a constant time (one second). This model " - "provides the lowest realism, but is (marginally) faster.", - &surf_network_model_init_Constant}, - {"SMPI", - "Realistic network model specifically tailored for HPC settings (accurate modeling of slow start with " - "correction factors on three intervals: < 1KiB, < 64 KiB, >= 64 KiB)", - &surf_network_model_init_SMPI}, - {"IB", "Realistic network model specifically tailored for HPC settings, with Infiniband contention model", - &surf_network_model_init_IB}, - {"CM02", - "Legacy network analytic model (Very similar to LV08, but without corrective factors. The timings of " - "small messages are thus poorly modeled).", - &surf_network_model_init_CM02}, - {"ns-3", "Network pseudo-model using the ns-3 tcp model instead of an analytic model", - &surf_network_model_init_NS3}, -}; - -#if !HAVE_SMPI -void surf_network_model_init_IB() -{ - xbt_die("Please activate SMPI support in cmake to use the IB network model."); -} -#endif -#if !SIMGRID_HAVE_NS3 -void surf_network_model_init_NS3() -{ - xbt_die("Please activate ns-3 support in cmake and install the dependencies to use the NS3 network model."); -} -#endif - -const std::vector surf_cpu_model_description = { - {"Cas01", "Simplistic CPU model (time=size/speed).", &surf_cpu_model_init_Cas01}, -}; - -const std::vector surf_disk_model_description = { - {"S19", "Simplistic disk model.", &surf_disk_model_init_S19}, -}; - -const std::vector surf_host_model_description = { - {"default", "Default host model. Currently, CPU:Cas01, network:LV08 (with cross traffic enabled), and disk:S19", - &surf_host_model_init_current_default}, - {"compound", "Host model that is automatically chosen if you change the CPU, network, and disk models", - &surf_host_model_init_compound}, - {"ptask_L07", "Host model somehow similar to Cas01+CM02+S19 but allowing parallel tasks", - &surf_host_model_init_ptask_L07}, -}; - -const std::vector surf_optimization_mode_description = { - {"Lazy", "Lazy action management (partial invalidation in lmm + heap in action remaining).", nullptr}, - {"TI", - "Trace integration. Highly optimized mode when using availability traces (only available for the Cas01 CPU " - "model for now).", - nullptr}, - {"Full", "Full update of remaining and variables. Slow but may be useful when debugging.", nullptr}, -}; - -/** Displays the long description of all registered models, and quit */ -void model_help(const char* category, const std::vector& table) -{ - XBT_HELP("Long description of the %s models accepted by this simulator:", category); - for (auto const& item : table) - XBT_HELP(" %s: %s", item.name, item.description); -} - -const surf_model_description_t* find_model_description(const std::vector& table, - const std::string& name) -{ - if (auto pos = std::find_if(table.begin(), table.end(), - [&name](const surf_model_description_t& item) { return item.name == name; }); - pos != table.end()) - return &*pos; - - std::string sep; - std::string name_list; - for (auto const& item : table) { - name_list += sep + item.name; - sep = ", "; - } - xbt_die("Model '%s' is invalid! Valid models are: %s.", name.c_str(), name_list.c_str()); -} diff --git a/src/surf/surf_interface.hpp b/src/surf/surf_interface.hpp index 7907a68afc..0a48400102 100644 --- a/src/surf/surf_interface.hpp +++ b/src/surf/surf_interface.hpp @@ -6,10 +6,12 @@ #ifndef SURF_MODEL_H_ #define SURF_MODEL_H_ +#include "src/simgrid/module.hpp" #include #include #include "src/internal_config.h" +#include "src/kernel/resource/profile/Profile.hpp" #include #include @@ -74,79 +76,12 @@ XBT_PUBLIC void surf_cpu_model_init_Cas01(); XBT_PUBLIC void surf_disk_model_init_S19(); -/** @ingroup SURF_models - * @brief Same as network model 'LagrangeVelho', only with different correction factors. - * - * This model is proposed by Pierre-Nicolas Clauss and Martin Quinson and Stéphane Génaud based on the model 'LV08' and - * different correction factors depending on the communication size (< 1KiB, < 64KiB, >= 64KiB). - * See comments in the code for more information. - * - * @see surf_host_model_init_SMPI() - */ -XBT_PUBLIC void surf_network_model_init_SMPI(); - -/** @ingroup SURF_models - * @brief Same as network model 'LagrangeVelho', only with different correction factors. - * - * This model implements a variant of the contention model on Infiniband networks based on - * the works of Jérôme Vienne : http://mescal.imag.fr/membres/jean-marc.vincent/index.html/PhD/Vienne.pdf - * - * @see surf_host_model_init_IB() - */ -#if !HAVE_SMPI -XBT_ATTRIB_NORETURN -#endif -XBT_PUBLIC void surf_network_model_init_IB(); - -/** @ingroup SURF_models - * @brief Initializes the platform with the network model 'LegrandVelho' - * - * This model is proposed by Arnaud Legrand and Pedro Velho based on the results obtained with the GTNets simulator for - * onelink and dogbone sharing scenarios. See comments in the code for more information. - * - * @see surf_host_model_init_LegrandVelho() - */ -XBT_PUBLIC void surf_network_model_init_LegrandVelho(); - -/** @ingroup SURF_models - * @brief Initializes the platform with the network model 'Constant' - * - * In this model, the communication time between two network cards is constant, hence no need for a routing table. - * This is particularly useful when simulating huge distributed algorithms where scalability is really an issue. This - * function is called in conjunction with surf_host_model_init_compound. - * - * @see surf_host_model_init_compound() - */ -XBT_PUBLIC void surf_network_model_init_Constant(); - -/** @ingroup SURF_models - * @brief Initializes the platform with the network model CM02 - * - * You should call this function by yourself only if you plan using surf_host_model_init_compound. - * See comments in the code for more information. - */ -XBT_PUBLIC void surf_network_model_init_CM02(); - -/** @ingroup SURF_models - * @brief Initializes the platform with the network model NS3 - * - * This function is called by surf_host_model_init_NS3 or by yourself only if you plan using - * surf_host_model_init_compound - * - * @see surf_host_model_init_NS3() - */ -#if !SIMGRID_HAVE_NS3 -XBT_ATTRIB_NORETURN -#endif -XBT_PUBLIC void surf_network_model_init_NS3(); - /** @ingroup SURF_models * @brief Initializes the VM model used in the platform * * A VM model depends on the physical CPU model to share the resources inside the VM * It will also creates the CPU model for actions running inside the VM * - * Such model is subject to modification with warning in the ChangeLog so monitor it! */ XBT_PUBLIC void surf_vm_model_init_HL13(simgrid::kernel::resource::CpuModel* cpu_pm_model); @@ -178,39 +113,17 @@ XBT_PUBLIC void surf_host_model_init_ptask_L07(); /* -------------------- * Model Descriptions * -------------------- */ -/** @brief Resource model description */ -struct surf_model_description_t { - const char* name; - const char* description; - std::function model_init_preparse; -}; - -XBT_PUBLIC const surf_model_description_t* find_model_description(const std::vector& table, - const std::string& name); -XBT_PUBLIC void model_help(const char* category, const std::vector& table); - -#define SIMGRID_REGISTER_PLUGIN(id, desc, init) \ - static void XBT_ATTRIB_CONSTRUCTOR(800) _XBT_CONCAT3(simgrid_, id, _plugin_register)() \ - { \ - surf_plugin_description().emplace_back(surf_model_description_t{_XBT_STRINGIFY(id), (desc), (init)}); \ - } -/** @brief The list of all available plugins */ -inline auto& surf_plugin_description() // Function to avoid static initialization order fiasco -{ - static std::vector plugin_description_table; - return plugin_description_table; -} /** @brief The list of all available optimization modes (both for cpu and networks). * These optimization modes can be set using --cfg=cpu/optim:... and --cfg=network/optim:... */ -XBT_PUBLIC_DATA const std::vector surf_optimization_mode_description; +XBT_PUBLIC_DATA simgrid::ModuleGroup surf_optimization_mode_description; /** @brief The list of all cpu models (pick one with --cfg=cpu/model) */ -XBT_PUBLIC_DATA const std::vector surf_cpu_model_description; -/** @brief The list of all network models (pick one with --cfg=network/model) */ -XBT_PUBLIC_DATA const std::vector surf_network_model_description; +XBT_PUBLIC_DATA simgrid::ModuleGroup surf_cpu_model_description; /** @brief The list of all disk models (pick one with --cfg=disk/model) */ -XBT_PUBLIC_DATA const std::vector surf_disk_model_description; +XBT_PUBLIC_DATA simgrid::ModuleGroup surf_disk_model_description; /** @brief The list of all host models (pick one with --cfg=host/model:) */ -XBT_PUBLIC_DATA const std::vector surf_host_model_description; +XBT_PUBLIC_DATA simgrid::ModuleGroup surf_host_model_description; + +void simgrid_create_models(); #endif /* SURF_MODEL_H_ */ diff --git a/src/surf/xml/surfxml_parseplatf.cpp b/src/surf/xml/surfxml_parseplatf.cpp index 5cfc7f2ffa..951b12a0d4 100644 --- a/src/surf/xml/surfxml_parseplatf.cpp +++ b/src/surf/xml/surfxml_parseplatf.cpp @@ -13,15 +13,13 @@ #include -XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_parse); - /* Trace related stuff */ XBT_PRIVATE std::unordered_map traces_set_list; -XBT_PRIVATE std::unordered_map trace_connect_list_host_avail; -XBT_PRIVATE std::unordered_map trace_connect_list_host_speed; -XBT_PRIVATE std::unordered_map trace_connect_list_link_avail; -XBT_PRIVATE std::unordered_map trace_connect_list_link_bw; -XBT_PRIVATE std::unordered_map trace_connect_list_link_lat; +static std::unordered_map trace_connect_list_host_avail; +static std::unordered_map trace_connect_list_host_speed; +static std::unordered_map trace_connect_list_link_avail; +static std::unordered_map trace_connect_list_link_bw; +static std::unordered_map trace_connect_list_link_lat; void sg_platf_trace_connect(simgrid::kernel::routing::TraceConnectCreationArgs* trace_connect) { diff --git a/src/surf/xml/surfxml_sax_cb.cpp b/src/surf/xml/surfxml_sax_cb.cpp index 567a2b2377..ad0431a697 100644 --- a/src/surf/xml/surfxml_sax_cb.cpp +++ b/src/surf/xml/surfxml_sax_cb.cpp @@ -26,10 +26,10 @@ #include "simgrid_dtd.c" -XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_parse, surf, "Logging specific to the SURF parsing module"); +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(platf_parse, ker_platform, "Logging specific to the parsing of platform files"); std::string surf_parsed_filename; // Currently parsed file (for the error messages) -std::vector parsed_link_list; /* temporary store of current link list of a route */ +static std::vector parsed_link_list; /* temporary store of current link list of a route */ /* Helping functions */ void surf_parse_assert(bool cond, const std::string& msg) @@ -127,9 +127,9 @@ static void explodesRadical(const std::string& radicals, std::vector* explo /* make sure these symbols are defined as strong ones in this file so that the linker can resolve them */ -std::vector> property_sets; +static std::vector> property_sets; -FILE *surf_file_to_parse = nullptr; +static FILE* surf_file_to_parse = nullptr; /* Stuff relative to storage */ void STag_surfxml_storage() @@ -826,7 +826,7 @@ void ETag_surfxml_argument(){/* Nothing to do */} void ETag_surfxml_model___prop(){/* Nothing to do */} /* Open and Close parse file */ -YY_BUFFER_STATE surf_input_buffer; +static YY_BUFFER_STATE surf_input_buffer; void surf_parse_open(const std::string& file) { diff --git a/src/xbt/log.cpp b/src/xbt/log.cpp index 642fe2acc9..88726a9fca 100644 --- a/src/xbt/log.cpp +++ b/src/xbt/log.cpp @@ -19,10 +19,6 @@ #include int xbt_log_no_loc = 0; /* if set to true (with --log=no_loc), file localization will be omitted (for tesh tests) */ -static std::recursive_mutex* log_cat_init_mutex = nullptr; - -xbt_log_appender_t xbt_log_default_appender = nullptr; /* set in log_init */ -xbt_log_layout_t xbt_log_default_layout = nullptr; /* set in log_init */ struct xbt_log_setting_t { std::string catname; @@ -58,17 +54,6 @@ s_xbt_log_category_t _XBT_LOGV(XBT_LOG_ROOT_CAT) = { XBT_LOG_NEW_DEFAULT_SUBCATEGORY(log, xbt, "Loggings from the logging mechanism itself"); -/* create the default appender and install it in the root category, - which were already created (damnit. Too slow little beetle) */ -void xbt_log_preinit(void) -{ - xbt_log_default_appender = xbt_log_appender_stream(stderr); - xbt_log_default_layout = xbt_log_layout_simple_new(nullptr); - _XBT_LOGV(XBT_LOG_ROOT_CAT).appender = xbt_log_default_appender; - _XBT_LOGV(XBT_LOG_ROOT_CAT).layout = xbt_log_default_layout; - log_cat_init_mutex = new std::recursive_mutex(); -} - static void xbt_log_help(); static void xbt_log_help_categories(); @@ -132,7 +117,6 @@ static void log_cat_exit(const s_xbt_log_category_t* cat) void xbt_log_postexit(void) { XBT_VERB("Exiting log"); - delete log_cat_init_mutex; log_cat_exit(&_XBT_LOGV(XBT_LOG_ROOT_CAT)); } @@ -246,8 +230,8 @@ int _xbt_log_cat_init(xbt_log_category_t category, e_xbt_log_priority_t priority if (category->initialized) return priority >= category->threshold; - if (log_cat_init_mutex != nullptr) - log_cat_init_mutex->lock(); + static std::recursive_mutex log_cat_init_mutex; + log_cat_init_mutex.lock(); XBT_DEBUG("Initializing category '%s' (firstChild=%s, nextSibling=%s)", category->name, (category->firstChild ? category->firstChild->name : "none"), @@ -255,8 +239,8 @@ int _xbt_log_cat_init(xbt_log_category_t category, e_xbt_log_priority_t priority if (category == &_XBT_LOGV(XBT_LOG_ROOT_CAT)) { category->threshold = xbt_log_priority_info; - category->appender = xbt_log_default_appender; - category->layout = xbt_log_default_layout; + category->appender = xbt_log_appender_stream(stderr); + category->layout = xbt_log_layout_simple_new(nullptr); } else { if (not category->parent) category->parent = &_XBT_LOGV(XBT_LOG_ROOT_CAT); @@ -291,8 +275,7 @@ int _xbt_log_cat_init(xbt_log_category_t category, e_xbt_log_priority_t priority } category->initialized = 1; - if (log_cat_init_mutex != nullptr) - log_cat_init_mutex->unlock(); + log_cat_init_mutex.unlock(); return priority >= category->threshold; } diff --git a/src/xbt/xbt_main.cpp b/src/xbt/xbt_main.cpp index 4d41e07467..8e70ab99c8 100644 --- a/src/xbt/xbt_main.cpp +++ b/src/xbt/xbt_main.cpp @@ -64,7 +64,6 @@ XBT_ATTRIB_NOINLINE void sthread_disable() static void xbt_preinit() { - xbt_log_preinit(); xbt_dict_preinit(); atexit(xbt_postexit); } diff --git a/teshsuite/xbt/parmap_bench/parmap_bench.cpp b/teshsuite/xbt/parmap_bench/parmap_bench.cpp index 09a186ef18..ccab38bb79 100644 --- a/teshsuite/xbt/parmap_bench/parmap_bench.cpp +++ b/teshsuite/xbt/parmap_bench/parmap_bench.cpp @@ -133,7 +133,7 @@ int main(int argc, char* argv[]) XBT_INFO("Parmap benchmark with %d workers (modes = %#x)...", nthreads, modes); XBT_INFO("%s", ""); - simgrid::kernel::context::set_nthreads(nthreads); + simgrid::kernel::context::Context::set_nthreads(nthreads); XBT_INFO("Benchmark for parmap create+apply+destroy (small comp):"); bench_all_modes(nthreads, timeout, modes, true, &fun_small_comp); diff --git a/teshsuite/xbt/parmap_test/parmap_test.cpp b/teshsuite/xbt/parmap_test/parmap_test.cpp index c7558c995e..e79cb393e0 100644 --- a/teshsuite/xbt/parmap_test/parmap_test.cpp +++ b/teshsuite/xbt/parmap_test/parmap_test.cpp @@ -88,7 +88,7 @@ int main(int argc, char** argv) int status = 0; xbt_log_control_set("parmap_test.fmt:[%c/%p]%e%m%n"); simgrid::s4u::Engine e(&argc, argv); - simgrid::kernel::context::set_nthreads(16); // dummy value > 1 + simgrid::kernel::context::Context::set_nthreads(16); // dummy value > 1 XBT_INFO("Basic testing posix"); status += test_parmap_basic(XBT_PARMAP_POSIX); diff --git a/tools/cmake/DefinePackages.cmake b/tools/cmake/DefinePackages.cmake index 3711fbd46d..4310792fe1 100644 --- a/tools/cmake/DefinePackages.cmake +++ b/tools/cmake/DefinePackages.cmake @@ -469,6 +469,8 @@ set(S4U_SRC set(SIMGRID_SRC src/simgrid/Exception.cpp + src/simgrid/module.cpp + src/simgrid/module.hpp src/simgrid/sg_config.cpp src/simgrid/sg_version.cpp src/simgrid/util.hpp