From 9ea179ce187f56df358fc6f69c3e721b330df272 Mon Sep 17 00:00:00 2001 From: Frederic Suter Date: Sun, 26 Mar 2017 12:28:12 +0200 Subject: [PATCH] one more teshsuite convertion a couple extra s4u methods were needed --- include/simgrid/s4u/Actor.hpp | 5 ++ include/simgrid/s4u/host.hpp | 2 + src/s4u/s4u_actor.cpp | 12 ++++- src/s4u/s4u_host.cpp | 14 ++++++ teshsuite/msg/CMakeLists.txt | 4 +- teshsuite/msg/process/process.cpp | 75 ------------------------------ teshsuite/msg/process/process.tesh | 17 ------- teshsuite/s4u/CMakeLists.txt | 6 +-- teshsuite/s4u/actor/actor.cpp | 66 ++++++++++++++++++++++++++ teshsuite/s4u/actor/actor.tesh | 16 +++++++ 10 files changed, 119 insertions(+), 98 deletions(-) delete mode 100644 teshsuite/msg/process/process.cpp delete mode 100644 teshsuite/msg/process/process.tesh create mode 100644 teshsuite/s4u/actor/actor.cpp create mode 100644 teshsuite/s4u/actor/actor.tesh diff --git a/include/simgrid/s4u/Actor.hpp b/include/simgrid/s4u/Actor.hpp index 58e1b4b76e..713127f8d4 100644 --- a/include/simgrid/s4u/Actor.hpp +++ b/include/simgrid/s4u/Actor.hpp @@ -218,6 +218,9 @@ public: /** Resume a suspended process by resuming the task on which it was waiting for the completion. */ void resume(); + /** Returns true if the process is suspended. */ + int isSuspended(); + /** If set to true, the actor will automatically restart when its host reboots */ void setAutoRestart(bool autorestart); @@ -321,6 +324,8 @@ namespace this_actor { /** @brief Resume the actor. */ XBT_PUBLIC(void) resume(); + XBT_PUBLIC(int) isSuspended(); + /** @brief kill the actor. */ XBT_PUBLIC(void) kill(); diff --git a/include/simgrid/s4u/host.hpp b/include/simgrid/s4u/host.hpp index 7af3255fe6..463043e99d 100644 --- a/include/simgrid/s4u/host.hpp +++ b/include/simgrid/s4u/host.hpp @@ -69,6 +69,8 @@ public: simgrid::xbt::string const& name() const { return name_; } const char* cname() { return name_.c_str(); } + void actorList(std::vector * whereto); + /** Turns that host on if it was previously off * * All actors on that host which were marked autorestart will be restarted automatically. diff --git a/src/s4u/s4u_actor.cpp b/src/s4u/s4u_actor.cpp index 4a3141e567..f16cabf607 100644 --- a/src/s4u/s4u_actor.cpp +++ b/src/s4u/s4u_actor.cpp @@ -13,7 +13,7 @@ #include "src/kernel/context/Context.hpp" -XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_actor,"S4U actors"); +XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_actor, "S4U actors"); namespace simgrid { namespace s4u { @@ -97,6 +97,11 @@ void Actor::resume() simcall_process_resume(pimpl_); } +int Actor::isSuspended() +{ + return simcall_process_is_suspended(pimpl_); +} + void Actor::setKillTime(double time) { simcall_process_set_kill_time(pimpl_,time); } @@ -215,6 +220,11 @@ void resume() simcall_process_resume(SIMIX_process_self()); } +int isSuspended() +{ + return simcall_process_is_suspended(SIMIX_process_self()); +} + void kill() { simcall_process_kill(SIMIX_process_self()); diff --git a/src/s4u/s4u_host.cpp b/src/s4u/s4u_host.cpp index 4d74e354f3..6c8a7ecd48 100644 --- a/src/s4u/s4u_host.cpp +++ b/src/s4u/s4u_host.cpp @@ -127,6 +127,20 @@ int Host::pstatesCount() const { return this->pimpl_cpu->getNbPStates(); } +/** + * \brief Return the list of actors attached to an host. + * + * \param whereto a vector in which we should push actors living on that host + */ +void Host::actorList(std::vector* whereto) +{ + smx_actor_t actor = NULL; + xbt_swag_foreach(actor, this->extension()->process_list) + { + whereto->push_back(actor->ciface()); + } +} + /** * \brief Find a route toward another host * diff --git a/teshsuite/msg/CMakeLists.txt b/teshsuite/msg/CMakeLists.txt index eb337340fb..0c1823154b 100644 --- a/teshsuite/msg/CMakeLists.txt +++ b/teshsuite/msg/CMakeLists.txt @@ -10,7 +10,7 @@ foreach(x concurrent_rw get_sender host_on_off host_on_off_recv host_on_off_proc endforeach() # CPP examples -foreach(x process task_destroy_cancel) +foreach(x task_destroy_cancel) add_executable (${x} ${x}/${x}.cpp) target_link_libraries(${x} simgrid) set_target_properties(${x} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${x}) @@ -35,6 +35,6 @@ set(xml_files ${xml_files} ${CMAKE_CURRENT_SOURCE_DIR}/trace_integration ${CMAKE_CURRENT_SOURCE_DIR}/trace_integration/test-hbp2.5-hbp1.5.xml PARENT_SCOPE) foreach(x concurrent_rw get_sender host_on_off host_on_off_processes host_on_off_recv host_on_off_wait listen_async - process storage_client_server task_destroy_cancel trace_integration) + storage_client_server task_destroy_cancel trace_integration) ADD_TESH_FACTORIES(tesh-msg-${x} "thread;boost;ucontext;raw" --setenv srcdir=${CMAKE_HOME_DIRECTORY}/teshsuite/msg/${x} --cd ${CMAKE_BINARY_DIR}/teshsuite/msg/${x} ${CMAKE_HOME_DIRECTORY}/teshsuite/msg/${x}/${x}.tesh) endforeach() diff --git a/teshsuite/msg/process/process.cpp b/teshsuite/msg/process/process.cpp deleted file mode 100644 index bebb77d33f..0000000000 --- a/teshsuite/msg/process/process.cpp +++ /dev/null @@ -1,75 +0,0 @@ -/* Copyright (c) 2010-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/msg.h" - -XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example"); - -static int slave(int argc, char* argv[]) -{ - MSG_process_sleep(.5); - XBT_INFO("Slave started (PID:%d, PPID:%d)", MSG_process_self_PID(), MSG_process_self_PPID()); - while (1) { - XBT_INFO("Plop i am %ssuspended", (MSG_process_is_suspended(MSG_process_self())) ? "" : "not "); - MSG_process_sleep(1); - } - XBT_INFO("I'm done. See you!"); - return 0; -} - -static int master(int argc, char* argv[]) -{ - MSG_process_sleep(1); - xbt_dynar_t process_list = xbt_dynar_new(sizeof(msg_process_t), nullptr); - MSG_host_get_process_list(MSG_host_self(), process_list); - - msg_process_t process = NULL; - unsigned int cursor; - xbt_dynar_foreach (process_list, cursor, process) { - XBT_INFO("Process(pid=%d, ppid=%d, name=%s)", MSG_process_get_PID(process), MSG_process_get_PPID(process), - MSG_process_get_name(process)); - if (MSG_process_self_PID() != MSG_process_get_PID(process)) - MSG_process_kill(process); - } - xbt_dynar_free(&process_list); - - process = MSG_process_create("slave from master", slave, NULL, MSG_host_self()); - MSG_process_sleep(2); - - XBT_INFO("Suspend Process(pid=%d)", MSG_process_get_PID(process)); - MSG_process_suspend(process); - - XBT_INFO("Process(pid=%d) is %ssuspended", MSG_process_get_PID(process), - (MSG_process_is_suspended(process)) ? "" : "not "); - MSG_process_sleep(2); - - XBT_INFO("Resume Process(pid=%d)", MSG_process_get_PID(process)); - MSG_process_resume(process); - - XBT_INFO("Process(pid=%d) is %ssuspended", MSG_process_get_PID(process), - (MSG_process_is_suspended(process)) ? "" : "not "); - MSG_process_sleep(2); - MSG_process_kill(process); - - XBT_INFO("Goodbye now!"); - return 0; -} - -int main(int argc, char* argv[]) -{ - MSG_init(&argc, argv); - xbt_assert(argc == 2, "Usage: %s platform_file\n\t Example: %s msg_platform.xml\n", argv[0], argv[0]); - - MSG_create_environment(argv[1]); - - MSG_process_create("master", master, NULL, MSG_get_host_by_name("Tremblay")); - MSG_process_create("slave", slave, NULL, MSG_get_host_by_name("Tremblay")); - - msg_error_t res = MSG_main(); - - XBT_INFO("Simulation time %g", MSG_get_clock()); - - return res != MSG_OK; -} diff --git a/teshsuite/msg/process/process.tesh b/teshsuite/msg/process/process.tesh deleted file mode 100644 index ddcc6a997a..0000000000 --- a/teshsuite/msg/process/process.tesh +++ /dev/null @@ -1,17 +0,0 @@ - -$ ./process ${srcdir:=.}/../../../examples/platforms/small_platform.xml -> [Tremblay:slave:(2) 0.500000] [msg_test/INFO] Slave started (PID:2, PPID:0) -> [Tremblay:slave:(2) 0.500000] [msg_test/INFO] Plop i am not suspended -> [Tremblay:master:(1) 1.000000] [msg_test/INFO] Process(pid=1, ppid=0, name=master) -> [Tremblay:master:(1) 1.000000] [msg_test/INFO] Process(pid=2, ppid=0, name=slave) -> [Tremblay:slave from master:(3) 1.500000] [msg_test/INFO] Slave started (PID:3, PPID:1) -> [Tremblay:slave from master:(3) 1.500000] [msg_test/INFO] Plop i am not suspended -> [Tremblay:slave from master:(3) 2.500000] [msg_test/INFO] Plop i am not suspended -> [Tremblay:master:(1) 3.000000] [msg_test/INFO] Suspend Process(pid=3) -> [Tremblay:master:(1) 3.000000] [msg_test/INFO] Process(pid=3) is suspended -> [Tremblay:master:(1) 5.000000] [msg_test/INFO] Resume Process(pid=3) -> [Tremblay:master:(1) 5.000000] [msg_test/INFO] Process(pid=3) is not suspended -> [Tremblay:slave from master:(3) 5.000000] [msg_test/INFO] Plop i am not suspended -> [Tremblay:slave from master:(3) 6.000000] [msg_test/INFO] Plop i am not suspended -> [Tremblay:master:(1) 7.000000] [msg_test/INFO] Goodbye now! -> [7.000000] [msg_test/INFO] Simulation time 7 diff --git a/teshsuite/s4u/CMakeLists.txt b/teshsuite/s4u/CMakeLists.txt index 30cbd0bf5b..d2dce9ca90 100644 --- a/teshsuite/s4u/CMakeLists.txt +++ b/teshsuite/s4u/CMakeLists.txt @@ -1,4 +1,4 @@ -foreach(x pid) +foreach(x actor pid) add_executable (${x} ${x}/${x}.cpp) target_link_libraries(${x} simgrid) set_target_properties(${x} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${x}) @@ -11,6 +11,6 @@ set(teshsuite_src ${teshsuite_src} PARENT_SCOPE) set(tesh_files ${tesh_files} PARENT_SCOPE) set(xml_files ${xml_files} PARENT_SCOPE) -foreach(x pid) - ADD_TESH_FACTORIES(tesh-msg-${x} "thread;boost;ucontext;raw" --setenv srcdir=${CMAKE_HOME_DIRECTORY}/teshsuite/s4u/${x} --cd ${CMAKE_BINARY_DIR}/teshsuite/s4u/${x} ${CMAKE_HOME_DIRECTORY}/teshsuite/s4u/${x}/${x}.tesh) +foreach(x actor pid) + ADD_TESH_FACTORIES(tesh-s4u-${x} "thread;boost;ucontext;raw" --setenv srcdir=${CMAKE_HOME_DIRECTORY}/teshsuite/s4u/${x} --cd ${CMAKE_BINARY_DIR}/teshsuite/s4u/${x} ${CMAKE_HOME_DIRECTORY}/teshsuite/s4u/${x}/${x}.tesh) endforeach() diff --git a/teshsuite/s4u/actor/actor.cpp b/teshsuite/s4u/actor/actor.cpp new file mode 100644 index 0000000000..d7a86285ac --- /dev/null +++ b/teshsuite/s4u/actor/actor.cpp @@ -0,0 +1,66 @@ +/* Copyright (c) 2010-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" + +XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example"); + +static void worker() +{ + simgrid::s4u::this_actor::sleep_for(.5); + XBT_INFO("Worker started (PID:%d, PPID:%d)", simgrid::s4u::this_actor::pid(), simgrid::s4u::this_actor::ppid()); + while (1) { + XBT_INFO("Plop i am %ssuspended", simgrid::s4u::this_actor::isSuspended() ? "" : "not "); + simgrid::s4u::this_actor::sleep_for(1); + } + XBT_INFO("I'm done. See you!"); +} + +static void master() +{ + simgrid::s4u::this_actor::sleep_for(1); + std::vector* actor_list = new std::vector(); + simgrid::s4u::this_actor::host()->actorList(actor_list); + + for (auto actor : *actor_list) { + XBT_INFO("Actor (pid=%d, ppid=%d, name=%s)", actor->pid(), actor->ppid(), actor->name().c_str()); + if (simgrid::s4u::this_actor::pid() != actor->pid()) + actor->kill(); + } + + simgrid::s4u::ActorPtr actor = + simgrid::s4u::Actor::createActor("worker from master", simgrid::s4u::this_actor::host(), worker); + simgrid::s4u::this_actor::sleep_for(2); + + XBT_INFO("Suspend Actor (pid=%d)", actor->pid()); + actor->suspend(); + + XBT_INFO("Actor (pid=%d) is %ssuspended", actor->pid(), actor->isSuspended() ? "" : "not "); + simgrid::s4u::this_actor::sleep_for(2); + + XBT_INFO("Resume Actor (pid=%d)", actor->pid()); + actor->resume(); + + XBT_INFO("Actor (pid=%d) is %ssuspended", actor->pid(), actor->isSuspended() ? "" : "not "); + simgrid::s4u::this_actor::sleep_for(2); + actor->kill(); + + delete actor_list; + XBT_INFO("Goodbye now!"); +} + +int main(int argc, char* argv[]) +{ + simgrid::s4u::Engine* e = new simgrid::s4u::Engine(&argc, argv); + e->loadPlatform(argv[1]); + + simgrid::s4u::Actor::createActor("master", simgrid::s4u::Host::by_name("Tremblay"), master); + simgrid::s4u::Actor::createActor("worker", simgrid::s4u::Host::by_name("Tremblay"), worker); + + e->run(); + XBT_INFO("Simulation time %g", e->getClock()); + + return 0; +} diff --git a/teshsuite/s4u/actor/actor.tesh b/teshsuite/s4u/actor/actor.tesh new file mode 100644 index 0000000000..86a6dbccda --- /dev/null +++ b/teshsuite/s4u/actor/actor.tesh @@ -0,0 +1,16 @@ +$ ./actor ${srcdir:=.}/../../../examples/platforms/small_platform.xml +> [Tremblay:worker:(0) 0.500000] [s4u_test/INFO] Worker started (PID:2, PPID:0) +> [Tremblay:worker:(0) 0.500000] [s4u_test/INFO] Plop i am not suspended +> [Tremblay:master:(0) 1.000000] [s4u_test/INFO] Actor (pid=1, ppid=0, name=master) +> [Tremblay:master:(0) 1.000000] [s4u_test/INFO] Actor (pid=2, ppid=0, name=worker) +> [Tremblay:worker from master:(0) 1.500000] [s4u_test/INFO] Worker started (PID:3, PPID:1) +> [Tremblay:worker from master:(0) 1.500000] [s4u_test/INFO] Plop i am not suspended +> [Tremblay:worker from master:(0) 2.500000] [s4u_test/INFO] Plop i am not suspended +> [Tremblay:master:(0) 3.000000] [s4u_test/INFO] Suspend Actor (pid=3) +> [Tremblay:master:(0) 3.000000] [s4u_test/INFO] Actor (pid=3) is suspended +> [Tremblay:master:(0) 5.000000] [s4u_test/INFO] Resume Actor (pid=3) +> [Tremblay:master:(0) 5.000000] [s4u_test/INFO] Actor (pid=3) is not suspended +> [Tremblay:worker from master:(0) 5.000000] [s4u_test/INFO] Plop i am not suspended +> [Tremblay:worker from master:(0) 6.000000] [s4u_test/INFO] Plop i am not suspended +> [Tremblay:master:(0) 7.000000] [s4u_test/INFO] Goodbye now! +> [7.000000] [s4u_test/INFO] Simulation time 7 -- 2.20.1