From f228565bee80306220bf1eb2ecda74c81c981c38 Mon Sep 17 00:00:00 2001 From: Frederic Suter Date: Tue, 21 Mar 2017 09:40:41 +0100 Subject: [PATCH] add suspend/resume to S4U update the actor-migration example to perfectly match the process-migration example in C/MSG --- .../actor-migration/s4u_actor-migration.cpp | 6 +++--- .../actor-migration/s4u_actor-migration.tesh | 6 +++--- include/simgrid/s4u/Actor.hpp | 13 ++++++++++++ src/s4u/s4u_actor.cpp | 20 +++++++++++++++++++ 4 files changed, 39 insertions(+), 6 deletions(-) diff --git a/examples/s4u/actor-migration/s4u_actor-migration.cpp b/examples/s4u/actor-migration/s4u_actor-migration.cpp index c5ecf5fb8a..5db96c6313 100644 --- a/examples/s4u/actor-migration/s4u_actor-migration.cpp +++ b/examples/s4u/actor-migration/s4u_actor-migration.cpp @@ -34,8 +34,8 @@ static void emigrant() identification->notify_all(); checkpoint->unlock(); - // TODO simgrid::s4u::this_actor::suspend(); to replace the sleep below - simgrid::s4u::this_actor::sleep_for(4); + simgrid::s4u::this_actor::suspend(); + XBT_INFO("I've been moved on this new host: %s", simgrid::s4u::this_actor::host()->cname()); XBT_INFO("Uh, nothing to do here. Stopping now"); } @@ -51,7 +51,7 @@ static void policeman() controlled_process->migrate(simgrid::s4u::Host::by_name("Jacquelin")); /* - Move an emigrant to Jacquelin */ XBT_INFO("I moved the emigrant"); - // TODO simgrid::s4u::this_actor::resume() + controlled_process->resume(); checkpoint->unlock(); } diff --git a/examples/s4u/actor-migration/s4u_actor-migration.tesh b/examples/s4u/actor-migration/s4u_actor-migration.tesh index ef6fad7096..19b9f973df 100644 --- a/examples/s4u/actor-migration/s4u_actor-migration.tesh +++ b/examples/s4u/actor-migration/s4u_actor-migration.tesh @@ -8,7 +8,7 @@ $ $SG_TEST_EXENV ${bindir:=.}/s4u_actor-migration ${srcdir:=.}/small_platform.xm > [ 0.000000] (emigrant@Boivin) Yeah, found something to do > [ 0.000000] (policeman@Boivin) Wait at the checkpoint. > [ 3.000000] (emigrant@Boivin) Moving back home after work +> [ 7.000000] (maestro@) Simulation time 7 +> [ 7.000000] (emigrant@Jacquelin) I've been moved on this new host: Jacquelin +> [ 7.000000] (emigrant@Jacquelin) Uh, nothing to do here. Stopping now > [ 7.000000] (policeman@Boivin) I moved the emigrant -> [ 11.000000] (emigrant@Jacquelin) I've been moved on this new host: Jacquelin -> [ 11.000000] (emigrant@Jacquelin) Uh, nothing to do here. Stopping now -> [ 11.000000] (maestro@) Simulation time 11 diff --git a/include/simgrid/s4u/Actor.hpp b/include/simgrid/s4u/Actor.hpp index 016799a33a..9e34530c07 100644 --- a/include/simgrid/s4u/Actor.hpp +++ b/include/simgrid/s4u/Actor.hpp @@ -212,6 +212,12 @@ public: /** Retrieves the PPID of that actor */ int ppid(); + /** Suspend an actor by suspending the task on which it was waiting for the completion. */ + void suspend(); + + /** Resume a suspended process by resuming the task on which it was waiting for the completion. */ + void resume(); + /** If set to true, the actor will automatically restart when its host reboots */ void setAutoRestart(bool autorestart); /** Sets the time at which that actor should be killed */ @@ -302,6 +308,13 @@ namespace this_actor { /** @brief Returns the name of the host on which the process is running. */ XBT_PUBLIC(Host*) host(); + /** @brief Suspend the actor. */ + XBT_PUBLIC(void) suspend(); + + /** @brief Resume the actor. */ + XBT_PUBLIC(void) resume(); + + /** @brief Migrate the actor to a new host. */ XBT_PUBLIC(void) migrate(Host* new_host); }; diff --git a/src/s4u/s4u_actor.cpp b/src/s4u/s4u_actor.cpp index 97d7ec1f32..16479c08ca 100644 --- a/src/s4u/s4u_actor.cpp +++ b/src/s4u/s4u_actor.cpp @@ -82,6 +82,16 @@ int Actor::ppid() return this->pimpl_->ppid; } +void Actor::suspend() +{ + simcall_process_suspend(pimpl_); +} + +void Actor::resume() +{ + simcall_process_resume(pimpl_); +} + void Actor::setKillTime(double time) { simcall_process_set_kill_time(pimpl_,time); } @@ -184,6 +194,16 @@ Host* host() return SIMIX_process_self()->host; } +void suspend() +{ + simcall_process_suspend(SIMIX_process_self()); +} + +void resume() +{ + simcall_process_resume(SIMIX_process_self()); +} + void migrate(Host* new_host) { simcall_process_set_host(SIMIX_process_self(), new_host); -- 2.20.1