Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
implement the DVFS functions in Java
authorMartin Quinson <martin.quinson@loria.fr>
Thu, 19 Jan 2017 14:15:51 +0000 (15:15 +0100)
committerMartin Quinson <martin.quinson@loria.fr>
Thu, 19 Jan 2017 14:15:51 +0000 (15:15 +0100)
.gitignore
examples/java/CMakeLists.txt
examples/java/energy/pstate/Main.java [new file with mode: 0644]
examples/java/energy/pstate/PstateRunner.java [new file with mode: 0644]
examples/java/energy/pstate/energy_pstate.tesh [new file with mode: 0644]
examples/msg/energy-pstate/energy-pstate.c
src/bindings/java/jmsg_host.cpp
src/bindings/java/jmsg_host.h
src/bindings/java/org/simgrid/msg/Host.java

index a8850ff..477d17a 100644 (file)
@@ -981,6 +981,7 @@ examples/java/dht/kademlia/java_dht_kademlia_compiled
 examples/java/cloud/masterworker/java_cloud_masterworker_compiled
 examples/java/cloud/migration/java_cloud_migration_compiled
 examples/java/energy/consumption/java_energy_consumption_compiled
+examples/java/energy/pstate/java_energy_pstate_compiled
 examples/java/energy/vm/java_energy_vm_compiled
 examples/java/io/file/java_io_file_compiled
 examples/java/io/storage/java_io_storage_compiled
