Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Expose Host Load for Java API through JNI
authorJeD <jean-emile.dartois@b-com.com>
Tue, 9 Oct 2018 09:36:55 +0000 (11:36 +0200)
committerJeD <jean-emile.dartois@b-com.com>
Tue, 9 Oct 2018 13:15:01 +0000 (15:15 +0200)
16 files changed:
examples/java/CMakeLists.txt
examples/java/cloud/migration/XVM.java
examples/java/hostload/LoadRunner.java [new file with mode: 0644]
examples/java/hostload/Main.java [new file with mode: 0644]
examples/java/hostload/hostload.tesh [new file with mode: 0644]
include/simgrid/host.h
include/simgrid/msg.h
include/simgrid/plugins/load.h
src/bindings/java/jmsg.cpp
src/bindings/java/jmsg.hpp
src/bindings/java/jmsg_host.cpp
src/bindings/java/jmsg_host.h
src/bindings/java/org/simgrid/msg/Host.java
src/bindings/java/org/simgrid/msg/Msg.java
src/msg/msg_legacy.cpp
src/s4u/s4u_Host.cpp

index 0e1967b..7a29a83 100644 (file)
@@ -23,11 +23,11 @@ set(process-migration_files     Main  Emigrant  Policeman)
 set(process-startkilltime_files Main  Sleeper)
 set(process-suspend_files       Main  DreamMaster  LazyGuy)
 set(task-priority_files         Main  Test)
-
+set(hostload_files              Main  LoadRunner)
 
 foreach (example app-bittorrent app-centralizedmutex app-masterworker app-pingpong app-tokenring async-yield async-waitall async-dsend
          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)
+         process-kill process-migration process-startkilltime process-suspend task-priority trace-pingpong hostload)
   string (REPLACE "-" "/" example_dir ${example})
   set (srcdir ${CMAKE_CURRENT_SOURCE_DIR}/${example_dir})
   foreach (filename ${${example}_files} )
@@ -66,7 +66,7 @@ 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-yield async-waitall async-dsend
            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)
+           process-kill process-migration process-startkilltime process-suspend task-priority trace-pingpong hostload)
     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/${example_dir} ${CMAKE_HOME_DIRECTORY}/examples/java/${example_dir}/${example}.tesh)
   endforeach()
index 563475f..6c24b50 100644 (file)
@@ -46,7 +46,7 @@ public class XVM extends VM {
     return this.daemon;
   }
 
-  public int getLoad(){
+  public double getLoad(){
     Msg.info("Remaining comp:" + this.daemon.getRemaining());
     return this.currentLoad;
   }
diff --git a/examples/java/hostload/LoadRunner.java b/examples/java/hostload/LoadRunner.java
new file mode 100644 (file)
index 0000000..24fcf93
--- /dev/null
@@ -0,0 +1,47 @@
+/* Copyright (c) 2016-2018. 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 hostload;
+
+import org.simgrid.msg.*;
+import org.simgrid.msg.Process;
+
+
+public class LoadRunner extends Process {
+
+    public LoadRunner(Host host, String s) {
+    super(host, s);
+}
+
+public void display(){
+    Msg.info("Computed Flops "+                getHost().getComputedFlops());
+    Msg.info("Current Load "+          getHost().getCurrentLoad());
+    Msg.info("GetLoad "+               getHost().getLoad());
+    Msg.info("AvgLoad "+               getHost().getAvgLoad());
+}
+@Override
+public void main(String[] strings) throws MsgException {
+    double workload = 100E6;
+    Host host = getHost();
+    display();
+    // Run a task
+    Task task1 = new Task("t1", workload, 0);
+    task1.execute();
+    display();
+    double taskTime = Msg.getClock();
+    Msg.info("Task1 simulation time: "+ taskTime);
+
+    // Run a second task
+    new Task("t1", workload, 0).execute();
+
+    taskTime = Msg.getClock() - taskTime;
+    Msg.info("Task2 simulation time: "+ taskTime);
+    display();
+
+}
+
+
+}
+
diff --git a/examples/java/hostload/Main.java b/examples/java/hostload/Main.java
new file mode 100644 (file)
index 0000000..785cc39
--- /dev/null
@@ -0,0 +1,34 @@
+/* Copyright (c) 2012-2018. 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 hostload;
+
+import org.simgrid.msg.Host;
+import org.simgrid.msg.Msg;
+import org.simgrid.msg.MsgException;
+
+public class Main {
+  private Main() {
+    throw new IllegalAccessError("Utility class");
+  }
+
+  public static void main(String[] args) throws MsgException {
+    Msg.loadInit();
+    Msg.init(args); 
+
+    if (args.length < 1) {
+      Msg.info("Usage   : Load platform_file");
+      Msg.info("Usage  : Load ../platforms/small_platform.xml");
+      System.exit(1);
+    }
+    /* Construct the platform */
+    Msg.createEnvironment(args[0]);
+    new LoadRunner(Host.all()[0], "").start();
+
+    Msg.run();
+
+  }
+}
diff --git a/examples/java/hostload/hostload.tesh b/examples/java/hostload/hostload.tesh
new file mode 100644 (file)
index 0000000..ba637d5
--- /dev/null
@@ -0,0 +1,19 @@
+#!/usr/bin/env tesh
+
+$ java -classpath ${classpath:=.} hostload/Main ${srcdir:=.}/../platforms/small_platform.xml
+> [0.000000] [java/INFO] Using regular java threads.
+> [Boivin::(1) 0.000000] [java/INFO] Computed Flops 0.0
+> [Boivin::(1) 0.000000] [java/INFO] Current Load 0.0
+> [Boivin::(1) 0.000000] [java/INFO] GetLoad 0.0
+> [Boivin::(1) 0.000000] [java/INFO] AvgLoad 0.0
+> [Boivin::(1) 1.019420] [java/INFO] Computed Flops 1.0E8
+> [Boivin::(1) 1.019420] [java/INFO] Current Load 1.0
+> [Boivin::(1) 1.019420] [java/INFO] GetLoad 0.0
+> [Boivin::(1) 1.019420] [java/INFO] AvgLoad 1.0
+> [Boivin::(1) 1.019420] [java/INFO] Task1 simulation time: 1.0194199500484225
+> [Boivin::(1) 2.038840] [java/INFO] Task2 simulation time: 1.0194199500484225
+> [Boivin::(1) 2.038840] [java/INFO] Computed Flops 2.0E8
+> [Boivin::(1) 2.038840] [java/INFO] Current Load 1.0
+> [Boivin::(1) 2.038840] [java/INFO] GetLoad 0.0
+> [Boivin::(1) 2.038840] [java/INFO] AvgLoad 1.0
+> [2.038840] [java/INFO] MSG_main finished; Cleaning up the simulation...
\ No newline at end of file
index 30a58f5..5d2f2f4 100644 (file)
@@ -93,6 +93,11 @@ XBT_PUBLIC double sg_host_get_available_speed(sg_host_t host);
 
 XBT_PUBLIC int sg_host_core_count(sg_host_t host);
 
