From: Paul Bédaride Date: Fri, 4 Apr 2014 08:46:08 +0000 (+0200) Subject: Add example of java cpu model X-Git-Tag: v3_11~133 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/9706edf4ebb5500f6d33984335280f42ad594ff1 Add example of java cpu model --- diff --git a/buildtools/Cmake/AddTests.cmake b/buildtools/Cmake/AddTests.cmake index 528fe59798..e22caa181b 100644 --- a/buildtools/Cmake/AddTests.cmake +++ b/buildtools/Cmake/AddTests.cmake @@ -631,6 +631,7 @@ if(NOT enable_memcheck) ADD_TEST(java-priority ${TESH_COMMAND} ${TESH_OPTION} --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/java --setenv classpath=${TESH_CLASSPATH} --cd ${CMAKE_BINARY_DIR}/examples/java ${CMAKE_HOME_DIRECTORY}/examples/java/priority/priority.tesh) ADD_TEST(java-reservation-surf-plugin ${TESH_COMMAND} ${TESH_OPTION} --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/java --setenv classpath=${TESH_CLASSPATH} --cd ${CMAKE_BINARY_DIR}/examples/java ${CMAKE_HOME_DIRECTORY}/examples/java/reservationSurfPlugin/reservation_surf_plugin.tesh) ADD_TEST(java-startKillTime ${TESH_COMMAND} ${TESH_OPTION} --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/java --setenv classpath=${TESH_CLASSPATH} --cd ${CMAKE_BINARY_DIR}/examples/java ${CMAKE_HOME_DIRECTORY}/examples/java/startKillTime/startKillTime.tesh) + ADD_TEST(java-surf-cpu-model ${TESH_COMMAND} ${TESH_OPTION} --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/java --setenv classpath=${TESH_CLASSPATH} --cd ${CMAKE_BINARY_DIR}/examples/java ${CMAKE_HOME_DIRECTORY}/examples/java/surfCpuModel/surf_cpu_model.tesh) ADD_TEST(java-surf-plugin ${TESH_COMMAND} ${TESH_OPTION} --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/java --setenv classpath=${TESH_CLASSPATH} --cd ${CMAKE_BINARY_DIR}/examples/java ${CMAKE_HOME_DIRECTORY}/examples/java/surfPlugin/surf_plugin.tesh) ADD_TEST(java-suspend ${TESH_COMMAND} ${TESH_OPTION} --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/java --setenv classpath=${TESH_CLASSPATH} --cd ${CMAKE_BINARY_DIR}/examples/java ${CMAKE_HOME_DIRECTORY}/examples/java/suspend/suspend.tesh) if(HAVE_TRACING) diff --git a/buildtools/Cmake/DefinePackages.cmake b/buildtools/Cmake/DefinePackages.cmake index 013c8fc526..047cbd2736 100644 --- a/buildtools/Cmake/DefinePackages.cmake +++ b/buildtools/Cmake/DefinePackages.cmake @@ -498,6 +498,7 @@ set(JSURF_JAVA_GENERATED_SRC ${CMAKE_BINARY_DIR}/src/bindings/java/org/simgrid/surf/SurfJNI.java ${CMAKE_BINARY_DIR}/src/bindings/java/org/simgrid/surf/Plugin.java ${CMAKE_BINARY_DIR}/src/bindings/java/org/simgrid/surf/Model.java + ${CMAKE_BINARY_DIR}/src/bindings/java/org/simgrid/surf/CpuModel.java ${CMAKE_BINARY_DIR}/src/bindings/java/org/simgrid/surf/Resource.java ${CMAKE_BINARY_DIR}/src/bindings/java/org/simgrid/surf/Action.java ${CMAKE_BINARY_DIR}/src/bindings/java/org/simgrid/surf/Cpu.java @@ -506,7 +507,10 @@ set(JSURF_JAVA_GENERATED_SRC ${CMAKE_BINARY_DIR}/src/bindings/java/org/simgrid/surf/NetworkAction.java ${CMAKE_BINARY_DIR}/src/bindings/java/org/simgrid/surf/RoutingEdge.java + ${CMAKE_BINARY_DIR}/src/bindings/java/org/simgrid/surf/TmgrTraceEvent.java + ${CMAKE_BINARY_DIR}/src/bindings/java/org/simgrid/surf/TmgrTrace.java + #enums ${CMAKE_BINARY_DIR}/src/bindings/java/org/simgrid/surf/ActionState.java ${CMAKE_BINARY_DIR}/src/bindings/java/org/simgrid/surf/ResourceState.java @@ -924,6 +928,7 @@ set(EXAMPLES_CMAKEFILES_TXT examples/java/priority/CMakeLists.txt examples/java/reservationSurfPlugin/CMakeLists.txt examples/java/startKillTime/CMakeLists.txt + examples/java/surfCpuModel/CMakeLists.txt examples/java/surfPlugin/CMakeLists.txt examples/java/suspend/CMakeLists.txt examples/java/tracing/CMakeLists.txt diff --git a/buildtools/Cmake/MakeExe.cmake b/buildtools/Cmake/MakeExe.cmake index b9445e4573..513d72f4c9 100644 --- a/buildtools/Cmake/MakeExe.cmake +++ b/buildtools/Cmake/MakeExe.cmake @@ -20,6 +20,7 @@ add_subdirectory(${CMAKE_HOME_DIRECTORY}/examples/java/pingPong) add_subdirectory(${CMAKE_HOME_DIRECTORY}/examples/java/priority) add_subdirectory(${CMAKE_HOME_DIRECTORY}/examples/java/reservationSurfPlugin) add_subdirectory(${CMAKE_HOME_DIRECTORY}/examples/java/startKillTime) +add_subdirectory(${CMAKE_HOME_DIRECTORY}/examples/java/surfCpuModel) add_subdirectory(${CMAKE_HOME_DIRECTORY}/examples/java/surfPlugin) add_subdirectory(${CMAKE_HOME_DIRECTORY}/examples/java/suspend) add_subdirectory(${CMAKE_HOME_DIRECTORY}/examples/java/tracing) diff --git a/examples/java/surfCpuModel/CMakeLists.txt b/examples/java/surfCpuModel/CMakeLists.txt new file mode 100644 index 0000000000..2af5240d05 --- /dev/null +++ b/examples/java/surfCpuModel/CMakeLists.txt @@ -0,0 +1,47 @@ +cmake_minimum_required(VERSION 2.6) + +set(example java_surf_cpu_model) +set(sources + ${CMAKE_CURRENT_SOURCE_DIR}/TestCpuModel.java + ${CMAKE_CURRENT_SOURCE_DIR}/CpuConstantModel.java + ${CMAKE_CURRENT_SOURCE_DIR}/Sender.java + ${CMAKE_CURRENT_SOURCE_DIR}/Receiver.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}/surf_cpu_model.tesh + PARENT_SCOPE + ) +set(xml_files + ${xml_files} + ${CMAKE_CURRENT_SOURCE_DIR}/surfCpuModelPlatform.xml + ${CMAKE_CURRENT_SOURCE_DIR}/surfCpuModelDeployment.xml + PARENT_SCOPE + ) +set(examples_src + ${examples_src} + ${sources} + PARENT_SCOPE + ) +set(bin_files + ${bin_files} + PARENT_SCOPE + ) +set(txt_files + ${txt_files} + PARENT_SCOPE + ) diff --git a/examples/java/surfCpuModel/CpuConstantModel.java b/examples/java/surfCpuModel/CpuConstantModel.java new file mode 100644 index 0000000000..7325355de7 --- /dev/null +++ b/examples/java/surfCpuModel/CpuConstantModel.java @@ -0,0 +1,77 @@ +package surfCpuModel; + +import org.simgrid.surf.*; +import org.simgrid.msg.Msg; +import java.util.List; +import java.util.ArrayList; + +public class CpuConstantModel extends CpuModel { + + private List cpus = new ArrayList(); + private List actions = new ArrayList(); + + public CpuConstantModel() { + super("Cpu Constant"); + Msg.info("Initialize Cpu Constant Model"); + } + + public Cpu createResource(String name, double[] power_peak, int pstate, double power_scale, TmgrTrace power_trace, int core, ResourceState state_initial, TmgrTrace state_trace, XbtDict cpu_properties) { + Msg.info("Create Resource Name: "+name); + CpuConstant res = new CpuConstant(this, name, cpu_properties, actions, 1, 1000, 1000); + cpus.add(res); + Surf.setCpu(name, res); + return res; + } + + public void setState(ResourceState state) { + Msg.info("setState"); + } + + public double shareResources(double now) { + Msg.info("shareResource of "+cpus.size()+" cpu and "+actions.size()+" actions"); + return now+1; + } + + public void updateActionsState(double now, double delta) { + Msg.info("updateActionState of "+cpus.size()+" cpu and "+actions.size()+" actions"); + } + + public void addTraces() { + } + +public class CpuConstant extends Cpu { + private List actions; + + public CpuConstant(CpuConstantModel model, String name, XbtDict props, + List actions, + int core, double powerPeak, double powerScale) { + super(model, name, props, core, powerPeak, powerScale); + this.actions = actions; + } + + public CpuAction execute(double size) { + CpuConstantAction res = new CpuConstantAction(getModel(), size, false); + Msg.info("Execute action of size "+size); + actions.add(res); + return res; + } + + public CpuAction sleep(double duration) { + CpuConstantAction res = new CpuConstantAction(getModel(), duration, false); + Msg.info("Sleep action of duration "+duration); + actions.add(res); + return res; + } + + public ResourceState getState(){ + return ResourceState.SURF_RESOURCE_ON; + } +} + +public class CpuConstantAction extends CpuAction { + public CpuConstantAction(Model model, double cost, boolean failed) { + super(model, cost, failed); + } +} +} + diff --git a/examples/java/surfCpuModel/Receiver.java b/examples/java/surfCpuModel/Receiver.java new file mode 100644 index 0000000000..bbfe7d2aca --- /dev/null +++ b/examples/java/surfCpuModel/Receiver.java @@ -0,0 +1,32 @@ +/* Copyright (c) 2006-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 surfCpuModel; +import org.simgrid.msg.Host; +import org.simgrid.msg.Msg; +import org.simgrid.msg.MsgException; +import org.simgrid.msg.Task; +import org.simgrid.msg.Process; + +public class Receiver extends Process { + public Receiver(Host host, String name, String[]args) { + super(host,name,args); + } + final double commSizeLat = 1; + final double commSizeBw = 100000000; + + public void main(String[] args) throws MsgException { + + Msg.info("helloo!"); + + Task task; + task = Task.receive(getHost().getName()); + task = Task.receive(getHost().getName()); + task = Task.receive(getHost().getName()); + + Msg.info("goodbye!"); + } +} diff --git a/examples/java/surfCpuModel/Sender.java b/examples/java/surfCpuModel/Sender.java new file mode 100644 index 0000000000..5f6a47f663 --- /dev/null +++ b/examples/java/surfCpuModel/Sender.java @@ -0,0 +1,51 @@ +/* Copyright (c) 2006-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 surfCpuModel; +import org.simgrid.msg.Host; +import org.simgrid.msg.HostNotFoundException; +import org.simgrid.msg.Msg; +import org.simgrid.msg.MsgException; +import org.simgrid.msg.Process; +import org.simgrid.msg.Task; + +public class Sender extends Process { + public Sender(Host host, String name, String[] args) { + super(host,name,args); + } + private final double commSizeLat = 1; + final double commSizeBw = 100000000; + + public void main(String[] args) throws MsgException { + + Msg.info("helloo!"); + + String receiverName = args[0]; + double oldTime, curTime; + double computeDuration = 10000; + Task task; + + oldTime = Msg.getClock(); + task = new Task("no name",computeDuration,commSizeLat); + task.send(receiverName); + curTime = Msg.getClock(); + Msg.info("Send duration: " + (curTime - oldTime)); + + oldTime = curTime; + task = new Task("no name",computeDuration,commSizeLat); + task.send(receiverName); + curTime = Msg.getClock(); + Msg.info("Send duration with update bandwidth: " + (curTime - oldTime)); + + oldTime = curTime; + task = new Task("no name",computeDuration,commSizeLat); + task.send(receiverName); + curTime = Msg.getClock(); + Msg.info("Send normal duration with limited bandwidth: " + (curTime - oldTime)); + + Msg.info("goodbye!"); + } +} diff --git a/examples/java/surfCpuModel/TestCpuModel.java b/examples/java/surfCpuModel/TestCpuModel.java new file mode 100644 index 0000000000..91345fdb81 --- /dev/null +++ b/examples/java/surfCpuModel/TestCpuModel.java @@ -0,0 +1,47 @@ +/* Copyright (c) 2006-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 surfCpuModel; + +import org.simgrid.msg.Msg; +import org.simgrid.msg.NativeException; +import org.simgrid.surf.Surf; +import org.simgrid.surf.Cpu; +import org.simgrid.surf.CpuModel; + +public class TestCpuModel { + + /* This only contains the launcher. If you do nothing more than than you can run + * java simgrid.msg.Msg + * which also contains such a launcher + */ + + public static void main(String[] args) throws NativeException { + /* initialize the MSG simulation. Must be done before anything else (even logging). */ + CpuModel cm = new CpuConstantModel(); + Surf.setCpuModel(cm); + //Msg.info(Surf.getCpuModel().getName()); + //Msg.info(cm.getName()); + Msg.init(args); + //Msg.info("Cpu Loaded: "+Surf.getCpuModel().getName()); + + if(args.length < 2) { + Msg.info("Usage : TestPlugin platform_file deployment_file"); + Msg.info("example : TestPlugin ping_pong_platform.xml ping_pong_deployment.xml"); + System.exit(1); + } + + /* construct the platform and deploy the application */ + Msg.createEnvironment(args[0]); + Msg.deployApplication(args[1]); + //Msg.info("Cpu Loaded: "+Surf.getCpuModel().getName()); + //Msg.info("Cpu Loaded: "+cm.getName()); + + // getName()); + /* execute the simulation. */ + Msg.run(); + } +} diff --git a/examples/java/surfCpuModel/surfCpuModelDeployment.xml b/examples/java/surfCpuModel/surfCpuModelDeployment.xml new file mode 100644 index 0000000000..0cb8e3b5c5 --- /dev/null +++ b/examples/java/surfCpuModel/surfCpuModelDeployment.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/examples/java/surfCpuModel/surfCpuModelPlatform.xml b/examples/java/surfCpuModel/surfCpuModelPlatform.xml new file mode 100644 index 0000000000..155dd2d2aa --- /dev/null +++ b/examples/java/surfCpuModel/surfCpuModelPlatform.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/java/surfCpuModel/surf_cpu_model.tesh b/examples/java/surfCpuModel/surf_cpu_model.tesh new file mode 100644 index 0000000000..2f0fd003e5 --- /dev/null +++ b/examples/java/surfCpuModel/surf_cpu_model.tesh @@ -0,0 +1,42 @@ +#! tesh + +$ java -classpath ${classpath:=.} surfCpuModel/TestCpuModel ${srcdir:=.}/surfCpuModel/surfCpuModelPlatform.xml ${srcdir:=.}/surfCpuModel/surfCpuModelDeployment.xml --cfg=workstation/model:compound +> [0.000000] [jmsg/INFO] Initialize Cpu Constant Model +> [0.000000] [xbt_cfg/INFO] Configuration change: Set 'workstation/model' to 'compound' +> [0.000000] [jmsg/INFO] Using regular java threads. Coroutines could speed your simulation up. +> [0.000000] [jmsg/INFO] Create Resource Name: Jacquelin +> [0.000000] [jmsg/INFO] Create Resource Name: Boivin +> [0.000000] [jmsg/INFO] Create Resource Name: TeX +> [0.000000] [jmsg/INFO] updateActionState of 3 cpu and 0 actions +> [Jacquelin:surfCpuModel.Sender:(1) 0.000000] [jmsg/INFO] helloo! +> [Boivin:surfCpuModel.Receiver:(2) 0.000000] [jmsg/INFO] helloo! +> [0.000000] [jmsg/INFO] Sleep action of duration -1.0 +> [0.000000] [jmsg/INFO] Sleep action of duration -1.0 +> [0.000000] [jmsg/INFO] shareResource of 3 cpu and 2 actions +> [0.000000] [jmsg/INFO] shareResource of 3 cpu and 2 actions +> [0.026020] [jmsg/INFO] updateActionState of 3 cpu and 2 actions +> [0.026020] [jmsg/INFO] shareResource of 3 cpu and 2 actions +> [0.026020] [jmsg/INFO] shareResource of 3 cpu and 2 actions +> [0.026021] [jmsg/INFO] updateActionState of 3 cpu and 2 actions +> [Jacquelin:surfCpuModel.Sender:(1) 0.026021] [jmsg/INFO] Send duration: 0.026021030927835052 +> [0.026021] [jmsg/INFO] Sleep action of duration -1.0 +> [0.026021] [jmsg/INFO] Sleep action of duration -1.0 +> [0.026021] [jmsg/INFO] shareResource of 3 cpu and 4 actions +> [0.026021] [jmsg/INFO] shareResource of 3 cpu and 4 actions +> [0.052041] [jmsg/INFO] updateActionState of 3 cpu and 4 actions +> [0.052041] [jmsg/INFO] shareResource of 3 cpu and 4 actions +> [0.052041] [jmsg/INFO] shareResource of 3 cpu and 4 actions +> [0.052042] [jmsg/INFO] updateActionState of 3 cpu and 4 actions +> [Jacquelin:surfCpuModel.Sender:(1) 0.052042] [jmsg/INFO] Send duration with update bandwidth: 0.026021030927835052 +> [0.052042] [jmsg/INFO] Sleep action of duration -1.0 +> [0.052042] [jmsg/INFO] Sleep action of duration -1.0 +> [0.052042] [jmsg/INFO] shareResource of 3 cpu and 6 actions +> [0.052042] [jmsg/INFO] shareResource of 3 cpu and 6 actions +> [0.078062] [jmsg/INFO] updateActionState of 3 cpu and 6 actions +> [0.078062] [jmsg/INFO] shareResource of 3 cpu and 6 actions +> [0.078062] [jmsg/INFO] shareResource of 3 cpu and 6 actions +> [0.078063] [jmsg/INFO] updateActionState of 3 cpu and 6 actions +> [Boivin:surfCpuModel.Receiver:(2) 0.078063] [jmsg/INFO] goodbye! +> [Jacquelin:surfCpuModel.Sender:(1) 0.078063] [jmsg/INFO] Send normal duration with limited bandwidth: 0.02602103092783506 +> [Jacquelin:surfCpuModel.Sender:(1) 0.078063] [jmsg/INFO] goodbye! +> [0.078063] [jmsg/INFO] MSG_main finished; Cleaning up the simulation... diff --git a/src/bindings/java/surf.i b/src/bindings/java/surf.i index 1553e77060..51a586e0e9 100644 --- a/src/bindings/java/surf.i +++ b/src/bindings/java/surf.i @@ -8,6 +8,7 @@ %module(directors="1") Surf %include "arrays_java.i" +%include "std_string.i" %pragma(java) jniclassimports=%{ import org.simgrid.NativeLib; @@ -29,9 +30,14 @@ import org.simgrid.NativeLib; %{ #include "src/surf/cpu_interface.hpp" #include "src/surf/network_interface.hpp" +#include "src/surf/trace_mgr_private.h" #include "src/bindings/java/surf_swig.hpp" #include "src/xbt/dict_private.h" typedef struct lmm_constraint *lmm_constraint_t; +typedef xbt_dynar_t DoubleDynar; +/*class CpuModel : public CpuModel { + +};*/ %} /* Handle xbt_dynar_t of NetworkLink */ @@ -56,31 +62,131 @@ JAVA_ARRAYSOFCLASSES(NetworkLink); xbt_dynar_free(&$1); } +/*%typemap(out) DoubleDynar { + $result = (double[])$1; +}*/ + +//typedef xbt_dynar_t DoubleDynar; +%nodefault DoubleDynar; +%typemap(jni) DoubleDynar "jdoubleArray" +%rename(DoubleDynar) Double[]; +%typemap(jtype) DoubleDynar "double[]" +%typemap(jstype) DoubleDynar "double[]" +%typemap(out) DoubleDynar { + long l = xbt_dynar_length($1); + $result = jenv->NewDoubleArray(l); + double *lout = (double *)xbt_dynar_to_array($1); + jenv->SetDoubleArrayRegion($result, 0, l, (const jdouble*)lout); + free(lout); +} +%typemap(javadirectorin) DoubleDynar "$jniinput" +%typemap(directorin,descriptor="[D") DoubleDynar %{ + long l = xbt_dynar_length($1); + $input = jenv->NewDoubleArray(l); + double *lout = (double *)xbt_dynar_to_array($1); + jenv->SetDoubleArrayRegion($input, 0, l, (const jdouble*)lout); + free(lout); +%} +%typemap(javain) DoubleDynar "$javainput" +%typemap(javaout) DoubleDynar {return $jnicall} + /* Allow to subclass Plugin and send java object to C++ code */ %feature("director") Plugin; %include "src/bindings/java/surf_swig.hpp" +%rename tmgr_trace TmgrTrace; +%nodefaultctor tmgr_trace; +struct tmgr_trace { + //enum e_trace_type type; + /*union { + struct { + xbt_dynar_t event_list; + } s_list; + struct { + probabilist_event_generator_t event_generator[2]; + int is_state_trace; + int next_event; + } s_probabilist; + };*/ + %extend { + } +}; + +%rename tmgr_trace_event TmgrTraceEvent; +%nodefaultctor tmgr_trace_event; +struct tmgr_trace_event { + //tmgr_trace_t trace; + //unsigned int idx; + //void *model; + //int free_me; + %extend { + unsigned int getIdx() {return 0;}//$self->idx;} + } +}; + + %nodefaultctor Model; class Model { public: + Model(const char *name); const char *getName(); + virtual double shareResources(double now); + virtual double shareResourcesLazy(double now); + virtual double shareResourcesFull(double now); + + virtual void updateActionsState(double now, double delta); + virtual void updateActionsStateLazy(double now, double delta); + virtual void updateActionsStateFull(double now, double delta); }; +%feature("director") CpuModel; +class CpuModel : public Model { +public: + CpuModel(const char *name); + virtual ~CpuModel(); + virtual Cpu *createResource(const char *name, DoubleDynar power_peak, + int pstate, double power_scale, + tmgr_trace *power_trace, int core, + e_surf_resource_state_t state_initial, + tmgr_trace *state_trace, + s_xbt_dict *cpu_properties)=0; + void setState(e_surf_resource_state_t state); + virtual void addTraces()=0; +}; + + class Resource { public: Resource(); const char *getName(); virtual bool isUsed()=0; + Model *getModel(); + + virtual e_surf_resource_state_t getState(); lmm_constraint *getConstraint(); s_xbt_dict *getProperties(); + virtual void updateState(tmgr_trace_event *event_type, double value, double date)=0; }; +%feature("director") Cpu; class Cpu : public Resource { public: - Cpu(); - ~Cpu(); - double getCurrentPowerPeak(); + Cpu(Model *model, const char *name, s_xbt_dict *props, + lmm_constraint *constraint, int core, double powerPeak, double powerScale); + Cpu(Model *model, const char *name, s_xbt_dict *props, + int core, double powerPeak, double powerScale); + virtual ~Cpu(); + virtual double getCurrentPowerPeak()=0; + virtual CpuAction *execute(double size)=0; + virtual CpuAction *sleep(double duration)=0; + virtual int getCore(); + virtual double getSpeed(double load); + virtual double getAvailableSpeed(); + virtual double getPowerPeakAt(int pstate_index)=0; + virtual int getNbPstates()=0; + virtual void setPowerPeakAt(int pstate_index)=0; + void setState(e_surf_resource_state_t state); }; class NetworkLink : public Resource { @@ -103,8 +209,10 @@ public: }; %nodefaultctor CpuAction; +%feature("director") CpuAction; class CpuAction : public Action { public: +CpuAction(Model *model, double cost, bool failed); %extend { Cpu *getCpu() {return getActionCpu($self);} } @@ -118,6 +226,7 @@ public: } }; + %nodefaultctor RoutingEdge; class RoutingEdge { public: diff --git a/src/bindings/java/surf_swig.cpp b/src/bindings/java/surf_swig.cpp index 8bf9b0cbf3..afff2a9a8a 100644 --- a/src/bindings/java/surf_swig.cpp +++ b/src/bindings/java/surf_swig.cpp @@ -9,7 +9,6 @@ #include "surf_swig.hpp" #include "src/simix/smx_private.h" - double getClock() { return surf_get_clock(); } @@ -18,10 +17,26 @@ void clean() { SIMIX_clean(); } -/*NetworkModel *getNetworkModel() -{ - return surf_network_model; -}*/ +CpuModel *getCpuModel(){ + return surf_cpu_model_pm; +} + +CpuModel *java_cpu_model; +static void java_cpu_model_init_preparse() { + surf_cpu_model_pm = java_cpu_model; + xbt_dynar_push(model_list, &java_cpu_model); + xbt_dynar_push(model_list_invoke, &java_cpu_model); + sg_platf_host_add_cb(parse_cpu_init); +} + +void setCpuModel(CpuModel *cpuModel){ + java_cpu_model = cpuModel; + surf_cpu_model_init_preparse = java_cpu_model_init_preparse; +} + +void setCpu(char *name, Cpu *cpu) { + xbt_lib_set(host_lib, name, SURF_CPU_LEVEL, cpu); +} NetworkLinkDynar getRoute(char *srcName, char *dstName) { RoutingEdge *src = (RoutingEdge*)xbt_lib_get_or_null(host_lib, srcName, ROUTING_HOST_LEVEL); diff --git a/src/bindings/java/surf_swig.hpp b/src/bindings/java/surf_swig.hpp index 5237a9d8b5..182ec9701a 100644 --- a/src/bindings/java/surf_swig.hpp +++ b/src/bindings/java/surf_swig.hpp @@ -11,11 +11,16 @@ #include "src/surf/maxmin_private.hpp" typedef xbt_dynar_t NetworkLinkDynar; - double getClock(); void clean(); +CpuModel *getCpuModel(); +void setCpuModel(CpuModel *cpuModel); + +void setCpu(char *name, Cpu *cpu); + + NetworkLinkDynar getRoute(char *srcName, char *dstName); class Plugin { diff --git a/src/include/surf/surf.h b/src/include/surf/surf.h index 51708d0007..701ae8c4bf 100644 --- a/src/include/surf/surf.h +++ b/src/include/surf/surf.h @@ -102,7 +102,7 @@ typedef WorkstationCLM03 *surf_workstation_CLM03_t; typedef NetworkCm02Link *surf_network_link_t; typedef Cpu *surf_cpu_t; -/** @ingroup SURF_c_bindings +/** @ingroup SURF_c_bindings * \brief Action structure * * Never create s_surf_action_t by yourself ! The actions are created @@ -165,8 +165,8 @@ typedef enum { } e_surf_action_state_t; /** @ingroup SURF_vm_interface - * - * + * + * */ /* FIXME: Where should the VM state be defined? */ typedef enum { @@ -217,9 +217,9 @@ XBT_PUBLIC(void) surf_as_cluster_set_backbone(AS_t as, void* backbone); /** @{ @ingroup SURF_c_bindings */ -/** +/** * @brief Get the name of a surf model - * + * * @param model A model * @return The name of the model */ @@ -227,7 +227,7 @@ XBT_PUBLIC(const char *) surf_model_name(surf_model_t model); /** * @brief Pop an action from the done actions set - * + * * @param model The model from which the action is extracted * @return An action in done state */ @@ -235,7 +235,7 @@ XBT_PUBLIC(surf_action_t) surf_model_extract_done_action_set(surf_model_t model) /** * @brief Pop an action from the failed actions set - * + * * @param model The model from which the action is extracted * @return An action in failed state */ @@ -243,7 +243,7 @@ XBT_PUBLIC(surf_action_t) surf_model_extract_failed_action_set(surf_model_t mode /** * @brief Pop an action from the ready actions set - * + * * @param model The model from which the action is extracted * @return An action in ready state */ @@ -251,7 +251,7 @@ XBT_PUBLIC(surf_action_t) surf_model_extract_ready_action_set(surf_model_t model /** * @brief Pop an action from the running actions set - * + * * @param model The model from which the action is extracted * @return An action in running state */ @@ -259,7 +259,7 @@ XBT_PUBLIC(surf_action_t) surf_model_extract_running_action_set(surf_model_t mod /** * @brief Get the size of the running action set of a model - * + * * @param model The model * @return The size of the running action set */ @@ -268,9 +268,9 @@ XBT_PUBLIC(int) surf_model_running_action_set_size(surf_model_t model); /** * @brief Execute a parallel task * @details [long description] - * + * * @param model The model which handle the parallelisation - * @param workstation_nb The number of workstations + * @param workstation_nb The number of workstations * @param workstation_list The list of workstations on which the task is executed * @param computation_amount The processing amount (in flop) needed to process * @param communication_amount The amount of data (in bytes) needed to transfer @@ -286,7 +286,7 @@ XBT_PUBLIC(surf_action_t) surf_workstation_model_execute_parallel_task(surf_work /** * @brief Create a communication between two hosts - * + * * @param model The model which handle the communication * @param src The source host * @param dst The destination host @@ -299,7 +299,7 @@ XBT_PUBLIC(surf_action_t) surf_workstation_model_communicate(surf_workstation_mo /** * @brief Get the route between two hosts * @details [long description] - * + * * @param model The model which handle the routes * @param src The source host * @param dst The destination host @@ -309,7 +309,7 @@ XBT_PUBLIC(xbt_dynar_t) surf_workstation_model_get_route(surf_workstation_model_ /** * @brief Create a new VM on the specified host - * + * * @param name The name of the workstation * @param ind_phys_host The host on which the VM is created */ @@ -318,7 +318,7 @@ XBT_PUBLIC(void) surf_vm_workstation_model_create(const char *name, surf_resourc /** * @brief Create a communication between two routing edges [TODO] * @details [long description] - * + * * @param model The model which handle the communication * @param src The source host * @param dst The destination host @@ -330,7 +330,7 @@ XBT_PUBLIC(surf_action_t) surf_network_model_communicate(surf_network_model_t mo /** * @brief Get the name of a surf resource (cpu, workstation, network, …) - * + * * @param resource The surf resource * @return The name of the surf resource */ @@ -338,7 +338,7 @@ XBT_PUBLIC(const char * ) surf_resource_name(surf_cpp_resource_t resource); /** * @brief Get the properties of a surf resource (cpu, workstation, network, …) - * + * * @param resource The surf resource * @return The properties of the surf resource */ @@ -346,7 +346,7 @@ XBT_PUBLIC(xbt_dict_t) surf_resource_get_properties(surf_cpp_resource_t resource /** * @brief Get the state of a surf resource (cpu, workstation, network, …) - * + * * @param resource The surf resource * @return The state of the surf resource */ @@ -354,7 +354,7 @@ XBT_PUBLIC(e_surf_resource_state_t) surf_resource_get_state(surf_cpp_resource_t /** * @brief Set the state of a surf resource (cpu, workstation, network, …) - * + * * @param resource The surf resource * @param state The new state of the surf resource */ @@ -362,17 +362,17 @@ XBT_PUBLIC(void) surf_resource_set_state(surf_cpp_resource_t resource, e_surf_re /** * @brief Get the speed of the cpu associtated to a workstation - * + * * @param resource The surf workstation * @param load [description] - * + * * @return [description] */ XBT_PUBLIC(double) surf_workstation_get_speed(surf_resource_t resource, double load); /** * @brief Get the available speed of cpu associtated to a workstation - * + * * @param resource The surf workstation * @return [description] */ @@ -380,7 +380,7 @@ XBT_PUBLIC(double) surf_workstation_get_available_speed(surf_resource_t resource /** * @brief Get the number of cores of the cpu associated to a workstation - * + * * @param resource The surf workstation * @return The number of cores */ @@ -391,14 +391,14 @@ XBT_PUBLIC(int) surf_workstation_get_core(surf_resource_t resource); * * @param resource The surf workstation * @param size The value of the processing amount (in flop) needed to process - * + * * @return The surf action corresponding to the processing */ XBT_PUBLIC(surf_action_t) surf_workstation_execute(surf_resource_t resource, double size); /** * @brief Make the workstation sleep - * + * * @param resource The surf workstation * @param duration The number of seconds to sleep * @return The surf action corresponding to the sleep @@ -407,7 +407,7 @@ XBT_PUBLIC(surf_action_t) surf_workstation_sleep(surf_resource_t resource, doubl /** * @brief Open a file on a workstation - * + * * @param workstation The surf workstation * @param fullpath The path to the file * @return The surf action corresponding to the openning @@ -416,17 +416,17 @@ XBT_PUBLIC(surf_action_t) surf_workstation_open(surf_resource_t workstation, con /** * @brief Close a file descriptor on a workstation - * + * * @param workstation The surf workstation * @param fd The file descriptor - * + * * @return The surf action corresponding to the closing */ XBT_PUBLIC(surf_action_t) surf_workstation_close(surf_resource_t workstation, surf_file_t fd); /** * @brief Read a file - * + * * @param resource The surf workstation * @param fd The file descriptor to read * @param size The size in bytes to read @@ -436,7 +436,7 @@ XBT_PUBLIC(surf_action_t) surf_workstation_read(surf_resource_t resource, surf_f /** * @brief Write a file - * + * * @param resource The surf workstation * @param fd The file descriptor to write * @param size The size in bytes to write @@ -452,7 +452,7 @@ XBT_PUBLIC(surf_action_t) surf_workstation_write(surf_resource_t resource, surf_ * - the storage name, * - the storage typeId, * - the storage content type - * + * * @param resource The surf workstation * @param fd The file descriptor * @return An xbt_dynar_t with the file informations @@ -461,7 +461,7 @@ XBT_PUBLIC(xbt_dynar_t) surf_workstation_get_info(surf_resource_t resource, surf /** * @brief Get the available space of the storage at the mount point - * + * * @param resource The surf workstation * @param name The mount point * @return The amount of availble space in bytes @@ -470,7 +470,7 @@ XBT_PUBLIC(sg_size_t) surf_workstation_get_free_size(surf_resource_t resource, c /** * @brief Get the used space of the storage at the mount point - * + * * @param resource The surf workstation * @param name The mount point * @return The amount of used space in bytes @@ -479,7 +479,7 @@ XBT_PUBLIC(sg_size_t) surf_workstation_get_used_size(surf_resource_t resource, c /** * @brief Get the VMs hosted on the workstation - * + * * @param resource The surf workstation * @return The list of VMs on the workstation */ @@ -488,7 +488,7 @@ XBT_PUBLIC(xbt_dynar_t) surf_workstation_get_vms(surf_resource_t resource); /** * @brief [brief description] * @details [long description] - * + * * @param resource [description] * @param params [description] */ @@ -497,7 +497,7 @@ XBT_PUBLIC(void) surf_workstation_get_params(surf_resource_t resource, ws_params /** * @brief [brief description] * @details [long description] - * + * * @param resource [description] * @param params [description] */ @@ -505,42 +505,42 @@ XBT_PUBLIC(void) surf_workstation_set_params(surf_resource_t resource, ws_params /** * @brief Destroy a Workstation VM - * + * * @param resource The surf workstation vm */ XBT_PUBLIC(void) surf_vm_workstation_destroy(surf_resource_t resource); /** * @brief Suspend a Workstation VM - * + * * @param resource The surf workstation vm */ XBT_PUBLIC(void) surf_vm_workstation_suspend(surf_resource_t resource); /** * @brief Resume a Workstation VM - * + * * @param resource The surf workstation vm */ XBT_PUBLIC(void) surf_vm_workstation_resume(surf_resource_t resource); /** * @brief Save the Workstation VM (Not yet implemented) - * + * * @param resource The surf workstation vm */ XBT_PUBLIC(void) surf_vm_workstation_save(surf_resource_t resource); /** * @brief Restore the Workstation VM (Not yet implemented) - * + * * @param resource The surf workstation vm */ XBT_PUBLIC(void) surf_vm_workstation_restore(surf_resource_t resource); /** * @brief Migrate the VM to the destination host - * + * * @param resource The surf workstation vm * @param ind_vm_ws_dest The destination host */ @@ -548,7 +548,7 @@ XBT_PUBLIC(void) surf_vm_workstation_migrate(surf_resource_t resource, surf_reso /** * @brief Get the physical machine hosting the VM - * + * * @param resource The surf workstation vm * @return The physical machine hosting the VM */ @@ -557,7 +557,7 @@ XBT_PUBLIC(surf_resource_t) surf_vm_workstation_get_pm(surf_resource_t resource) /** * @brief [brief description] * @details [long description] - * + * * @param resource [description] * @param bound [description] */ @@ -566,7 +566,7 @@ XBT_PUBLIC(void) surf_vm_workstation_set_bound(surf_resource_t resource, double /** * @brief [brief description] * @details [long description] - * + * * @param resource [description] * @param cpu [description] * @param mask [description] @@ -575,7 +575,7 @@ XBT_PUBLIC(void) surf_vm_workstation_set_affinity(surf_resource_t resource, surf /** * @brief Execute some quantity of computation - * + * * @param cpu The surf cpu * @param size The value of the processing amount (in flop) needed to process * @return The surf action corresponding to the processing @@ -585,7 +585,7 @@ XBT_PUBLIC(surf_action_t) surf_cpu_execute(surf_resource_t cpu, double size); /** * @brief Make the cpu sleep for duration (in seconds) * @details [long description] - * + * * @param cpu The surf cpu * @param duration The number of seconds to sleep * @return The surf action corresponding to the sleeping @@ -595,7 +595,7 @@ XBT_PUBLIC(surf_action_t) surf_cpu_sleep(surf_resource_t cpu, double duration); /** * @brief Get the workstation power peak * @details [long description] - * + * * @param host The surf workstation * @return The power peak */ @@ -604,10 +604,10 @@ XBT_PUBLIC(double) surf_workstation_get_current_power_peak(surf_resource_t host) /** * @brief [brief description] * @details [long description] - * + * * @param host [description] * @param pstate_index [description] - * + * * @return [description] */ XBT_PUBLIC(double) surf_workstation_get_power_peak_at(surf_resource_t host, int pstate_index); @@ -615,7 +615,7 @@ XBT_PUBLIC(double) surf_workstation_get_power_peak_at(surf_resource_t host, int /** * @brief [brief description] * @details [long description] - * + * * @param host [description] * @return [description] */ @@ -624,7 +624,7 @@ XBT_PUBLIC(int) surf_workstation_get_nb_pstates(surf_resource_t host); /** * @brief [brief description] * @details [long description] - * + * * @param host [description] * @param pstate_index [description] */ @@ -632,7 +632,7 @@ XBT_PUBLIC(void) surf_workstation_set_power_peak_at(surf_resource_t host, int ps /** * @brief Get the consumed energy (in joules) of a workstation - * + * * @param host The surf workstation * @return The consumed energy */ @@ -640,7 +640,7 @@ XBT_PUBLIC(double) surf_workstation_get_consumed_energy(surf_resource_t host); /** * @brief Get the list of storages mounted on a workstation - * + * * @param workstation The surf workstation * @return Dictionary of mount point, Storage */ @@ -656,27 +656,27 @@ XBT_PUBLIC(xbt_dynar_t) surf_workstation_get_attached_storage_list(surf_resource /** * @brief Unlink a file descriptor - * + * * @param workstation The surf workstation * @param fd The file descriptor - * + * * @return 0 if failed to unlink, 1 otherwise */ XBT_PUBLIC(int) surf_workstation_unlink(surf_resource_t workstation, surf_file_t fd); /** * @brief Get the size of a file on a workstation - * + * * @param workstation The surf workstation * @param fd The file descriptor - * + * * @return The size in bytes of the file */ XBT_PUBLIC(size_t) surf_workstation_get_size(surf_resource_t workstation, surf_file_t fd); /** * @brief Get the current position of the file descriptor - * + * * @param workstation The surf workstation * @param fd The file descriptor * @return The current position of the file descriptor @@ -698,7 +698,7 @@ XBT_PUBLIC(int) surf_workstation_file_move(surf_resource_t workstation, surf_fil /** * @brief Set the position indictator assiociated with the file descriptor to a new position * @details [long description] - * + * * @param workstation The surf workstation * @param fd The file descriptor * @param offset The offset from the origin @@ -713,7 +713,7 @@ XBT_PUBLIC(int) surf_workstation_file_seek(surf_resource_t workstation, surf_fil /** * @brief [brief description] * @details [long description] - * + * * @param link [description] * @return [description] */ @@ -721,7 +721,7 @@ XBT_PUBLIC(int) surf_network_link_is_shared(surf_cpp_resource_t link); /** * @brief Get the bandwidth of a link in bytes per second - * + * * @param link The surf link * @return The bandwidth in bytes per second */ @@ -729,7 +729,7 @@ XBT_PUBLIC(double) surf_network_link_get_bandwidth(surf_cpp_resource_t link); /** * @brief Get the latency of a link in seconds - * + * * @param link The surf link * @return The latency in seconds */ @@ -737,7 +737,7 @@ XBT_PUBLIC(double) surf_network_link_get_latency(surf_cpp_resource_t link); /** * @brief Get the content of a storage - * + * * @param resource The surf storage * @return A xbt_dict_t with path as keys and size in bytes as values */ @@ -745,7 +745,7 @@ XBT_PUBLIC(xbt_dict_t) surf_storage_get_content(surf_resource_t resource); /** * @brief Get the size in bytes of a storage - * + * * @param resource The surf storage * @return The size in bytes of the storage */ @@ -753,7 +753,7 @@ XBT_PUBLIC(sg_size_t) surf_storage_get_size(surf_resource_t resource); /** * @brief Get the data associated to the action - * + * * @param action The surf action * @return The data associated to the action */ @@ -762,7 +762,7 @@ XBT_PUBLIC(void*) surf_action_get_data(surf_action_t action); /** * @brief Set the data associated to the action * @details [long description] - * + * * @param action The surf action * @param data The new data associated to the action */ @@ -770,14 +770,14 @@ XBT_PUBLIC(void) surf_action_set_data(surf_action_t action, void *data); /** * @brief Unreference an action - * + * * @param action The surf action */ XBT_PUBLIC(void) surf_action_unref(surf_action_t action); /** * @brief Get the start time of an action - * + * * @param action The surf action * @return The start time in seconds from the beginning of the simulation */ @@ -785,7 +785,7 @@ XBT_PUBLIC(double) surf_action_get_start_time(surf_action_t action); /** * @brief Get the finish time of an action - * + * * @param action The surf action * @return The finish time in seconds from the beginning of the simulation */ @@ -793,7 +793,7 @@ XBT_PUBLIC(double) surf_action_get_finish_time(surf_action_t action); /** * @brief Get the remains amount of work to do of an action - * + * * @param action The surf action * @return The remains amount of work to do */ @@ -801,21 +801,21 @@ XBT_PUBLIC(double) surf_action_get_remains(surf_action_t action); /** * @brief Suspend an action - * + * * @param action The surf action */ XBT_PUBLIC(void) surf_action_suspend(surf_action_t action); /** * @brief Resume an action - * + * * @param action The surf action */ XBT_PUBLIC(void) surf_action_resume(surf_action_t action); /** * @brief Cancel an action - * + * * @param action The surf action */ XBT_PUBLIC(void) surf_action_cancel(surf_action_t action); @@ -823,7 +823,7 @@ XBT_PUBLIC(void) surf_action_cancel(surf_action_t action); /** * @brief Set the priority of an action * @details [long description] - * + * * @param action The surf action * @param priority The new priority [TODO] */ @@ -832,15 +832,15 @@ XBT_PUBLIC(void) surf_action_set_priority(surf_action_t action, double priority) /** * @brief Set the category of an action * @details [long description] - * + * * @param action The surf action * @param category The new category of the action */ XBT_PUBLIC(void) surf_action_set_category(surf_action_t action, const char *category); /** - * @brief Get the state of an action - * + * @brief Get the state of an action + * * @param action The surf action * @return The state of the action */ @@ -848,7 +848,7 @@ XBT_PUBLIC(e_surf_action_state_t) surf_action_get_state(surf_action_t action); /** * @brief Get the cost of an action - * + * * @param action The surf action * @return The cost of the action */ @@ -857,7 +857,7 @@ XBT_PUBLIC(double) surf_action_get_cost(surf_action_t action); /** * @brief [brief desrciption] * @details [long description] - * + * * @param action The surf cpu action * @param cpu [description] * @param mask [description] @@ -867,7 +867,7 @@ XBT_PUBLIC(void) surf_cpu_action_set_affinity(surf_action_t action, surf_resourc /** * @brief [brief description] * @details [long description] - * + * * @param action The surf cpu action * @param bound [description] */ @@ -883,7 +883,7 @@ XBT_PUBLIC(double) surf_network_action_get_latency_limited(surf_action_t action) /** * @brief Get the file associated to a storage action - * + * * @param action The surf storage action * @return The file associated to a storage action */ @@ -891,7 +891,7 @@ XBT_PUBLIC(surf_file_t) surf_storage_action_get_file(surf_action_t action); /** * @brief Get the result dictionary of an ls action - * + * * @param action The surf storage action * @return The dictionry listing a path */ @@ -914,6 +914,9 @@ XBT_PUBLIC(surf_model_t) surf_resource_model(const void *host, int level); /* Implementations of model object */ /**************************************/ +XBT_PUBLIC_DATA(int) autoload_surf_cpu_model; +extern void_f_void_t surf_cpu_model_init_preparse; + /** \ingroup SURF_models * \brief The CPU model object for the physical machine layer */ @@ -1207,7 +1210,7 @@ XBT_PUBLIC(xbt_dict_t) watched_hosts_lib; /*******************************************/ /*** SURF Platform *************************/ /*******************************************/ -XBT_PUBLIC_DATA(AS_t) surf_AS_get_routing_root(void); +XBT_PUBLIC_DATA(AS_t) surf_AS_get_routing_root(void); XBT_PUBLIC_DATA(const char *) surf_AS_get_name(AS_t as); XBT_PUBLIC_DATA(xbt_dict_t) surf_AS_get_routing_sons(AS_t as); XBT_PUBLIC_DATA(const char *) surf_AS_get_model(AS_t as); @@ -1227,7 +1230,7 @@ XBT_PUBLIC_DATA(e_surf_network_element_type_t) surf_routing_edge_get_rc_type(sg_ * * This function has to be called to initialize the common * structures. Then you will have to create the environment by - * calling + * calling * e.g. surf_workstation_model_init_CM02() * * \see surf_workstation_model_init_CM02(), surf_workstation_model_init_compound(), surf_exit() diff --git a/src/simgrid/sg_config.c b/src/simgrid/sg_config.c index 818aad91bd..ef2a7bbeb0 100644 --- a/src/simgrid/sg_config.c +++ b/src/simgrid/sg_config.c @@ -952,13 +952,17 @@ void surf_config_models_setup() xbt_assert(network_model_name, "Set a network model to use with the 'compound' workstation model"); + if(surf_cpu_model_init_preparse){ + surf_cpu_model_init_preparse(); + } else { + cpu_id = + find_model_description(surf_cpu_model_description, cpu_model_name); + surf_cpu_model_description[cpu_id].model_init_preparse(); + } + network_id = find_model_description(surf_network_model_description, network_model_name); - cpu_id = - find_model_description(surf_cpu_model_description, cpu_model_name); - - surf_cpu_model_description[cpu_id].model_init_preparse(); surf_network_model_description[network_id].model_init_preparse(); } diff --git a/src/surf/cpu_cas01.cpp b/src/surf/cpu_cas01.cpp index a66bacad37..3c6662dda7 100644 --- a/src/surf/cpu_cas01.cpp +++ b/src/surf/cpu_cas01.cpp @@ -17,18 +17,10 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_cpu_cas, surf_cpu, * CallBacks * *************/ -static void parse_cpu_init(sg_platf_host_cbarg_t host){ - ((CpuCas01ModelPtr)surf_cpu_model_pm)->parseInit(host); -} - -static void cpu_add_traces_cpu(){ - surf_cpu_model_pm->addTraces(); -} - static void cpu_define_callbacks() { sg_platf_host_add_cb(parse_cpu_init); - sg_platf_postparse_add_cb(cpu_add_traces_cpu); + sg_platf_postparse_add_cb(add_traces_cpu); } /********* diff --git a/src/surf/cpu_interface.cpp b/src/surf/cpu_interface.cpp index 652259da77..8fbf799a80 100644 --- a/src/surf/cpu_interface.cpp +++ b/src/surf/cpu_interface.cpp @@ -10,9 +10,11 @@ XBT_LOG_EXTERNAL_CATEGORY(surf_kernel); XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_cpu, surf, "Logging specific to the SURF cpu module"); +int autoload_surf_cpu_model = 1; +void_f_void_t surf_cpu_model_init_preparse = NULL; + CpuModelPtr surf_cpu_model_pm; CpuModelPtr surf_cpu_model_vm; - /************* * Callbacks * *************/ @@ -28,9 +30,29 @@ surf_callback(void, CpuPtr) cpuDestructedCallbacks; surf_callback(void, CpuPtr, e_surf_resource_state_t, e_surf_resource_state_t) cpuStateChangedCallbacks; surf_callback(void, CpuActionPtr, e_surf_action_state_t, e_surf_action_state_t) cpuActionStateChangedCallbacks; +void parse_cpu_init(sg_platf_host_cbarg_t host){ + surf_cpu_model_pm->parseInit(host); +} + +void add_traces_cpu(){ + surf_cpu_model_pm->addTraces(); +} + /********* * Model * *********/ +void CpuModel::parseInit(sg_platf_host_cbarg_t host) +{ + createResource(host->id, + host->power_peak, + host->pstate, + host->power_scale, + host->power_trace, + host->core_amount, + host->initial_state, + host->state_trace, + host->properties); +} void CpuModel::updateActionsStateLazy(double now, double /*delta*/) { diff --git a/src/surf/cpu_interface.hpp b/src/surf/cpu_interface.hpp index 4991eb462b..d4f858caf6 100644 --- a/src/surf/cpu_interface.hpp +++ b/src/surf/cpu_interface.hpp @@ -54,6 +54,10 @@ XBT_PUBLIC_DATA( surf_callback(void, CpuPtr, e_surf_resource_state_t, e_surf_res */ XBT_PUBLIC_DATA( surf_callback(void, CpuActionPtr, e_surf_action_state_t, e_surf_action_state_t)) cpuActionStateChangedCallbacks; +void parse_cpu_init(sg_platf_host_cbarg_t host); + +void add_traces_cpu(); + /********* * Model * *********/ @@ -78,8 +82,14 @@ public: * * @return The created Cpu */ - CpuPtr createResource(string name); - + void parseInit(sg_platf_host_cbarg_t host); + + virtual CpuPtr createResource(const char *name, xbt_dynar_t power_peak, + int pstate, double power_scale, + tmgr_trace_t power_trace, int core, + e_surf_resource_state_t state_initial, + tmgr_trace_t state_trace, + xbt_dict_t cpu_properties)=0; void setState(e_surf_resource_state_t state); void updateActionsStateLazy(double now, double delta); diff --git a/src/surf/cpu_ti.cpp b/src/surf/cpu_ti.cpp index c4bf40422c..5c083d5929 100644 --- a/src/surf/cpu_ti.cpp +++ b/src/surf/cpu_ti.cpp @@ -119,7 +119,7 @@ double CpuTiTgmr::integrate(double a, double b) /** * \brief Auxiliary function to calculate the integral between a and b. - * It simply calculates the integral at point a and b and returns the difference + * It simply calculates the integral at point a and b and returns the difference * between them. * \param trace Trace structure * \param a Initial point @@ -257,7 +257,7 @@ double CpuTiTgmr::solveSomewhatSimple(double a, double amount) * It returns the date when the requested amount of flops is available * \param trace Trace structure * \param a Initial point - * \param amount Amount of flops + * \param amount Amount of flops * \return The date when amount is available. */ double CpuTiTrace::solveSimple(double a, double amount) @@ -347,7 +347,7 @@ CpuTiTgmr::CpuTiTgmr(tmgr_trace_t power_trace, double value) /** * \brief Binary search in array. - * It returns the first point of the interval in which "a" is. + * It returns the first point of the interval in which "a" is. * \param array Array * \param a Value to search * \param low Low bound to search in array @@ -379,18 +379,10 @@ int CpuTiTrace::binarySearch(double *array, double a, int low, int high) * CallBacks * *************/ -static void parse_cpu_ti_init(sg_platf_host_cbarg_t host){ - ((CpuTiModelPtr)surf_cpu_model_pm)->parseInit(host); -} - -static void add_traces_cpu_ti(){ - surf_cpu_model_pm->addTraces(); -} - static void cpu_ti_define_callbacks() { - sg_platf_host_add_cb(parse_cpu_ti_init); - sg_platf_postparse_add_cb(add_traces_cpu_ti); + sg_platf_host_add_cb(parse_cpu_init); + sg_platf_postparse_add_cb(add_traces_cpu); } /********* @@ -435,20 +427,7 @@ CpuTiModel::~CpuTiModel() xbt_heap_free(p_tiActionHeap); } -void CpuTiModel::parseInit(sg_platf_host_cbarg_t host) -{ - createResource(host->id, - host->power_peak, - host->pstate, - host->power_scale, - host->power_trace, - host->core_amount, - host->initial_state, - host->state_trace, - host->properties); -} - -CpuTiPtr CpuTiModel::createResource(const char *name, +CpuPtr CpuTiModel::createResource(const char *name, xbt_dynar_t powerPeak, int pstate, double powerScale, @@ -571,8 +550,8 @@ CpuTi::CpuTi(CpuTiModelPtr model, const char *name, xbt_dynar_t powerPeak, setState(stateInitial); m_powerScale = powerScale; m_core = core; - tmgr_trace_t empty_trace; - s_tmgr_event_t val; + tmgr_trace_t empty_trace; + s_tmgr_event_t val; xbt_assert(core==1,"Multi-core not handled with this model yet"); XBT_DEBUG("power scale %f", powerScale); p_availTrace = new CpuTiTgmr(powerTrace, powerScale); @@ -593,7 +572,7 @@ CpuTi::CpuTi(CpuTiModelPtr model, const char *name, xbt_dynar_t powerPeak, if (stateTrace) p_stateEvent = tmgr_history_add_trace(history, stateTrace, 0.0, 0, static_cast(this)); if (powerTrace && xbt_dynar_length(powerTrace->s_list.event_list) > 1) { - // add a fake trace event if periodicity == 0 + // add a fake trace event if periodicity == 0 xbt_dynar_get_cpy(powerTrace->s_list.event_list, xbt_dynar_length(powerTrace->s_list.event_list) - 1, &val); if (val.delta == 0) { @@ -886,7 +865,7 @@ void CpuTiAction::updateIndexHeap(int i) void CpuTiAction::setState(e_surf_action_state_t state) { - Action::setState(state); + CpuAction::setState(state); xbt_swag_insert(p_cpu, reinterpret_cast(getModel())->p_modifiedCpu); } diff --git a/src/surf/cpu_ti.hpp b/src/surf/cpu_ti.hpp index 752754a285..1361b0ef4b 100644 --- a/src/surf/cpu_ti.hpp +++ b/src/surf/cpu_ti.hpp @@ -50,7 +50,7 @@ private: }; enum trace_type { - + TRACE_FIXED, /*< Trace fixed, no availability file */ TRACE_DYNAMIC /*< Dynamic, availability file disponible */ }; @@ -86,7 +86,7 @@ public: ~CpuTiModel(); void parseInit(sg_platf_host_cbarg_t host); - CpuTiPtr createResource(const char *name, xbt_dynar_t powerPeak, + CpuPtr createResource(const char *name, xbt_dynar_t powerPeak, int pstate, double power_scale, tmgr_trace_t power_trace, int core, e_surf_resource_state_t state_initial, @@ -121,7 +121,7 @@ public: xbt_dict_t properties) ; ~CpuTi(); - void updateState(tmgr_trace_event_t event_type, double value, double date); + void updateState(tmgr_trace_event_t event_type, double value, double date); void updateActionsFinishTime(double now); bool isUsed(); void printCpuTiModel(); diff --git a/src/surf/workstation_ptask_L07.cpp b/src/surf/workstation_ptask_L07.cpp index d964ddf188..d34b521246 100644 --- a/src/surf/workstation_ptask_L07.cpp +++ b/src/surf/workstation_ptask_L07.cpp @@ -287,19 +287,21 @@ xbt_dynar_t WorkstationL07Model::getRoute(WorkstationPtr src, WorkstationPtr dst return route; } -ResourcePtr CpuL07Model::createResource(const char *name, double power_scale, - double power_initial, - tmgr_trace_t power_trace, - e_surf_resource_state_t state_initial, - tmgr_trace_t state_trace, - xbt_dict_t cpu_properties) +CpuPtr CpuL07Model::createResource(const char *name, xbt_dynar_t powerPeak, + int pstate, double power_scale, + tmgr_trace_t power_trace, int core, + e_surf_resource_state_t state_initial, + tmgr_trace_t state_trace, + xbt_dict_t cpu_properties) { + double power_initial = xbt_dynar_get_as(powerPeak, pstate, double); + xbt_assert(!surf_workstation_resource_priv(surf_workstation_resource_by_name(name)), "Host '%s' declared several times in the platform file.", name); CpuL07Ptr cpu = new CpuL07(this, name, cpu_properties, - power_scale, power_initial, power_trace,state_initial, state_trace); + power_initial, power_scale, power_trace,state_initial, state_trace); xbt_lib_set(host_lib, name, SURF_CPU_LEVEL, static_cast(cpu)); @@ -749,21 +751,6 @@ static void ptask_parse_workstation_init(sg_platf_host_cbarg_t host) host->properties); } -static void ptask_parse_cpu_init(sg_platf_host_cbarg_t host) -{ - double power_peak = xbt_dynar_get_as(host->power_peak, host->pstate, double); - static_cast(surf_cpu_model_pm)->createResource( - host->id, - power_peak, - host->power_scale, - host->power_trace, - host->initial_state, - host->state_trace, - host->properties); -} - - - static void ptask_parse_link_init(sg_platf_link_cbarg_t link) { if (link->policy == SURF_LINK_FULLDUPLEX) { @@ -813,7 +800,7 @@ static void ptask_add_traces(){ static void ptask_define_callbacks() { - sg_platf_host_add_cb(ptask_parse_cpu_init); + sg_platf_host_add_cb(parse_cpu_init); sg_platf_host_add_cb(ptask_parse_workstation_init); sg_platf_link_add_cb(ptask_parse_link_init); sg_platf_postparse_add_cb(ptask_add_traces); diff --git a/src/surf/workstation_ptask_L07.hpp b/src/surf/workstation_ptask_L07.hpp index 9bcac9fe0f..f6b00b1ac4 100644 --- a/src/surf/workstation_ptask_L07.hpp +++ b/src/surf/workstation_ptask_L07.hpp @@ -75,6 +75,12 @@ public: e_surf_resource_state_t state_initial, tmgr_trace_t state_trace, xbt_dict_t cpu_properties); + CpuPtr createResource(const char *name, xbt_dynar_t powerPeak, + int pstate, double power_scale, + tmgr_trace_t power_trace, int core, + e_surf_resource_state_t state_initial, + tmgr_trace_t state_trace, + xbt_dict_t cpu_properties); void addTraces() {DIE_IMPOSSIBLE;}; WorkstationL07ModelPtr p_workstationModel; diff --git a/teshsuite/simdag/platforms/flatifier.c b/teshsuite/simdag/platforms/flatifier.c index e0762b0f07..128b9b7857 100644 --- a/teshsuite/simdag/platforms/flatifier.c +++ b/teshsuite/simdag/platforms/flatifier.c @@ -116,7 +116,7 @@ int main(int argc, char **argv) if (parse_cmdline(&timings, &downgrade, &platformFile, argc, argv) || !platformFile) { xbt_die("Invalid command line arguments: expected [--timings|--downgrade] platformFile"); } - + XBT_DEBUG("%d,%d,%s", timings, downgrade, platformFile); if (downgrade) {