From bbe2fa7b0c1edfa11b9c327be81d0fc6d005ab05 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Thu, 21 Jan 2016 01:21:13 +0100 Subject: [PATCH] integrate Adrien's example for Java VM energy as a tesh test --- .gitignore | 1 + examples/java/cloud/energy/CMakeLists.txt | 42 +++++++ .../java/cloud/energy/EnergyVMRunner.java | 70 +++++++++++ examples/java/cloud/energy/Main.java | 43 +++---- examples/java/cloud/energy/Test.java | 111 ------------------ .../cloud/energy/deployment_consumption.xml | 7 -- examples/java/cloud/energy/energy.tesh | 16 +++ src/bindings/java/jmsg_vm.cpp | 1 + tools/cmake/MakeExe.cmake | 1 + tools/cmake/Tests.cmake | 1 + 10 files changed, 149 insertions(+), 144 deletions(-) create mode 100644 examples/java/cloud/energy/CMakeLists.txt create mode 100644 examples/java/cloud/energy/EnergyVMRunner.java delete mode 100644 examples/java/cloud/energy/Test.java delete mode 100644 examples/java/cloud/energy/deployment_consumption.xml create mode 100644 examples/java/cloud/energy/energy.tesh diff --git a/.gitignore b/.gitignore index 1f6f88132c..646c141315 100644 --- a/.gitignore +++ b/.gitignore @@ -1051,6 +1051,7 @@ examples/java/async/java_async_compiled examples/java/bittorrent/java_bittorrent_compiled examples/java/chord/java_chord_compiled examples/java/cloud/java_cloud_compiled +examples/java/cloud/energy/java_cloud_energy_compiled examples/java/cloud/migration/java_cloud_migration_compiled examples/java/commTime/java_commTime_compiled examples/java/energy/java_energy_compiled diff --git a/examples/java/cloud/energy/CMakeLists.txt b/examples/java/cloud/energy/CMakeLists.txt new file mode 100644 index 0000000000..ee8beccd18 --- /dev/null +++ b/examples/java/cloud/energy/CMakeLists.txt @@ -0,0 +1,42 @@ +set(example java_cloud_energy) +set(sources + ${CMAKE_CURRENT_SOURCE_DIR}/Main.java + ${CMAKE_CURRENT_SOURCE_DIR}/EnergyVMRunner.java + ) + +if(enable_java) + add_custom_command( + COMMENT "Building ${example}..." + OUTPUT ${example}_compiled + DEPENDS ${sources} simgrid-java_jar ${SIMGRID_JAR} + COMMAND ${JAVA_COMPILE} -classpath ${SIMGRID_JAR} + -d ${CMAKE_CURRENT_BINARY_DIR}/../.. ${sources} + COMMAND ${CMAKE_COMMAND} -E remove ${example}_compiled + COMMAND ${CMAKE_COMMAND} -E touch ${example}_compiled + ) + add_custom_target(${example} ALL DEPENDS ${example}_compiled) +endif() + +set(tesh_files + ${tesh_files} + ${CMAKE_CURRENT_SOURCE_DIR}/energyVM.tesh + PARENT_SCOPE + ) +set(xml_files + ${xml_files} + PARENT_SCOPE + ) +set(examples_src + ${examples_src} + ${sources} + PARENT_SCOPE + ) +set(bin_files + ${bin_files} + PARENT_SCOPE + ) +set(txt_files + ${CMAKE_CURRENT_SOURCE_DIR}/README + ${txt_files} + PARENT_SCOPE + ) diff --git a/examples/java/cloud/energy/EnergyVMRunner.java b/examples/java/cloud/energy/EnergyVMRunner.java new file mode 100644 index 0000000000..f967fa1220 --- /dev/null +++ b/examples/java/cloud/energy/EnergyVMRunner.java @@ -0,0 +1,70 @@ +/* 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 cloud.energy; + +import org.simgrid.msg.*; +import org.simgrid.msg.Process; + +/* This class is a process in charge of running the test. It creates and starts the VMs, and fork processes within the VMs */ +public class EnergyVMRunner extends Process { + + public class DummyProcess extends Process { + public DummyProcess (Host host, String name) { + super(host, name); + } + + public void main(String[] args) { + Task task = new Task(this.getHost().getName()+"-task", 300E6 , 0); + try { + task.execute(); + } catch (Exception e) { + e.printStackTrace(); + } + Msg.info("This worker is done."); + } + } + + EnergyVMRunner(Host host, String name, String[] args) throws HostNotFoundException, NativeException { + super(host, name, args); + } + + public void main(String[] strings) throws MsgException, HostNotFoundException { + double startTime = 0; + double endTime = 0; + + /* get hosts */ + Host host1 = Host.getByName("MyHost1"); + Host host2 = Host.getByName("MyHost2"); + Host host3 = Host.getByName("MyHost3"); + + Msg.info("Creating and starting two VMs"); + VM vmHost1 = new VM(host1, "vmHost1", 4, 2048, 100, null, 1024 * 20, 10,50); + vmHost1.start(); + + VM vmHost3 = new VM(host3, "vmHost3", 4, 2048, 100, null, 1024 * 20, 10,50); + vmHost3.start(); + + Msg.info("Create two tasks on Host1: one inside a VM, the other directly on the host"); + new DummyProcess (vmHost1, "p11"); + new DummyProcess (host1, "p12"); + + Msg.info("Create two tasks on Host2: both directly on the host"); + new DummyProcess (host2, "p21"); + new DummyProcess (host2, "p22"); + + Msg.info("Create two tasks on Host3: both inside a VM"); + new DummyProcess (vmHost3, "p31"); + new DummyProcess (vmHost3, "p312"); + + Msg.info("Wait 5 seconds. The tasks are still running (they run for 3 seconds, but 2 tasks are co-located, so they run for 6 seconds)"); + waitFor(5); + Msg.info("Wait another 5 seconds. The tasks stop at some point in between"); + waitFor(5); + + vmHost1.shutdown(); + vmHost3.shutdown(); + } +} diff --git a/examples/java/cloud/energy/Main.java b/examples/java/cloud/energy/Main.java index 875777e48d..931d2fd50f 100644 --- a/examples/java/cloud/energy/Main.java +++ b/examples/java/cloud/energy/Main.java @@ -1,10 +1,9 @@ -/* Copyright (c) 2014. The SimGrid Team. - * All rights reserved. */ +/* 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 cloud.energy; +package cloud.energy; import org.simgrid.msg.Host; import org.simgrid.msg.HostNotFoundException; @@ -12,31 +11,23 @@ import org.simgrid.msg.Msg; import org.simgrid.msg.NativeException; public class Main { - private static boolean endOfTest = false; - public static void setEndOfTest(){ - endOfTest=true; - } + public static void main(String[] args) throws NativeException, HostNotFoundException { + /* Init. internal values */ + Msg.energyInit(); + Msg.init(args); - public static boolean isEndOfTest(){ - return endOfTest; - } + if (args.length < 1) { + Msg.info("Usage: Main platform_file.xml"); + System.exit(1); + } - public static void main(String[] args) throws NativeException { - /* Init. internal values */ - Msg.energyInit(); - Msg.init(args); + /* construct the platform */ + Msg.createEnvironment(args[0]); + + /* Create and start a runner for the experiment */ + new EnergyVMRunner(Host.all()[0],"energy VM runner",null).start(); - if (args.length < 1) { - Msg.info("Usage : Main platform_file.xml deployment_file.xml"); - System.exit(1); - } - - /* construct the platform and deploy the application */ - Msg.createEnvironment(args[0]); - Msg.deployApplication(args[1]); - - Msg.run(); - - } + Msg.run(); + } } diff --git a/examples/java/cloud/energy/Test.java b/examples/java/cloud/energy/Test.java deleted file mode 100644 index 1128e75979..0000000000 --- a/examples/java/cloud/energy/Test.java +++ /dev/null @@ -1,111 +0,0 @@ -/* Copyright (c) 2014. 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 cloud.energy; - -import org.simgrid.msg.*; -import org.simgrid.msg.Process; - -public class Test extends Process{ - - - public class DummyProcess extends Process { - public DummyProcess (Host host, String name) { - super(host, name); - } - - public void main(String[] args) { - Task task = new Task(this.getHost().getName()+"-task", 30E6 , 0); - try { - task.execute(); - } catch (Exception e) { - e.printStackTrace(); - } - //task.finalize(); - Msg.info("This worker is done."); - } - } - - Test(Host host, String name, String[] args) throws HostNotFoundException, NativeException { - super(host, name, args); - } - - public void main(String[] strings) throws MsgException { - - double startTime = 0; - double endTime = 0; - - /* get hosts */ - Host host1 = null; - Host host2 = null; - Host host3 = null; - - try { - host1 = Host.getByName("MyHost1"); - host2 = Host.getByName("MyHost2"); - host3 = Host.getByName("MyHost3"); - } catch (HostNotFoundException e) { - e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. - } - - - /* Host 1*/ - Msg.info("Creating and starting two VMs"); - VM vmHost1 = null; - vmHost1 = new VM( - host1, - "vmHost1", - 4, // Nb of vcpu - 2048, // Ramsize, - 100, // Net Bandwidth - null, //VM disk image - 1024 * 20, //size of disk image, - 10, // Net bandwidth, - 50 // Memory intensity - ); - vmHost1.start(); - - VM vmHost3 = null; - vmHost3 = new VM( - host3, - "vmHost3", - 4, // Nb of vcpu - 2048, // Ramsize, - 100, // Net Bandwidth - null, //VM disk image - 1024 * 20, //size of disk image, - 10, // Net bandwidth, - 50 // Memory intensity - ); - vmHost3.start(); - - Msg.info("Create two tasks on Host1: one inside a VM, the other directly on the host"); - DummyProcess p11 = new DummyProcess (vmHost1, "p11"); - p11.run(); - DummyProcess p12 = new DummyProcess (host1, "p12"); - p12.run(); - - Msg.info("Create two tasks on Host2: both directly on the host"); - DummyProcess p21 = new DummyProcess (host2, "p21"); - p21.run(); - DummyProcess p22 = new DummyProcess (host2, "p22"); - p22.run(); - - Msg.info("Create two tasks on Host3: both inside a VM"); - DummyProcess p31 = new DummyProcess (vmHost3, "p31"); - p31.run(); - DummyProcess p32 = new DummyProcess (vmHost3, "p312"); - p32.run(); - - Msg.info("Wait 5 seconde. The tasks are still runing (they run for 3 secondes, but 2 tasks are co-located, so they run for 6 seconds)"); - Process.sleep(5); - Msg.info("Wait another 5 seconds. The tasks stop at some point in between"); - Process.sleep(5); - - vmHost1.shutdown(); - vmHost3.shutdown(); - } -} diff --git a/examples/java/cloud/energy/deployment_consumption.xml b/examples/java/cloud/energy/deployment_consumption.xml deleted file mode 100644 index 7f5fef8b90..0000000000 --- a/examples/java/cloud/energy/deployment_consumption.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/examples/java/cloud/energy/energy.tesh b/examples/java/cloud/energy/energy.tesh new file mode 100644 index 0000000000..f94a06d907 --- /dev/null +++ b/examples/java/cloud/energy/energy.tesh @@ -0,0 +1,16 @@ +#! tesh + +$ java -classpath ${classpath:=.} cloud/energy/Main ${srcdir:=.}/../platforms/energy_platform.xml +> [0.000000] [jmsg/INFO] Using regular java threads. +> [MyHost1:energy VM runner:(1) 0.000000] [jmsg/INFO] Creating and starting two VMs +> [0.000000] [surf_vm/INFO] Create VM(vmHost1)@PM(MyHost1) with 0 mounted disks +> [0.000000] [surf_vm/INFO] Create VM(vmHost3)@PM(MyHost3) with 0 mounted disks +> [MyHost1:energy VM runner:(1) 0.000000] [jmsg/INFO] Create two tasks on Host1: one inside a VM, the other directly on the host +> [MyHost1:energy VM runner:(1) 0.000000] [jmsg/INFO] Create two tasks on Host2: both directly on the host +> [MyHost1:energy VM runner:(1) 0.000000] [jmsg/INFO] Create two tasks on Host3: both inside a VM +> [MyHost1:energy VM runner:(1) 0.000000] [jmsg/INFO] Wait 5 seconds. The tasks are still running (they run for 3 seconds, but 2 tasks are co-located, so they run for 6 seconds) +> [MyHost1:energy VM runner:(1) 5.000000] [jmsg/INFO] Wait another 5 seconds. The tasks stop at some point in between +> [10.000000] [jmsg/INFO] MSG_main finished; Cleaning up the simulation... +> [10.000000] [surf_energy/INFO] Total energy of host MyHost1: 1000.000000 Joules +> [10.000000] [surf_energy/INFO] Total energy of host MyHost2: 1000.000000 Joules +> [10.000000] [surf_energy/INFO] Total energy of host MyHost3: 1000.000000 Joules diff --git a/src/bindings/java/jmsg_vm.cpp b/src/bindings/java/jmsg_vm.cpp index 84e805877e..2d2b382d3d 100644 --- a/src/bindings/java/jmsg_vm.cpp +++ b/src/bindings/java/jmsg_vm.cpp @@ -168,6 +168,7 @@ Java_org_simgrid_msg_VM_get_pm(JNIEnv *env, jobject jvm) { msg_host_t host = MSG_vm_get_pm(vm); if (!host->extension(JAVA_HOST_LEVEL)) { + THROW_DEADCODE; /* the native host not yet associated with the java host instance */ /* instanciate a new java host instance */ diff --git a/tools/cmake/MakeExe.cmake b/tools/cmake/MakeExe.cmake index 494e108d18..cd1f8fb9e5 100644 --- a/tools/cmake/MakeExe.cmake +++ b/tools/cmake/MakeExe.cmake @@ -7,6 +7,7 @@ add_subdirectory(${CMAKE_HOME_DIRECTORY}/examples/java/async) add_subdirectory(${CMAKE_HOME_DIRECTORY}/examples/java/bittorrent) add_subdirectory(${CMAKE_HOME_DIRECTORY}/examples/java/chord) add_subdirectory(${CMAKE_HOME_DIRECTORY}/examples/java/cloud) +add_subdirectory(${CMAKE_HOME_DIRECTORY}/examples/java/cloud/energy) add_subdirectory(${CMAKE_HOME_DIRECTORY}/examples/java/cloud/migration) add_subdirectory(${CMAKE_HOME_DIRECTORY}/examples/java/commTime) add_subdirectory(${CMAKE_HOME_DIRECTORY}/examples/java/energy) diff --git a/tools/cmake/Tests.cmake b/tools/cmake/Tests.cmake index b92e390015..19c318fef6 100644 --- a/tools/cmake/Tests.cmake +++ b/tools/cmake/Tests.cmake @@ -500,6 +500,7 @@ IF(NOT enable_memcheck) ADD_TESH(java-bypass --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/java --setenv classpath=${TESH_CLASSPATH} --cd ${CMAKE_BINARY_DIR}/examples/java ${CMAKE_HOME_DIRECTORY}/examples/java/master_slave_bypass/bypass.tesh) ADD_TESH(java-chord --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/java --setenv classpath=${TESH_CLASSPATH} --cd ${CMAKE_BINARY_DIR}/examples/java ${CMAKE_HOME_DIRECTORY}/examples/java/chord/chord.tesh) ADD_TESH(java-cloud --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/java --setenv classpath=${TESH_CLASSPATH} --cd ${CMAKE_BINARY_DIR}/examples/java ${CMAKE_HOME_DIRECTORY}/examples/java/cloud/cloud.tesh) + ADD_TESH(java-cloud-energy --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/java --setenv classpath=${TESH_CLASSPATH} --cd ${CMAKE_BINARY_DIR}/examples/java ${CMAKE_HOME_DIRECTORY}/examples/java/cloud/energy/energy.tesh) ADD_TESH(java-cloud-migration --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/java --setenv classpath=${TESH_CLASSPATH} --cd ${CMAKE_BINARY_DIR}/examples/java ${CMAKE_HOME_DIRECTORY}/examples/java/cloud/migration/migration.tesh) ADD_TESH(java-commTime --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/java --setenv classpath=${TESH_CLASSPATH} --cd ${CMAKE_BINARY_DIR}/examples/java ${CMAKE_HOME_DIRECTORY}/examples/java/commTime/commtime.tesh) ADD_TESH(java-energy --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/java --setenv classpath=${TESH_CLASSPATH} --cd ${CMAKE_BINARY_DIR}/examples/java ${CMAKE_HOME_DIRECTORY}/examples/java/energy/energy.tesh) -- 2.20.1