+/** \ingroup m_host_management
+ * \brief Returns the current computation load (in flops per second).
+ */
+XBT_PUBLIC double sg_host_load(sg_host_t host);
+
 /** \ingroup m_process_management
  * \brief Return the location on which a process is running.
  * \return the sg_host_t corresponding to the location on which \a process is running.
index b562b47..c859352 100644 (file)
@@ -82,6 +82,7 @@ XBT_PUBLIC void MSG_host_set_property_value(sg_host_t host, const char* name, co
 XBT_PUBLIC void MSG_host_get_process_list(sg_host_t host, xbt_dynar_t whereto);
 
 XBT_PUBLIC sg_host_t MSG_host_self();
+XBT_PUBLIC double MSG_host_get_load(sg_host_t host);
 
 /* ******************************** VMs ************************************* */
 typedef sg_vm_t msg_vm_t;
index 734752a..eb518c8 100644 (file)
@@ -21,6 +21,7 @@ XBT_PUBLIC void sg_host_load_reset(sg_host_t host);
 #define MSG_host_load_plugin_init() sg_host_load_plugin_init()
 #define MSG_host_get_current_load(host) sg_host_get_current_load(host)
 #define MSG_host_get_computed_flops(host) sg_host_get_computed_flops(host)
+#define MSG_host_get_avg_load(host) sg_host_get_avg_load(host)
 
 SG_END_DECL()
 
index 6e5cbdd..86e69d9 100644 (file)
@@ -13,6 +13,7 @@
 #include "simgrid/plugins/energy.h"
 #include "simgrid/plugins/file_system.h"
 #include "simgrid/plugins/live_migration.h"
+#include "simgrid/plugins/load.h"
 #include "simgrid/simix.h"
 
 #include "simgrid/s4u/Host.hpp"
@@ -238,6 +239,10 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Msg_fileSystemInit()
   sg_storage_file_system_init();
 }
 
