From: Martin Quinson Date: Thu, 7 Dec 2017 14:09:43 +0000 (+0100) Subject: Merge branch 'master' of scm.gforge.inria.fr:/gitroot/simgrid/simgrid X-Git-Tag: v3.18~113 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/06053662d38a9206e3bbd0f81d710378a65ddb29?hp=1f7c3b764985ce61bc164259f6b15c17599573cd Merge branch 'master' of scm.gforge.inria.fr:/gitroot/simgrid/simgrid --- diff --git a/examples/s4u/CMakeLists.txt b/examples/s4u/CMakeLists.txt index 7ce200058d..eda4aa1361 100644 --- a/examples/s4u/CMakeLists.txt +++ b/examples/s4u/CMakeLists.txt @@ -4,6 +4,7 @@ foreach (example actions-comm actions-storage async-wait async-waitany async-waitall cloud-progress-monitor energy-link energy-pstate energy-ptask energy-vm + execute-priority io-file-system io-file-remote io-storage-raw platform-properties plugin-hostload mutex) add_executable (s4u-${example} ${example}/s4u-${example}.cpp) @@ -71,6 +72,7 @@ foreach(example actions-comm actions-storage cloud-progress-monitor dht-chord energy-link energy-pstate energy-ptask energy-vm + execute-priority platform-properties plugin-hostload mutex io-file-system io-file-remote io-storage-raw) ADD_TESH_FACTORIES(s4u-${example} "thread;ucontext;raw;boost" diff --git a/examples/s4u/execute-priority/s4u-execute-priority.cpp b/examples/s4u/execute-priority/s4u-execute-priority.cpp new file mode 100644 index 0000000000..5813a4e166 --- /dev/null +++ b/examples/s4u/execute-priority/s4u-execute-priority.cpp @@ -0,0 +1,35 @@ +/* Copyright (c) 2007-2017. The SimGrid Team. All rights reserved. */ + +/* This program is free software; you can redistribute it and/or modify it + * under the terms of the license (GNU LGPL) which comes with this package. */ + +#include "simgrid/s4u.hpp" +#include "simgrid/forward.h" +#include "simgrid/s4u/forward.hpp" + +XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example"); + +static void test(double computation_amount, double priority) +{ + XBT_INFO("Hello! Execute %g flops with priority %g", computation_amount, priority); + simgrid::s4u::ExecPtr activity = simgrid::s4u::Actor::self()->exec_init(computation_amount); + activity->setPriority(priority); + activity->start(); + activity->wait(); + + XBT_INFO("Goodbye now!"); +} + +int main(int argc, char* argv[]) +{ + simgrid::s4u::Engine e(&argc, argv); + e.loadPlatform(argv[1]); + simgrid::s4u::Actor::createActor("test", simgrid::s4u::Host::by_name("Fafard"), test, 7.6296e+07, 1.0); + simgrid::s4u::Actor::createActor("test", simgrid::s4u::Host::by_name("Fafard"), test, 7.6296e+07, 2.0); + + e.run(); + + XBT_INFO("Simulation time %g", e.getClock()); + + return 0; +} diff --git a/examples/s4u/execute-priority/s4u-execute-priority.tesh b/examples/s4u/execute-priority/s4u-execute-priority.tesh new file mode 100644 index 0000000000..a0e31be27b --- /dev/null +++ b/examples/s4u/execute-priority/s4u-execute-priority.tesh @@ -0,0 +1,9 @@ +#! ./tesh + +! output sort 19 +$ $SG_TEST_EXENV ${bindir:=.}/s4u-execute-priority$EXEEXT ${platfdir}/small_platform.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" +> [ 0.000000] (1:test@Fafard) Hello! Execute 7.6296e+07 flops with priority 1 +> [ 0.000000] (2:test@Fafard) Hello! Execute 7.6296e+07 flops with priority 2 +> [ 1.500000] (2:test@Fafard) Goodbye now! +> [ 2.000000] (0:maestro@) Simulation time 2 +> [ 2.000000] (1:test@Fafard) Goodbye now! diff --git a/include/simgrid/s4u/Exec.hpp b/include/simgrid/s4u/Exec.hpp index 84b0ea08ac..f24e3a90ab 100644 --- a/include/simgrid/s4u/Exec.hpp +++ b/include/simgrid/s4u/Exec.hpp @@ -6,10 +6,12 @@ #ifndef SIMGRID_S4U_EXEC_HPP #define SIMGRID_S4U_EXEC_HPP -#include "src/kernel/activity/ExecImpl.hpp" #include +#include #include +#include + namespace simgrid { namespace s4u { @@ -17,39 +19,25 @@ XBT_PUBLIC_CLASS Exec : public Activity { Exec() : Activity() {} public: - friend void intrusive_ptr_release(simgrid::s4u::Exec * e) - { - if (e->refcount_.fetch_sub(1, std::memory_order_release) == 1) { - std::atomic_thread_fence(std::memory_order_acquire); - delete e; - } - } - - friend void intrusive_ptr_add_ref(simgrid::s4u::Exec * e) { e->refcount_.fetch_add(1, std::memory_order_relaxed); } - + friend void intrusive_ptr_release(simgrid::s4u::Exec * e); + friend void intrusive_ptr_add_ref(simgrid::s4u::Exec * e); friend Actor; // Factory of Exec ~Exec() = default; - void start() override - { - pimpl_ = simcall_execution_start(nullptr, flops_amount_, 1 / priority_, 0.); - state_ = started; - } - void wait() override { this->wait(-1); } - void wait(double timeout) override { simcall_execution_wait(pimpl_); } + void start() override; + void wait() override; + void wait(double timeout) override; + bool test(); + + ExecPtr setPriority(double priority); - double getRemains() - { - return simgrid::simix::kernelImmediate( - [this]() { return boost::static_pointer_cast(pimpl_)->remains(); }); - } + double getRemains(); private: smx_actor_t runner_ = nullptr; double flops_amount_ = 0.0; double priority_ = 1.0; - double bound_ = 0.0; std::atomic_int_fast32_t refcount_{0}; }; // class diff --git a/src/s4u/s4u_exec.cpp b/src/s4u/s4u_exec.cpp new file mode 100644 index 0000000000..bc78b1ec70 --- /dev/null +++ b/src/s4u/s4u_exec.cpp @@ -0,0 +1,72 @@ +/* Copyright (c) 2006-2017. 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 "xbt/log.h" + +#include "simgrid/s4u/Actor.hpp" +#include "simgrid/s4u/Exec.hpp" +#include "src/kernel/activity/ExecImpl.hpp" + +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(s4u_exec, s4u_activity, "S4U asynchronous executions"); + +namespace simgrid { +namespace s4u { + +void Exec::start() +{ + pimpl_ = simcall_execution_start(nullptr, flops_amount_, 1 / priority_, 0.); + state_ = started; +} + +void Exec::wait() +{ + this->wait(-1); +} + +void Exec::wait(double timeout) +{ + simcall_execution_wait(pimpl_); +} + +bool Exec::test() +{ + xbt_assert(state_ == inited || state_ == started || state_ == finished); + + if (state_ == finished) { + return true; + } + + if (state_ == inited) { + this->start(); + } + + return false; +} + +ExecPtr Exec::setPriority(double priority) +{ + priority_ = priority; + return this; +} + +double Exec::getRemains() +{ + return simgrid::simix::kernelImmediate( + [this]() { return boost::static_pointer_cast(pimpl_)->remains(); }); +} + +void intrusive_ptr_release(simgrid::s4u::Exec* e) +{ + if (e->refcount_.fetch_sub(1, std::memory_order_release) == 1) { + std::atomic_thread_fence(std::memory_order_acquire); + delete e; + } +} + +void intrusive_ptr_add_ref(simgrid::s4u::Exec* e) +{ + e->refcount_.fetch_add(1, std::memory_order_relaxed); +} +} +} diff --git a/tools/cmake/DefinePackages.cmake b/tools/cmake/DefinePackages.cmake index 5a2b006f60..38517be840 100644 --- a/tools/cmake/DefinePackages.cmake +++ b/tools/cmake/DefinePackages.cmake @@ -427,7 +427,8 @@ set(S4U_SRC src/s4u/s4u_conditionVariable.cpp src/s4u/s4u_comm.cpp src/s4u/s4u_engine.cpp - src/s4u/s4u_host.cpp + src/s4u/s4u_exec.cpp + src/s4u/s4u_host.cpp src/s4u/s4u_link.cpp src/s4u/s4u_mailbox.cpp src/s4u/s4u_mutex.cpp