From: SUTER Frederic Date: Sun, 16 May 2021 12:51:27 +0000 (+0200) Subject: move kernel timers from simix:: to kernel::timer:: X-Git-Tag: v3.28~280 X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/76081077f259960acb8a8624359ad2aa5c32ab46 move kernel timers from simix:: to kernel::timer:: --- diff --git a/MANIFEST.in b/MANIFEST.in index 79afec6862..5225d57808 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1970,6 +1970,7 @@ include include/simgrid/jedule/jedule.hpp include include/simgrid/jedule/jedule_events.hpp include include/simgrid/jedule/jedule_platform.hpp include include/simgrid/jedule/jedule_sd_binding.h +include include/simgrid/kernel/Timer.hpp include include/simgrid/kernel/future.hpp include include/simgrid/kernel/resource/Action.hpp include include/simgrid/kernel/resource/Model.hpp @@ -2229,6 +2230,7 @@ include src/kernel/routing/TorusZone.cpp include src/kernel/routing/TorusZone_test.cpp include src/kernel/routing/VivaldiZone.cpp include src/kernel/routing/WifiZone.cpp +include src/kernel/timer/Timer.cpp include src/mc/AddressSpace.hpp include src/mc/ModelChecker.cpp include src/mc/ModelChecker.hpp diff --git a/include/simgrid/forward.h b/include/simgrid/forward.h index 18368a6da9..7f110d54a6 100644 --- a/include/simgrid/forward.h +++ b/include/simgrid/forward.h @@ -166,6 +166,9 @@ class NetworkAction; class DiskImpl; class DiskModel; } +namespace timer { +class Timer; +} namespace routing { class NetPoint; class NetZoneImpl; @@ -178,7 +181,6 @@ class Profile; } // namespace kernel namespace simix { class Host; - class Timer; } namespace surf { class HostImpl; @@ -208,7 +210,7 @@ using s4u_Disk = simgrid::s4u::Disk; using s4u_NetZone = simgrid::s4u::NetZone; using s4u_VM = simgrid::s4u::VirtualMachine; -using smx_timer_t = simgrid::simix::Timer*; +using smx_timer_t = simgrid::kernel::timer::Timer*; using smx_actor_t = simgrid::kernel::actor::ActorImpl*; using smx_activity_t = simgrid::kernel::activity::ActivityImpl*; using smx_cond_t = simgrid::kernel::activity::ConditionVariableImpl*; diff --git a/include/simgrid/kernel/Timer.hpp b/include/simgrid/kernel/Timer.hpp new file mode 100644 index 0000000000..d5f1e15084 --- /dev/null +++ b/include/simgrid/kernel/Timer.hpp @@ -0,0 +1,51 @@ +/* Copyright (c) 2021. 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 SRC_KERNEL_TIMER_TIMER_HPP_ +#define SRC_KERNEL_TIMER_TIMER_HPP_ + +#include +#include +#include + +#include + +namespace simgrid { +namespace kernel { +namespace timer { + +inline auto& kernel_timers() // avoid static initialization order fiasco +{ + using TimerQelt = std::pair; + static boost::heap::fibonacci_heap>> value; + return value; +} + +/** @brief Timer datatype */ +class Timer { +public: + const double date; + std::remove_reference_t::handle_type handle_; + + Timer(double date, xbt::Task&& callback) : date(date), callback(std::move(callback)) {} + + xbt::Task callback; + void remove(); + + template static inline Timer* set(double date, F callback) + { + return set(date, xbt::Task(std::move(callback))); + } + + static Timer* set(double date, xbt::Task&& callback); + static double next() { return kernel_timers().empty() ? -1.0 : kernel_timers().top().first; } +}; + +} // namespace timer +} // namespace kernel +} // namespace simgrid + +#endif /* SRC_KERNEL_TIMER_TIMER_HPP_ */ diff --git a/include/simgrid/kernel/future.hpp b/include/simgrid/kernel/future.hpp index e3a24687ac..332cf19157 100644 --- a/include/simgrid/kernel/future.hpp +++ b/include/simgrid/kernel/future.hpp @@ -413,7 +413,7 @@ template Future unwrap_future(Future> future) * auto promise = std::make_shared>(); * auto future = promise->get_future(); * - * simgrid::simix::Timer::set(date, [promise] { + * simgrid::kernel::timer::Timer::set(date, [promise] { * try { * int value = compute_the_value(); * if (value < 0) diff --git a/include/simgrid/simix.h b/include/simgrid/simix.h index 189c36b47b..e69bb74621 100644 --- a/include/simgrid/simix.h +++ b/include/simgrid/simix.h @@ -48,12 +48,12 @@ XBT_PUBLIC void SIMIX_set_maestro(void (*code)(void*), void* data); XBT_PUBLIC void SIMIX_run(); XBT_PUBLIC double SIMIX_get_clock(); -XBT_ATTRIB_DEPRECATED_v329("Please use simgrid::simix::Timer::set()") XBT_PUBLIC smx_timer_t +XBT_ATTRIB_DEPRECATED_v329("Please use simgrid::kernel::timer::Timer::set()") XBT_PUBLIC smx_timer_t SIMIX_timer_set(double date, void (*function)(void*), void* arg); -XBT_ATTRIB_DEPRECATED_v329("Please use simgrid::simix::Timer::remove()") XBT_PUBLIC +XBT_ATTRIB_DEPRECATED_v329("Please use simgrid::kernel::timer::Timer::remove()") XBT_PUBLIC void SIMIX_timer_remove(smx_timer_t timer); -XBT_ATTRIB_DEPRECATED_v329("Please use simgrid::simix::Timer::next()") XBT_PUBLIC double SIMIX_timer_next(); -XBT_ATTRIB_DEPRECATED_v329("Please use simgrid::simix::Timer::get_date()") XBT_PUBLIC +XBT_ATTRIB_DEPRECATED_v329("Please use simgrid::kernel::timer::Timer::next()") XBT_PUBLIC double SIMIX_timer_next(); +XBT_ATTRIB_DEPRECATED_v329("Please use simgrid::kernel::timer::Timer::get_date()") XBT_PUBLIC double SIMIX_timer_get_date(smx_timer_t timer); XBT_ATTRIB_DEPRECATED_v329("Please use simix_global->display_all_actor_status()") XBT_PUBLIC diff --git a/include/simgrid/simix.hpp b/include/simgrid/simix.hpp index e931b8300d..1acd620f51 100644 --- a/include/simgrid/simix.hpp +++ b/include/simgrid/simix.hpp @@ -8,12 +8,9 @@ #define SIMGRID_SIMIX_HPP #include -#include #include #include -#include -#include #include #include @@ -102,33 +99,6 @@ namespace simix { XBT_PUBLIC void unblock(smx_actor_t process); -inline auto& simix_timers() // avoid static initialization order fiasco -{ - using TimerQelt = std::pair; - static boost::heap::fibonacci_heap>> value; - return value; -} - -/** @brief Timer datatype */ -class Timer { -public: - const double date; - std::remove_reference_t::handle_type handle_; - - Timer(double date, simgrid::xbt::Task&& callback) : date(date), callback(std::move(callback)) {} - - simgrid::xbt::Task callback; - void remove(); - - template static inline Timer* set(double date, F callback) - { - return set(date, simgrid::xbt::Task(std::move(callback))); - } - - static Timer* set(double date, simgrid::xbt::Task&& callback); - static double next() { return simix_timers().empty() ? -1.0 : simix_timers().top().first; } -}; - // In MC mode, the application sends these pointers to the MC xbt_dynar_t simix_global_get_actors_addr(); xbt_dynar_t simix_global_get_dead_actors_addr(); diff --git a/src/kernel/activity/CommImpl.cpp b/src/kernel/activity/CommImpl.cpp index 303566a233..b914b3de3a 100644 --- a/src/kernel/activity/CommImpl.cpp +++ b/src/kernel/activity/CommImpl.cpp @@ -453,7 +453,7 @@ void CommImpl::wait_any_for(actor::ActorImpl* issuer, const std::vectorsimcall_.timeout_cb_ = nullptr; } else { - issuer->simcall_.timeout_cb_ = simix::Timer::set(SIMIX_get_clock() + timeout, [issuer, comms]() { + issuer->simcall_.timeout_cb_ = timer::Timer::set(SIMIX_get_clock() + timeout, [issuer, comms]() { // FIXME: Vector `comms' is copied here. Use a reference once its lifetime is extended (i.e. when the simcall is // modernized). issuer->simcall_.timeout_cb_ = nullptr; diff --git a/src/kernel/activity/ExecImpl.cpp b/src/kernel/activity/ExecImpl.cpp index 3553841d57..c1d2583cce 100644 --- a/src/kernel/activity/ExecImpl.cpp +++ b/src/kernel/activity/ExecImpl.cpp @@ -241,7 +241,7 @@ void ExecImpl::wait_any_for(actor::ActorImpl* issuer, const std::vectorsimcall_.timeout_cb_ = nullptr; } else { - issuer->simcall_.timeout_cb_ = simix::Timer::set(SIMIX_get_clock() + timeout, [issuer, &execs]() { + issuer->simcall_.timeout_cb_ = timer::Timer::set(SIMIX_get_clock() + timeout, [issuer, &execs]() { issuer->simcall_.timeout_cb_ = nullptr; for (auto* exec : execs) exec->unregister_simcall(&issuer->simcall_); diff --git a/src/kernel/activity/IoImpl.cpp b/src/kernel/activity/IoImpl.cpp index 3621e1c127..034099dc90 100644 --- a/src/kernel/activity/IoImpl.cpp +++ b/src/kernel/activity/IoImpl.cpp @@ -152,7 +152,7 @@ void IoImpl::wait_any_for(actor::ActorImpl* issuer, const std::vector& if (timeout < 0.0) { issuer->simcall_.timeout_cb_ = nullptr; } else { - issuer->simcall_.timeout_cb_ = simix::Timer::set(SIMIX_get_clock() + timeout, [issuer, &ios]() { + issuer->simcall_.timeout_cb_ = timer::Timer::set(SIMIX_get_clock() + timeout, [issuer, &ios]() { issuer->simcall_.timeout_cb_ = nullptr; for (auto* io : ios) io->unregister_simcall(&issuer->simcall_); diff --git a/src/kernel/actor/ActorImpl.cpp b/src/kernel/actor/ActorImpl.cpp index 06d324c478..a55d76ae1f 100644 --- a/src/kernel/actor/ActorImpl.cpp +++ b/src/kernel/actor/ActorImpl.cpp @@ -275,7 +275,7 @@ void ActorImpl::set_kill_time(double kill_time) if (kill_time <= SIMIX_get_clock()) return; XBT_DEBUG("Set kill time %f for actor %s@%s", kill_time, get_cname(), host_->get_cname()); - kill_timer_ = simix::Timer::set(kill_time, [this] { + kill_timer_ = timer::Timer::set(kill_time, [this] { this->exit(); kill_timer_ = nullptr; }); diff --git a/src/kernel/actor/ActorImpl.hpp b/src/kernel/actor/ActorImpl.hpp index d32bea829f..85cdf80db1 100644 --- a/src/kernel/actor/ActorImpl.hpp +++ b/src/kernel/actor/ActorImpl.hpp @@ -6,6 +6,7 @@ #ifndef SIMGRID_KERNEL_ACTOR_ACTORIMPL_HPP #define SIMGRID_KERNEL_ACTOR_ACTORIMPL_HPP +#include "simgrid/kernel/Timer.hpp" #include "simgrid/s4u/Actor.hpp" #include "src/simix/popping_private.hpp" #include "xbt/PropertyHolder.hpp" @@ -77,7 +78,7 @@ public: std::make_shared>>(); std::function code_; - simix::Timer* kill_timer_ = nullptr; + timer::Timer* kill_timer_ = nullptr; private: /* Refcounting */ diff --git a/src/kernel/timer/Timer.cpp b/src/kernel/timer/Timer.cpp new file mode 100644 index 0000000000..9c4123280a --- /dev/null +++ b/src/kernel/timer/Timer.cpp @@ -0,0 +1,29 @@ +/* Copyright (c) 2021. The SimGrid Team. + * All rights reserved. */ + +/* This program is free software; you can redistribute it and/or modify it + * under the terms of the license (GNU LGPL) which comes with this package. */ + +#include "simgrid/kernel/Timer.hpp" + +namespace simgrid { +namespace kernel { +namespace timer { + +Timer* Timer::set(double date, xbt::Task&& callback) +{ + auto* timer = new Timer(date, std::move(callback)); + timer->handle_ = kernel_timers().emplace(std::make_pair(date, timer)); + return timer; +} + +/** @brief cancels a timer that was added earlier */ +void Timer::remove() +{ + kernel_timers().erase(handle_); + delete this; +} + +} // namespace timer +} // namespace kernel +} // namespace simgrid diff --git a/src/simix/popping_private.hpp b/src/simix/popping_private.hpp index f02203c975..13ab4f17ac 100644 --- a/src/simix/popping_private.hpp +++ b/src/simix/popping_private.hpp @@ -44,9 +44,9 @@ union u_smx_scalar { * @brief Represents a simcall to the kernel. */ struct s_smx_simcall { - simgrid::simix::Simcall call_ = simgrid::simix::Simcall::NONE; - smx_actor_t issuer_ = nullptr; - smx_timer_t timeout_cb_ = nullptr; // Callback to timeouts + simgrid::simix::Simcall call_ = simgrid::simix::Simcall::NONE; + smx_actor_t issuer_ = nullptr; + simgrid::kernel::timer::Timer* timeout_cb_ = nullptr; // Callback to timeouts simgrid::kernel::actor::SimcallObserver* observer_ = nullptr; // makes that simcall observable by the MC unsigned int mc_max_consider_ = 0; // How many times this simcall should be used. If >1, this will be a fork in the state space. diff --git a/src/simix/smx_global.cpp b/src/simix/smx_global.cpp index b5f5b98804..aa1e972100 100644 --- a/src/simix/smx_global.cpp +++ b/src/simix/smx_global.cpp @@ -4,6 +4,7 @@ * under the terms of the license (GNU LGPL) which comes with this package. */ #include "mc/mc.h" +#include "simgrid/kernel/Timer.hpp" #include "simgrid/s4u/Engine.hpp" #include "simgrid/s4u/Host.hpp" #include "src/smpi/include/smpi_actor.hpp" @@ -148,20 +149,6 @@ static void install_segvhandler() namespace simgrid { namespace simix { -Timer* Timer::set(double date, xbt::Task&& callback) -{ - auto* timer = new Timer(date, std::move(callback)); - timer->handle_ = simix_timers().emplace(std::make_pair(date, timer)); - return timer; -} - -/** @brief cancels a timer that was added earlier */ -void Timer::remove() -{ - simix_timers().erase(handle_); - delete this; -} - /** Execute all the tasks that are queued, e.g. `.then()` callbacks of futures. */ bool Global::execute_tasks() { @@ -359,9 +346,9 @@ void SIMIX_clean() /* Exit the SIMIX network module */ SIMIX_mailbox_exit(); - while (not simgrid::simix::simix_timers().empty()) { - delete simgrid::simix::simix_timers().top().second; - simgrid::simix::simix_timers().pop(); + while (not simgrid::kernel::timer::kernel_timers().empty()) { + delete simgrid::kernel::timer::kernel_timers().top().second; + simgrid::kernel::timer::kernel_timers().pop(); } /* Free the remaining data structures */ simix_global->actors_to_run.clear(); @@ -405,12 +392,12 @@ double SIMIX_get_clock() static bool SIMIX_execute_timers() { bool result = false; - while (not simgrid::simix::simix_timers().empty() && - SIMIX_get_clock() >= simgrid::simix::simix_timers().top().first) { + while (not simgrid::kernel::timer::kernel_timers().empty() && + SIMIX_get_clock() >= simgrid::kernel::timer::kernel_timers().top().first) { result = true; // FIXME: make the timers being real callbacks (i.e. provide dispatchers that read and expand the args) - smx_timer_t timer = simgrid::simix::simix_timers().top().second; - simgrid::simix::simix_timers().pop(); + simgrid::kernel::timer::Timer* timer = simgrid::kernel::timer::kernel_timers().top().second; + simgrid::kernel::timer::kernel_timers().pop(); timer->callback(); delete timer; } @@ -532,7 +519,7 @@ void SIMIX_run() } } - time = simgrid::simix::Timer::next(); + time = simgrid::kernel::timer::Timer::next(); if (time > -1.0 || not simix_global->process_list.empty()) { XBT_DEBUG("Calling surf_solve"); time = surf_solve(time); @@ -582,12 +569,12 @@ void SIMIX_run() double SIMIX_timer_next() // XBT_ATTRIB_DEPRECATED_v329 { - return simgrid::simix::Timer::next(); + return simgrid::kernel::timer::Timer::next(); } smx_timer_t SIMIX_timer_set(double date, void (*callback)(void*), void* arg) // XBT_ATTRIB_DEPRECATED_v329 { - return simgrid::simix::Timer::set(date, std::bind(callback, arg)); + return simgrid::kernel::timer::Timer::set(date, std::bind(callback, arg)); } /** @brief cancels a timer that was added earlier */ diff --git a/src/surf/sg_platf.cpp b/src/surf/sg_platf.cpp index 882e3fb7af..8d8d4f1042 100644 --- a/src/surf/sg_platf.cpp +++ b/src/surf/sg_platf.cpp @@ -500,7 +500,7 @@ void sg_platf_new_actor(simgrid::kernel::routing::ActorCreationArgs* actor) auto_restart); XBT_DEBUG("Process %s@%s will be started at time %f", arg->name.c_str(), arg->host->get_cname(), start_time); - simgrid::simix::Timer::set(start_time, [arg, auto_restart]() { + simgrid::kernel::timer::Timer::set(start_time, [arg, auto_restart]() { simgrid::kernel::actor::ActorImplPtr new_actor = simgrid::kernel::actor::ActorImpl::create(arg->name.c_str(), arg->code, arg->data, arg->host, nullptr); new_actor->set_properties(arg->properties); diff --git a/teshsuite/kernel/simcall-generic/simcall-generic.cpp b/teshsuite/kernel/simcall-generic/simcall-generic.cpp index db7ecb6fd8..c7de734eb5 100644 --- a/teshsuite/kernel/simcall-generic/simcall-generic.cpp +++ b/teshsuite/kernel/simcall-generic/simcall-generic.cpp @@ -8,6 +8,7 @@ #include +#include #include #include #include @@ -29,7 +30,7 @@ static simgrid::kernel::Future kernel_wait_until(double date) { auto promise = std::make_shared>(); auto future = promise->get_future(); - simgrid::simix::Timer::set(date, [promise] { promise->set_value(); }); + simgrid::kernel::timer::Timer::set(date, [promise] { promise->set_value(); }); return future; } diff --git a/tools/cmake/DefinePackages.cmake b/tools/cmake/DefinePackages.cmake index 438f07a496..f36808b192 100644 --- a/tools/cmake/DefinePackages.cmake +++ b/tools/cmake/DefinePackages.cmake @@ -337,6 +337,8 @@ set(SURF_SRC src/kernel/routing/VivaldiZone.cpp src/kernel/routing/WifiZone.cpp + src/kernel/timer/Timer.cpp + src/kernel/EngineImpl.cpp src/kernel/EngineImpl.hpp @@ -686,6 +688,7 @@ set(headers_to_install include/simgrid/forward.h include/simgrid/simix.h include/simgrid/simix.hpp + include/simgrid/kernel/Timer.hpp include/simgrid/kernel/future.hpp include/simgrid/disk.h include/simgrid/host.h