From: Martin Quinson Date: Thu, 19 Jan 2017 14:15:51 +0000 (+0100) Subject: implement the DVFS functions in Java X-Git-Tag: v3_15~536 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/b22adadfea7ebc1441083b43c6e287cdf1eaa79a?hp=8a0c620164f51b5bfcf22286b2d43ae6a1b3893f implement the DVFS functions in Java --- diff --git a/.gitignore b/.gitignore index a8850ff332..477d17a535 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/examples/java/CMakeLists.txt b/examples/java/CMakeLists.txt index b246cbfcfe..4b73e94d91 100644 --- a/examples/java/CMakeLists.txt +++ b/examples/java/CMakeLists.txt @@ -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 index 0000000000..aa364a66c2 --- /dev/null +++ b/examples/java/energy/pstate/Main.java @@ -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 index 0000000000..7319c3afcf --- /dev/null +++ b/examples/java/energy/pstate/PstateRunner.java @@ -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 index 0000000000..09bf104094 --- /dev/null +++ b/examples/java/energy/pstate/energy_pstate.tesh @@ -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 diff --git a/examples/msg/energy-pstate/energy-pstate.c b/examples/msg/energy-pstate/energy-pstate.c index 09019696a7..12beaf56b9 100644 --- a/examples/msg/energy-pstate/energy-pstate.c +++ b/examples/msg/energy-pstate/energy-pstate.c @@ -8,7 +8,8 @@ /** @addtogroup MSG_examples * - * - energy/e1/e1.c Shows how a set of pstates can be defined for a host and how the current pstate can be + * - energy-pstate/energy-pstate.c 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. */ diff --git a/src/bindings/java/jmsg_host.cpp b/src/bindings/java/jmsg_host.cpp index 93c9aac4ca..09f12e4346 100644 --- a/src/bindings/java/jmsg_host.cpp +++ b/src/bindings/java/jmsg_host.cpp @@ -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); +} diff --git a/src/bindings/java/jmsg_host.h b/src/bindings/java/jmsg_host.h index f5a2d0cdaf..461d69cc30 100644 --- a/src/bindings/java/jmsg_host.h +++ b/src/bindings/java/jmsg_host.h @@ -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 */ diff --git a/src/bindings/java/org/simgrid/msg/Host.java b/src/bindings/java/org/simgrid/msg/Host.java index d4d336c72a..4da5e01347 100644 --- a/src/bindings/java/org/simgrid/msg/Host.java +++ b/src/bindings/java/org/simgrid/msg/Host.java @@ -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();