Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' into actor-yield
authorZitagcc <toufik.boubehziz@inria.fr>
Thu, 23 Nov 2017 09:27:06 +0000 (10:27 +0100)
committerGitHub <noreply@github.com>
Thu, 23 Nov 2017 09:27:06 +0000 (10:27 +0100)
examples/s4u/CMakeLists.txt
examples/s4u/README.doc
examples/s4u/actor-yield/s4u-actor-yield.cpp [new file with mode: 0644]
examples/s4u/actor-yield/s4u-actor-yield.tesh [new file with mode: 0644]
examples/s4u/actor-yield/s4u-actor-yield_d.xml [new file with mode: 0644]
include/simgrid/s4u/Actor.hpp
src/s4u/s4u_actor.cpp

index 5b88ee4..3e90de1 100644 (file)
@@ -1,7 +1,7 @@
 foreach (example actions-comm actions-storage 
                  actor-create actor-daemon actor-execute actor-kill actor-lifetime actor-migration actor-suspend actor-priority
                  app-masterworker app-pingpong app-token-ring
-                async-wait async-waitany async-waitall
+                async-wait async-waitany async-waitall actor-yield
                 energy-link
                 plugin-hostload io mutex)
   add_executable       (s4u-${example}  ${example}/s4u-${example}.cpp)
