From 18b9c05d4b0ad3302e1013aef59861418df7a404 Mon Sep 17 00:00:00 2001 From: Frederic Suter Date: Sun, 3 Feb 2019 15:18:50 +0100 Subject: [PATCH] modernize a few simcall_execution_* calls --- include/simgrid/s4u/Activity.hpp | 2 + include/simgrid/simix.h | 5 -- src/kernel/activity/ExecImpl.cpp | 1 - src/kernel/activity/ExecImpl.hpp | 1 + src/msg/msg_gos.cpp | 15 ++++-- src/msg/msg_task.cpp | 8 ++-- src/simix/libsmx.cpp | 80 -------------------------------- 7 files changed, 20 insertions(+), 92 deletions(-) diff --git a/include/simgrid/s4u/Activity.hpp b/include/simgrid/s4u/Activity.hpp index f9af5aca21..d8b4a681aa 100644 --- a/include/simgrid/s4u/Activity.hpp +++ b/include/simgrid/s4u/Activity.hpp @@ -90,6 +90,8 @@ public: /** Retrieve the user data of the Activity */ void* get_user_data() { return user_data_; } + simgrid::kernel::activity::ActivityImplPtr get_impl() { return pimpl_; } + #ifndef DOXYGEN XBT_ATTRIB_DEPRECATED_v324("Please use Activity::wait_for()") virtual void wait(double timeout) = 0; XBT_ATTRIB_DEPRECATED_v323("Please use Activity::get_state()") Activity::State getState() { return state_; } diff --git a/include/simgrid/simix.h b/include/simgrid/simix.h index 3f1bb78ff1..c0daa91530 100644 --- a/include/simgrid/simix.h +++ b/include/simgrid/simix.h @@ -180,15 +180,10 @@ XBT_PUBLIC void SIMIX_comm_finish(smx_activity_t synchro); /******************************* Host simcalls ********************************/ #ifdef __cplusplus -XBT_PUBLIC smx_activity_t simcall_execution_start(std::string name, std::string category, double flops_amount, - double priority, double bound, sg_host_t host); XBT_PUBLIC smx_activity_t simcall_execution_parallel_start(std::string name, int host_nb, sg_host_t* host_list, double* flops_amount, double* bytes_amount, double rate, double timeout); #endif -XBT_PUBLIC void simcall_execution_cancel(smx_activity_t execution); -XBT_PUBLIC void simcall_execution_set_priority(smx_activity_t execution, double priority); -XBT_PUBLIC void simcall_execution_set_bound(smx_activity_t execution, double bound); XBT_PUBLIC e_smx_state_t simcall_execution_wait(smx_activity_t execution); XBT_PUBLIC e_smx_state_t simcall_execution_test(smx_activity_t execution); diff --git a/src/kernel/activity/ExecImpl.cpp b/src/kernel/activity/ExecImpl.cpp index 3cd26b0bbb..8e5fd996f0 100644 --- a/src/kernel/activity/ExecImpl.cpp +++ b/src/kernel/activity/ExecImpl.cpp @@ -78,7 +78,6 @@ double simgrid::kernel::activity::ExecImpl::get_remaining() xbt_assert(host_ != nullptr, "Calling remains() on a parallel execution is not allowed. " "We would need to return a vector instead of a scalar. " "Did you mean remainingRatio() instead?"); - return surf_action_ ? surf_action_->get_remains() : 0; } diff --git a/src/kernel/activity/ExecImpl.hpp b/src/kernel/activity/ExecImpl.hpp index 6ea0231356..4ed1ab7e76 100644 --- a/src/kernel/activity/ExecImpl.hpp +++ b/src/kernel/activity/ExecImpl.hpp @@ -33,6 +33,7 @@ public: /* The host where the execution takes place. nullptr means this is a parallel exec (and only surf knows the hosts) */ s4u::Host* host_ = nullptr; + private: resource::Action* timeout_detector_ = nullptr; diff --git a/src/msg/msg_gos.cpp b/src/msg/msg_gos.cpp index 422ba8d58a..10e43af200 100644 --- a/src/msg/msg_gos.cpp +++ b/src/msg/msg_gos.cpp @@ -4,6 +4,7 @@ * under the terms of the license (GNU LGPL) which comes with this package. */ #include "simgrid/Exception.hpp" +#include #include "simgrid/s4u/Mailbox.hpp" #include "src/instr/instr_private.hpp" @@ -68,9 +69,17 @@ msg_error_t MSG_parallel_task_execute_with_timeout(msg_task_t task, double timeo if (task->category != nullptr) simcall_set_category(simdata->compute, task->category); } else { - simdata->compute = boost::static_pointer_cast( - simcall_execution_start(task->name ?: "", task->category ?: "", simdata->flops_amount, simdata->priority, - simdata->bound, MSG_process_get_host(MSG_process_self()))); + sg_host_t host = MSG_process_get_host(MSG_process_self()); + simdata->compute = simgrid::simix::simcall([task, host] { + return simgrid::kernel::activity::ExecImplPtr( + new simgrid::kernel::activity::ExecImpl(task->name ?: "", task->category ?: "", + /*timeout_detector*/ nullptr, host)); + }); + /* checking for infinite values */ + xbt_assert(std::isfinite(simdata->flops_amount), "flops_amount is not finite!"); + xbt_assert(std::isfinite(simdata->priority), "priority is not finite!"); + + simdata->compute->start(simdata->flops_amount, simdata->priority, simdata->bound); } comp_state = simcall_execution_wait(simdata->compute); diff --git a/src/msg/msg_task.cpp b/src/msg/msg_task.cpp index 14b3ce6201..bf8de7e43c 100644 --- a/src/msg/msg_task.cpp +++ b/src/msg/msg_task.cpp @@ -6,6 +6,7 @@ #include "msg_private.hpp" #include "src/simix/smx_private.hpp" #include +#include XBT_LOG_NEW_DEFAULT_SUBCATEGORY(msg_task, msg, "Logging specific to MSG (task)"); @@ -186,7 +187,7 @@ msg_error_t MSG_task_cancel(msg_task_t task) simdata_task_t simdata = task->simdata; if (simdata->compute) { - simcall_execution_cancel(simdata->compute); + simgrid::simix::simcall([simdata] { simdata->compute->cancel(); }); } else if (simdata->comm) { simcall_comm_cancel(simdata->comm); } @@ -275,8 +276,9 @@ double MSG_task_get_bytes_amount(msg_task_t task) void MSG_task_set_priority(msg_task_t task, double priority) { task->simdata->priority = 1 / priority; + xbt_assert(std::isfinite(task->simdata->priority), "priority is not finite!"); if (task->simdata->compute) - simcall_execution_set_priority(task->simdata->compute, task->simdata->priority); + simgrid::simix::simcall([task] { task->simdata->compute->set_priority(task->simdata->priority); }); } /** @brief Changes the maximum CPU utilization of a computation task (in flops/s). @@ -290,5 +292,5 @@ void MSG_task_set_bound(msg_task_t task, double bound) task->simdata->bound = bound; if (task->simdata->compute) - simcall_execution_set_bound(task->simdata->compute, task->simdata->bound); + simgrid::simix::simcall([task, bound] { task->simdata->compute->set_bound(bound); }); } diff --git a/src/simix/libsmx.cpp b/src/simix/libsmx.cpp index 7269508cc9..4907a9521e 100644 --- a/src/simix/libsmx.cpp +++ b/src/simix/libsmx.cpp @@ -26,33 +26,6 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix); #include "popping_bodies.cpp" -/** - * @ingroup simix_process_management - * @brief Creates a synchro that executes some computation of a host. - * - * This function creates a SURF action and allocates the data necessary - * to create the SIMIX synchro. It can raise a HostFailureException exception if the host crashed. - * - * @param name Name of the execution synchro to create - * @param category Tracing category - * @param flops_amount amount Computation amount (in flops) - * @param priority computation priority - * @param bound Maximal speed for this execution (in flops) or -1 if no limit - * @param host host where the synchro will be executed - * @return A new SIMIX execution synchronization - */ -smx_activity_t simcall_execution_start(std::string name, std::string category, double flops_amount, double priority, - double bound, simgrid::s4u::Host* host) -{ - /* checking for infinite values */ - xbt_assert(std::isfinite(flops_amount), "flops_amount is not finite!"); - xbt_assert(std::isfinite(priority), "priority is not finite!"); - - return simgrid::simix::simcall([name, category, flops_amount, priority, bound, host] { - return SIMIX_execution_start(name, category, flops_amount, priority, bound, host); - }); -} - /** * @ingroup simix_process_management * @brief Creates a synchro that may involve parallel computation on @@ -90,59 +63,6 @@ smx_activity_t simcall_execution_parallel_start(std::string name, int host_nb, s }); } -/** - * @ingroup simix_process_management - * @brief Cancels an execution synchro. - * - * This functions stops the execution. It calls a surf function. - * @param execution The execution synchro to cancel - */ -void simcall_execution_cancel(smx_activity_t execution) -{ - simgrid::kernel::activity::ExecImplPtr exec = - boost::static_pointer_cast(execution); - if (exec->surf_action_ == nullptr) // FIXME: One test fails if I remove this, but I don't get why... - return; - simgrid::simix::simcall([exec] { exec->cancel(); }); -} - -/** - * @ingroup simix_process_management - * @brief Changes the priority of an execution synchro. - * - * This functions changes the priority only. It calls a surf function. - * @param execution The execution synchro - * @param priority The new priority - */ -void simcall_execution_set_priority(smx_activity_t execution, double priority) -{ - /* checking for infinite values */ - xbt_assert(std::isfinite(priority), "priority is not finite!"); - simgrid::simix::simcall([execution, priority] { - - simgrid::kernel::activity::ExecImplPtr exec = - boost::static_pointer_cast(execution); - exec->set_priority(priority); - }); -} - -/** - * @ingroup simix_process_management - * @brief Changes the capping (the maximum CPU utilization) of an execution synchro. - * - * This functions changes the capping only. It calls a surf function. - * @param execution The execution synchro - * @param bound The new bound - */ -void simcall_execution_set_bound(smx_activity_t execution, double bound) -{ - simgrid::simix::simcall([execution, bound] { - simgrid::kernel::activity::ExecImplPtr exec = - boost::static_pointer_cast(execution); - exec->set_bound(bound); - }); -} - /** * @ingroup simix_host_management * @brief Waits for the completion of an execution synchro and destroy it. -- 2.20.1