+JNIEXPORT void JNICALL Java_org_simgrid_msg_Msg_loadInit() {
+    sg_host_load_plugin_init();
+}
+
 /** Run a Java org.simgrid.msg.Process
  *
  *  If needed, this waits for the process starting time.
index c76fb11..6028080 100644 (file)
@@ -38,6 +38,7 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Msg_init(JNIEnv* env, jclass cls, jo
 JNIEXPORT void JNICALL Java_org_simgrid_msg_Msg_energyInit();
 JNIEXPORT void JNICALL Java_org_simgrid_msg_Msg_liveMigrationInit();
 JNIEXPORT void JNICALL Java_org_simgrid_msg_Msg_fileSystemInit();
+JNIEXPORT void JNICALL Java_org_simgrid_msg_Msg_loadInit();
 
 JNIEXPORT void JNICALL Java_org_simgrid_msg_Msg_debug(JNIEnv* env, jclass cls, jstring jargs);
 JNIEXPORT void JNICALL Java_org_simgrid_msg_Msg_verb(JNIEnv* env, jclass cls, jstring jargs);
index 32c513f..d6cc242 100644 (file)
@@ -6,6 +6,7 @@
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "simgrid/plugins/energy.h"
+#include "simgrid/plugins/load.h"
 #include "simgrid/s4u/Host.hpp"
 #include "simgrid/s4u/Storage.hpp"
 
@@ -372,3 +373,50 @@ JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Host_getPowerPeakAt(JNIEnv* env,
   msg_host_t host = jhost_get_native(env, jhost);
   return MSG_host_get_power_peak_at(host, pstate);
 }
+
+JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Host_getLoad(JNIEnv* env, jobject jhost)
+{
+  msg_host_t host = jhost_get_native(env, jhost);
+  return MSG_host_get_load(host);
+}
+
+
+
+JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Host_getCurrentLoad (JNIEnv *env, jobject jhost)
+{
+  msg_host_t host = jhost_get_native(env, jhost);
+
+  if (not host) {
+    jxbt_throw_notbound(env, "host", jhost);
+    return 0;
+  }
+
+  return MSG_host_get_current_load(host);
+}
+
+
+JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Host_getComputedFlops (JNIEnv *env, jobject jhost)
+{
+  msg_host_t host = jhost_get_native(env, jhost);
+
+  if (not host) {
+    jxbt_throw_notbound(env, "host", jhost);
+    return 0;
+  }
+
+  return MSG_host_get_computed_flops(host);
+}
+
+
+
+JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Host_getAvgLoad (JNIEnv *env, jobject jhost)
+{
+  msg_host_t host = jhost_get_native(env, jhost);
+
+  if (not host) {
+    jxbt_throw_notbound(env, "host", jhost);
+    return 0;
+  }
+
+  return MSG_host_get_avg_load(host);
+}
\ No newline at end of file
index cc9ee4a..9f6ac0d 100644 (file)
@@ -68,6 +68,10 @@ JNIEXPORT jint JNICALL Java_org_simgrid_msg_Host_getPstate(JNIEnv* env, jobject
 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);
+JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Host_getLoad(JNIEnv* env, jobject jhost);
 
+JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Host_getCurrentLoad(JNIEnv *env, jobject jhost);
+JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Host_getAvgLoad(JNIEnv *env, jobject jhost);
+JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Host_getComputedFlops (JNIEnv *env, jobject jhost);
 SG_END_DECL()
 #endif
index 0476da4..c61d9c7 100644 (file)
@@ -143,7 +143,13 @@ public class Host {
         * the value will be updated in kernel mode before returning the control to the requesting actor.
         */
        public native double getConsumedEnergy();
-       
+
+       public native double getCurrentLoad();
+
+       public native double getComputedFlops();
+
+       public native double getAvgLoad();
+
        /** Returns the current pstate */
        public native int getPstate();
        /** Changes the current pstate */
@@ -153,7 +159,9 @@ public class Host {
        public native double getCurrentPowerPeak();
        /** Returns the speed of the processor (in flop/s) at a given pstate. See also @ref plugin_energy. */
        public native double getPowerPeakAt(int pstate);
-       
+
+       /** Returns the current computation load (in flops per second) */
+       public native double getLoad();
 
        /** Class initializer, to initialize various JNI stuff */
        private static native void nativeInit();
index b103d2f..953b1df 100644 (file)
@@ -41,6 +41,7 @@ public final class Msg {
        /** Tell the kernel that you want to use the energy plugin */
        public static final native void energyInit();
        public static final native void fileSystemInit();
+       public static final native void loadInit();
 
        /** Run the MSG simulation.
         *
index bb1148f..3a69cb3 100644 (file)
@@ -297,6 +297,11 @@ sg_host_t MSG_host_self()
 {
   return sg_host_self();
 }
+
+double MSG_host_get_load(sg_host_t host)
+{
+  return sg_host_load(host);
+}
 /* ************************** Virtual Machines *************************** */
 sg_vm_t MSG_vm_create_core(sg_host_t pm, const char* name)
 {
index e321de2..3ccf041 100644 (file)
@@ -645,3 +645,8 @@ sg_host_t sg_host_self()
   smx_actor_t process = SIMIX_process_self();
   return (process == nullptr) ? nullptr : process->host;
 }
+
+double sg_host_load(sg_host_t host)
+{
+  return host->get_load();
+}
\ No newline at end of file