@@ -33,6 +33,7 @@ endforeach()
 set(examples_src  ${examples_src}                                                                          PARENT_SCOPE)
 set(tesh_files    ${tesh_files}   ${CMAKE_CURRENT_SOURCE_DIR}/app-bittorrent/s4u-app-bittorrent.tesh
                                   ${CMAKE_CURRENT_SOURCE_DIR}/dht-chord/s4u-dht-chord.tesh
+                                  ${CMAKE_CURRENT_SOURCE_DIR}/actor-yield/s4u-actor-yield.tesh
                                   ${CMAKE_CURRENT_SOURCE_DIR}/actor-priority/s4u-actor-priority.tesh
                                   ${CMAKE_CURRENT_SOURCE_DIR}/actor-lifetime/s4u-actor-lifetime.tesh
                                   ${CMAKE_CURRENT_SOURCE_DIR}/async-wait/s4u-async-wait.tesh
@@ -50,6 +51,7 @@ set(xml_files     ${xml_files}    ${CMAKE_CURRENT_SOURCE_DIR}/actions-comm/s4u-a
                                   ${CMAKE_CURRENT_SOURCE_DIR}/async-waitany/s4u-async-waitany_d.xml
                                   ${CMAKE_CURRENT_SOURCE_DIR}/async-waitall/s4u-async-waitall_d.xml
                                   ${CMAKE_CURRENT_SOURCE_DIR}/async-wait/s4u-async-wait_d.xml
+                                  ${CMAKE_CURRENT_SOURCE_DIR}/actor-yield/s4u-actor-yield_d.xml
                                   ${CMAKE_CURRENT_SOURCE_DIR}/dht-chord/s4u-dht-chord_d.xml
                                   ${CMAKE_CURRENT_SOURCE_DIR}/actor-lifetime/s4u-actor-lifetime_d.xml
                  PARENT_SCOPE)
@@ -62,7 +64,7 @@ set(txt_files     ${txt_files}    ${CMAKE_CURRENT_SOURCE_DIR}/actions-comm/s4u-a
 foreach(example actions-comm actions-storage 
                 actor-create actor-daemon actor-execute actor-kill actor-lifetime actor-migration actor-suspend
                 app-bittorrent app-masterworker app-pingpong app-token-ring 
-               async-wait async-waitall async-waitany actor-priority
+               async-wait async-waitall async-waitany actor-priority actor-yield
                dht-chord 
                energy-link
                plugin-hostload io mutex)
index 78254fb..f626d7e 100644 (file)
@@ -101,6 +101,12 @@ documentation, but it should remain readable directly.
     @ref examples/s4u/actor-migration/s4u-actor-migration.cpp \n
     Actors can move or be moved from a host to another with the @ref migrate method.
 
+  - <b>Yielding to other actor</b>.
+    @ref examples/s4u/actor-yield/s4u-actor-yield.c\n
+    The @ref yield function interrupts the execution of the
+    current actor, leaving a chance to run to the other actor
+    that are ready to run at the exact same timestamp
+
 @section s4u_ex_synchro Inter-Actor Synchronization 
 
  - <b>Mutex: </b> @ref examples/s4u/mutex/s4u-mutex.cpp \n
diff --git a/examples/s4u/actor-yield/s4u-actor-yield.cpp b/examples/s4u/actor-yield/s4u-actor-yield.cpp
new file mode 100644 (file)
index 0000000..f554233
--- /dev/null
@@ -0,0 +1,54 @@
+/* Copyright (c) 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 "src/simix/ActorImpl.hpp"
+#include "src/simix/smx_private.h"
+#include <string>
+
+/* This example does not much: It just spans over-polite actor that yield a large amount
+* of time before ending.
+*
+* This serves as an example for the s4u-actor-yield() function, with which an actor can request
+* to be rescheduled after the other actor that are ready at the current timestamp.
+*
+* It can also be used to benchmark our context-switching mechanism.
+*/
+XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_actor_yield, "Messages specific for this s4u example");
+/* Main function of the Yielder process */
+class yielder {
+ long number_of_yields;
+public: 
+ explicit yielder() = default;
+ explicit yielder(std::vector<std::string> args)
+{ 
+ number_of_yields = std::stod(args[1]);
+}
+void operator()()
+{
+ for (int i = 0; i < number_of_yields; i++)
+ simgrid::s4u::this_actor::yield();
+ XBT_INFO("I yielded %ld times. Goodbye now!", number_of_yields);
+}
+};
+
+int main(int argc, char* argv[])
+{
+ simgrid::s4u::Engine e(&argc, argv);
+ xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n"
+ "\tExample: %s platform.xml deployment.xml\n",
+ argv[0], argv[0]);
+ e.loadPlatform(argv[1]);  /* - Load the platform description */
+ e.registerFunction<yielder>("yielder");
+ std::vector<std::string> args; 
+
+ e.loadDeployment(argv[2]);
+
+ e.run();  /* - Run the simulation */
+
+ return 0;
+}
diff --git a/examples/s4u/actor-yield/s4u-actor-yield.tesh b/examples/s4u/actor-yield/s4u-actor-yield.tesh
new file mode 100644 (file)
index 0000000..938470d
--- /dev/null
@@ -0,0 +1,5 @@
+#! ./tesh
+
+$ $SG_TEST_EXENV ${bindir:=.}/s4u-actor-yield ${srcdir:=.}/small_platform_fatpipe.xml ${srcdir:=.}/../s4u/actor-yield/s4u-actor-yield_d.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n"
+> [  0.000000] (1:yielder@Tremblay) I yielded 10 times. Goodbye now!
+> [  0.000000] (2:yielder@Ruby) I yielded 15 times. Goodbye now!
diff --git a/examples/s4u/actor-yield/s4u-actor-yield_d.xml b/examples/s4u/actor-yield/s4u-actor-yield_d.xml
new file mode 100644 (file)
index 0000000..b1ab776
--- /dev/null
@@ -0,0 +1,10 @@
+<?xml version='1.0'?>
+<!DOCTYPE platform SYSTEM "http://simgrid.gforge.inria.fr/simgrid/simgrid.dtd">
+<platform version="4.1">
+  <actor host="Tremblay" function="yielder">
+    <argument value="10"/>       <!-- Number of yields to do  -->
+  </actor>
+  <actor host="Ruby" function="yielder">
+    <argument value="15"/>       <!-- Number of yields to do  -->
+  </actor>
+</platform>
index e9cdd87..92fc485 100644 (file)
@@ -217,7 +217,9 @@ public:
 
   /** Resume a suspended actor by resuming the task on which it was waiting for the completion. */
   void resume();
-
+  
+  void yield();
+  
   /** Returns true if the actor is suspended. */
   int isSuspended();
 
@@ -347,6 +349,9 @@ XBT_PUBLIC(Host*) getHost();
 /** @brief Suspend the actor. */
 XBT_PUBLIC(void) suspend();
 
+/** @brief yield the actor. */
+XBT_PUBLIC(void) yield();
+
 /** @brief Resume the actor. */
 XBT_PUBLIC(void) resume();
 
index 1553bb9..86ea2e2 100644 (file)
@@ -214,6 +214,11 @@ void sleep_for(double duration)
     simcall_process_sleep(duration);
 }
 
+void yield()
+{
+  simgrid::simix::kernelImmediate([] { /* do nothing*/ });
+}
+
 XBT_PUBLIC(void) sleep_until(double timeout)
 {
   double now = SIMIX_get_clock();