index b246cbf..4b73e94 100644 (file)
@@ -49,6 +49,9 @@ set(trace_pingpong_sources     ${srcdir}/Main.java  ${srcdir}/PingPongTask.java
 set (srcdir ${CMAKE_CURRENT_SOURCE_DIR}/energy/consumption)
 set(energy_consumption_sources ${srcdir}/Main.java  ${srcdir}/EnergyConsumer.java)
 
+set (srcdir ${CMAKE_CURRENT_SOURCE_DIR}/energy/pstate)
+set(energy_pstate_sources      ${srcdir}/Main.java  ${srcdir}/PstateRunner.java)
+
 set (srcdir ${CMAKE_CURRENT_SOURCE_DIR}/energy/vm)
 set(energy_vm_sources          ${srcdir}/Main.java  ${srcdir}/EnergyVMRunner.java)
 
@@ -74,7 +77,7 @@ set (srcdir ${CMAKE_CURRENT_SOURCE_DIR}/task/priority)
 set(task_priority_sources      ${srcdir}/Main.java  ${srcdir}/Test.java)
 
 foreach (example app_bittorrent app_centralizedmutex app_masterworker app_pingpong app_tokenring async_waitall async_dsend
-         cloud_migration cloud_masterworker dht_chord dht_kademlia energy_consumption energy_vm io_file io_storage 
+         cloud_migration cloud_masterworker dht_chord dht_kademlia energy_consumption energy_pstate energy_vm io_file io_storage 
          process_kill process_migration process_startkilltime process_suspend task_priority trace_pingpong)
   string (REPLACE "_" "/" example_dir ${example})
   if(enable_java)
@@ -108,10 +111,9 @@ set(xml_files     ${xml_files}     ${CMAKE_CURRENT_SOURCE_DIR}/app/bittorrent/bi
 
 if(enable_java)
   foreach (example app_bittorrent app_centralizedmutex app_masterworker app_pingpong app_tokenring async_waitall async_dsend
-           cloud_migration cloud_masterworker dht_chord dht_kademlia energy_consumption energy_vm io_file io_storage 
+           cloud_migration cloud_masterworker dht_chord dht_kademlia energy_consumption energy_pstate energy_vm io_file io_storage 
            process_kill process_migration process_startkilltime process_suspend task_priority trace_pingpong)
     string (REPLACE "_" "/" example_dir ${example})
-    ADD_TESH(java-${example}  --setenv
-srcdir=${CMAKE_HOME_DIRECTORY}/examples/java --setenv LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/lib --setenv classpath=${TESH_CLASSPATH} --cd ${CMAKE_BINARY_DIR}/examples/java ${CMAKE_HOME_DIRECTORY}/examples/java/${example_dir}/${example}.tesh)
+    ADD_TESH(java-${example}  --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/java --setenv LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/lib --setenv classpath=${TESH_CLASSPATH} --cd ${CMAKE_BINARY_DIR}/examples/java ${CMAKE_HOME_DIRECTORY}/examples/java/${example_dir}/${example}.tesh)
   endforeach()
 endif()
diff --git a/examples/java/energy/pstate/Main.java b/examples/java/energy/pstate/Main.java
new file mode 100644 (file)
index 0000000..aa364a6
--- /dev/null
@@ -0,0 +1,35 @@
+/* Copyright (c) 2016. 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. */
+
+package energy.pstate;
+
+import org.simgrid.msg.Msg;
+import org.simgrid.msg.Host;
+import org.simgrid.msg.HostNotFoundException;
+import org.simgrid.msg.NativeException;
+
+class Main {
+  private Main() {
+    throw new IllegalAccessError("Utility class");
+  }
+
+  public static void main(String[] args) throws NativeException, HostNotFoundException {
+    Msg.energyInit();
+    Msg.init(args);
+
+    if (args.length < 1) {
+      Msg.info("Usage: Main ../platforms/energy_platform_file.xml");
+      System.exit(1);
+    }
+
+    /* construct the platform */
+    Msg.createEnvironment(args[0]);
+
+    /* Create and start a runner for the experiment */
+    new PstateRunner(Host.all()[0],"pstate runner",null).start();
+
+    Msg.run();
+  }
+}
diff --git a/examples/java/energy/pstate/PstateRunner.java b/examples/java/energy/pstate/PstateRunner.java
new file mode 100644 (file)
index 0000000..7319c3a
--- /dev/null
@@ -0,0 +1,86 @@
+/* Copyright (c) 2016. 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. */
+
+package energy.pstate;
+
+import org.simgrid.msg.Host;
+import org.simgrid.msg.HostFailureException;
+import org.simgrid.msg.HostNotFoundException;
+import org.simgrid.msg.Msg;
+import org.simgrid.msg.NativeException;
+import org.simgrid.msg.Process;
+import org.simgrid.msg.Task;
+import org.simgrid.msg.TaskCancelledException;
+
+/* This class is a process in charge of running the test. It creates and starts the VMs, and fork processes within VMs */
+public class PstateRunner extends Process {
+
+       public class DVFS extends Process {
+               public  DVFS (Host host, String name) {
+                       super(host, name); 
+               }
+
+               @Override
+               public void main(String[] strings) throws HostNotFoundException, HostFailureException, TaskCancelledException {
+                       double workload = 100E6;
+                       int new_peak_index=2;
+                       Host host = getHost();
+
+                       int nb = host.getPstatesCount();
+                       Msg.info("Count of Processor states="+ nb);
+
+                       double current_peak = host.getCurrentPowerPeak();
+                       Msg.info("Current power peak=" + current_peak);
+
+                       // Run a task
+                       Task task1 = new Task("t1", workload, 0);
+                       task1.execute();
+
+                       double task_time = Msg.getClock();
+                       Msg.info("Task1 simulation time: "+ task_time);
+
+                       // Change power peak
+                       if ((new_peak_index >= nb) || (new_peak_index < 0)){
+                               Msg.info("Cannot set pstate "+new_peak_index+"%d, host supports only "+nb+" pstates.");
+                               return;
+                       }
+
+                       double peak_at = host.getPowerPeakAt(new_peak_index);
+                       Msg.info("Changing power peak value to "+peak_at+" (at index "+new_peak_index+")");
+
+                       host.setPstate(new_peak_index);
+
+                       current_peak = host.getCurrentPowerPeak();
+                       Msg.info("Current power peak="+ current_peak);
+
+                       // Run a second task
+                       task1 = new Task("t1", workload, 0);
+
+                       task_time = Msg.getClock() - task_time;
+                       Msg.info("Task2 simulation time: "+ task_time);
+
+                       // Verify the default pstate is set to 0
+                       host = Host.getByName("MyHost2");
+                       int nb2 = host.getPstatesCount();
+                       Msg.info("Count of Processor states="+ nb2);
+
+                       double current_peak2 = host.getCurrentPowerPeak();
+                       Msg.info("Current power peak=" + current_peak2);
+                       return ;
+               }
+       }
+
+       PstateRunner(Host host, String name, String[] args) throws HostNotFoundException, NativeException  {
+               super(host, name, args);
+       }
+
+       @Override
+       public void main(String[] strings) throws HostNotFoundException, HostFailureException {
+
+           new DVFS (Host.getByName("MyHost1"), "dvfs_test").start(); 
+           new DVFS (Host.getByName("MyHost2"), "dvfs_test").start(); 
+
+       }
+}
diff --git a/examples/java/energy/pstate/energy_pstate.tesh b/examples/java/energy/pstate/energy_pstate.tesh
new file mode 100644 (file)
index 0000000..09bf104
--- /dev/null
@@ -0,0 +1,24 @@
+#! tesh
+
+$ java -classpath ${classpath:=.} energy/pstate/Main ${srcdir:=.}/../platforms/energy_platform.xml
+> [0.000000] [jmsg/INFO] Using regular java threads.
+> [MyHost1:dvfs_test:(2) 0.000000] [jmsg/INFO] Count of Processor states=3
+> [MyHost1:dvfs_test:(2) 0.000000] [jmsg/INFO] Current power peak=1.0E8
+> [MyHost2:dvfs_test:(3) 0.000000] [jmsg/INFO] Count of Processor states=3
+> [MyHost2:dvfs_test:(3) 0.000000] [jmsg/INFO] Current power peak=1.0E8
+> [MyHost1:dvfs_test:(2) 1.000000] [jmsg/INFO] Task1 simulation time: 1.0
+> [MyHost2:dvfs_test:(3) 1.000000] [jmsg/INFO] Task1 simulation time: 1.0
+> [MyHost1:dvfs_test:(2) 1.000000] [jmsg/INFO] Changing power peak value to 2.0E7 (at index 2)
+> [MyHost2:dvfs_test:(3) 1.000000] [jmsg/INFO] Changing power peak value to 2.0E7 (at index 2)
+> [MyHost1:dvfs_test:(2) 1.000000] [jmsg/INFO] Current power peak=2.0E7
+> [MyHost1:dvfs_test:(2) 1.000000] [jmsg/INFO] Task2 simulation time: 0.0
+> [MyHost1:dvfs_test:(2) 1.000000] [jmsg/INFO] Count of Processor states=3
+> [MyHost2:dvfs_test:(3) 1.000000] [jmsg/INFO] Current power peak=2.0E7
+> [MyHost2:dvfs_test:(3) 1.000000] [jmsg/INFO] Task2 simulation time: 0.0
+> [MyHost2:dvfs_test:(3) 1.000000] [jmsg/INFO] Count of Processor states=3
+> [MyHost1:dvfs_test:(2) 1.000000] [jmsg/INFO] Current power peak=2.0E7
+> [MyHost2:dvfs_test:(3) 1.000000] [jmsg/INFO] Current power peak=2.0E7
+> [1.000000] [jmsg/INFO] MSG_main finished; Cleaning up the simulation...
+> [1.000000] [surf_energy/INFO] Total energy of host MyHost1: 120.000000 Joules
+> [1.000000] [surf_energy/INFO] Total energy of host MyHost2: 120.000000 Joules
+> [1.000000] [surf_energy/INFO] Total energy of host MyHost3: 100.000000 Joules
index 0901969..12beaf5 100644 (file)
@@ -8,7 +8,8 @@
 
 /** @addtogroup MSG_examples
  *
- * - <b>energy/e1/e1.c</b> Shows how a set of pstates can be defined for a host and how the current pstate can be
+ * - <b>energy-pstate/energy-pstate.c</b> Shows how a set of pstates can be defined for a host and how the current
+ * pstate can be
  *     accessed/changed with @ref MSG_get_host_current_power_peak and @ref  MSG_set_host_pstate.
  *     Make sure to read the platform XML file for details on how to declare the CPU capacity for each pstate.
  */
index 93c9aac..09f12e4 100644 (file)
@@ -379,3 +379,29 @@ JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Host_getConsumedEnergy (JNIEnv *e
 
   return MSG_host_get_consumed_energy(host);
 }
+
+JNIEXPORT void JNICALL Java_org_simgrid_msg_Host_setPstate(JNIEnv* env, jobject jhost, jint pstate)
+{
+  msg_host_t host = jhost_get_native(env, jhost);
+  MSG_host_set_pstate(host, pstate);
+}
+JNIEXPORT jint JNICALL Java_org_simgrid_msg_Host_getPstate(JNIEnv* env, jobject jhost)
+{
+  msg_host_t host = jhost_get_native(env, jhost);
+  return MSG_host_get_pstate(host);
+}
+JNIEXPORT jint JNICALL Java_org_simgrid_msg_Host_getPstatesCount(JNIEnv* env, jobject jhost)
+{
+  msg_host_t host = jhost_get_native(env, jhost);
+  return MSG_host_get_nb_pstates(host);
+}
+JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Host_getCurrentPowerPeak(JNIEnv* env, jobject jhost)
+{
+  msg_host_t host = jhost_get_native(env, jhost);
+  return MSG_host_get_current_power_peak(host);
+}
+JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Host_getPowerPeakAt(JNIEnv* env, jobject jhost, jint pstate)
+{
+  msg_host_t host = jhost_get_native(env, jhost);
+  return MSG_host_get_power_peak_at(host, pstate);
+}
index f5a2d0c..461d69c 100644 (file)
@@ -198,6 +198,12 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Host_setAsyncMailbox(JNIEnv * env, j
 
 JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Host_getConsumedEnergy (JNIEnv *env, jobject jhost);
 
+JNIEXPORT void JNICALL Java_org_simgrid_msg_Host_setPstate(JNIEnv* env, jobject jhost, jint pstate);
+JNIEXPORT jint JNICALL Java_org_simgrid_msg_Host_getPstate(JNIEnv* env, jobject jhost);
+JNIEXPORT jint JNICALL Java_org_simgrid_msg_Host_getPstatesCount(JNIEnv* env, jobject jhost);
+JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Host_getCurrentPowerPeak(JNIEnv* env, jobject jhost);
+JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Host_getPowerPeakAt(JNIEnv* env, jobject jhost, jint pstate);
+
 SG_END_DECL()
 #endif                          /*!MSG_JHOST_H */
 
index d4d336c..4da5e01 100644 (file)
@@ -136,6 +136,17 @@ public class Host {
 
        /** Returns the amount of Joules consumed by that host so far */
        public native double getConsumedEnergy();
+       
+       /** Returns the current pstate */
+       public native int getPstate();
+       /** Changes the current pstate */
+       public native void setPstate(int pstate);
+       public native int getPstatesCount();
+       /** Returns the speed of the processor (in flop/s) at the current pstate. See also @ref SURF_plugin_energy. */
+       public native double getCurrentPowerPeak();
+       /** Returns the speed of the processor (in flop/s) at a given pstate. See also @ref SURF_plugin_energy. */
+       public native double getPowerPeakAt(int pstate);
+       
 
        /** Class initializer, to initialize various JNI stuff */
        public static native void nativeInit();