Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge pull request #45 from mpoquet/master
authorMartin Quinson <martin.quinson@ens-rennes.fr>
Thu, 7 Jan 2016 21:52:53 +0000 (22:52 +0100)
committerMartin Quinson <martin.quinson@ens-rennes.fr>
Thu, 7 Jan 2016 21:52:53 +0000 (22:52 +0100)
Patch candidate for issue 15

54 files changed:
examples/msg/bittorrent/bittorrent_platfgen.c
examples/msg/energy/vm/energy_vm.tesh
examples/msg/masterslave/masterslave_failure_platfgen.c
examples/msg/masterslave/masterslave_platfgen.c
include/simgrid/Host.hpp
include/simgrid/forward.h
include/simgrid/host.h
include/simgrid/platf.h
src/bindings/lua/lua_platf.c
src/include/surf/surf.h
src/msg/msg_host.cpp
src/s4u/s4u_host.cpp
src/simgrid/host.cpp
src/simix/smx_host.cpp
src/simix/smx_host_private.h
src/simix/smx_io.cpp
src/simix/smx_network.cpp
src/simix/smx_process.cpp
src/simix/smx_vm.cpp
src/surf/cpu_cas01.cpp
src/surf/cpu_cas01.hpp
src/surf/cpu_interface.cpp
src/surf/cpu_interface.hpp
src/surf/cpu_ti.cpp
src/surf/cpu_ti.hpp
src/surf/host_interface.cpp
src/surf/host_interface.hpp
src/surf/host_ptask_L07.cpp
src/surf/host_ptask_L07.hpp
src/surf/network_cm02.cpp
src/surf/network_cm02.hpp
src/surf/network_constant.hpp
src/surf/network_interface.cpp
src/surf/network_interface.hpp
src/surf/network_ns3.cpp
src/surf/network_ns3.hpp
src/surf/plugins/energy.cpp
src/surf/sg_platf.cpp
src/surf/storage_interface.cpp
src/surf/storage_interface.hpp
src/surf/storage_n11.cpp
src/surf/surf_c_bindings.cpp
src/surf/surf_interface.cpp
src/surf/surf_interface.hpp
src/surf/surf_routing.cpp
src/surf/surf_routing_cluster.cpp
src/surf/surf_routing_cluster_fat_tree.cpp
src/surf/surf_routing_cluster_torus.cpp
src/surf/surfxml_parse.c
src/surf/trace_mgr.c
src/surf/virtual_machine.cpp
src/surf/virtual_machine.hpp
src/surf/vm_hl13.cpp
src/surf/vm_hl13.hpp

index b15116b..16c0e65 100644 (file)
@@ -38,7 +38,7 @@ void promoter(context_node_t node)
     host_parameters.core_amount = 1;
     host_parameters.speed_scale = 1;
     host_parameters.speed_trace = NULL;
-    host_parameters.initial_state = SURF_RESOURCE_ON;
+    host_parameters.initiallyOn = 1;
     host_parameters.state_trace = NULL;
     host_parameters.coord = NULL;
     host_parameters.properties = NULL;
@@ -60,7 +60,7 @@ void labeler(context_edge_t edge)
   //Latency from 0ms to 100ms
   link_parameters.latency = RngStream_RandU01(rng_stream) / 10.0;
   link_parameters.latency_trace = NULL;
-  link_parameters.state = SURF_RESOURCE_ON;
+  link_parameters.initiallyOn = 1;
   link_parameters.state_trace = NULL;
   link_parameters.policy = SURF_LINK_SHARED;
   link_parameters.properties = NULL;
index bb5b408..975a6ba 100644 (file)
@@ -18,6 +18,6 @@ $ $SG_TEST_EXENV energy/vm/energy_vm$EXEEXT ${srcdir:=.}/../platforms/energy_pla
 > [  6.000000] (6:p31@vm_host3) This worker is done.
 > [  6.000000] (7:p32@vm_host3) This worker is done.
 > [ 10.000000] (0:@) Total simulation time: 10.00; All hosts must have the exact same energy consumption.
+> [ 10.000000] (0:@) Total energy of host MyHost1: 1600.000000 Joules
 > [ 10.000000] (0:@) Total energy of host MyHost2: 1600.000000 Joules
-> [ 10.000000] (0:@) Total energy of host vm_host1: 1600.000000 Joules
-> [ 10.000000] (0:@) Total energy of host vm_host3: 1600.000000 Joules
+> [ 10.000000] (0:@) Total energy of host MyHost3: 1600.000000 Joules
index 28e8fdf..c3f3c5c 100644 (file)
@@ -46,7 +46,7 @@ void promoter_1(context_node_t node) {
   host_parameters.core_amount = 1;
   host_parameters.speed_scale = 1;
   host_parameters.speed_trace = NULL;
-  host_parameters.initial_state = SURF_RESOURCE_ON;
+  host_parameters.initiallyOn = 1;
   host_parameters.state_trace = NULL;
   host_parameters.coord = NULL;
   host_parameters.properties = NULL;
@@ -83,7 +83,7 @@ void labeler_1(context_edge_t edge) {
   link_parameters.bandwidth_trace = NULL;
   link_parameters.latency = 0.01;
   link_parameters.latency_trace = NULL;
-  link_parameters.state = SURF_RESOURCE_ON;
+  link_parameters.initiallyOn = 1;
   link_parameters.state_trace = NULL;
   link_parameters.policy = SURF_LINK_SHARED;
   link_parameters.properties = NULL;
@@ -100,7 +100,7 @@ void labeler_1(context_edge_t edge) {
               tmgr_trace_generator_avail_unavail(bprintf("state_link_%ld", edge->id),
                                                 avail_generator,
                                                 unavail_generator,
-                                                SURF_RESOURCE_ON);
+                                                1/*ON*/);
 
 
   platf_graph_link_label(edge, &link_parameters);
index 06db03e..e2496d9 100644 (file)
@@ -33,7 +33,7 @@ void promoter_1(context_node_t node) {
   host_parameters.core_amount = 1;
   host_parameters.speed_scale = 1;
   host_parameters.speed_trace = NULL;
-  host_parameters.initial_state = SURF_RESOURCE_ON;
+  host_parameters.initiallyOn = 1;
   host_parameters.state_trace = NULL;
   host_parameters.coord = NULL;
   host_parameters.properties = NULL;
@@ -52,7 +52,7 @@ void labeler_1(context_edge_t edge) {
   link_parameters.bandwidth_trace = NULL;
   link_parameters.latency = 0.01;
   link_parameters.latency_trace = NULL;
-  link_parameters.state = SURF_RESOURCE_ON;
+  link_parameters.initiallyOn = 1;
   link_parameters.state_trace = NULL;
   link_parameters.policy = SURF_LINK_SHARED;
   link_parameters.properties = NULL;
index fb2a509..3e82229 100644 (file)
@@ -40,7 +40,8 @@ public:
   simgrid::xbt::string const& getName() const { return name_; }
   void on();
   void off();
-  e_surf_resource_state_t getState();
+  bool isOn();
+  bool isOff();
   xbt_dict_t getProperties();
   xbt_swag_t getProcessList();
   double getCurrentPowerPeak();
index 5c4cc38..2961972 100644 (file)
@@ -54,13 +54,6 @@ typedef struct tmgr_trace *tmgr_trace_t; /**< Opaque structure defining an avail
 
 typedef void *sg_routing_link_t; /* FIXME:The actual type is model-dependent so use void* instead*/
 
-/** @ingroup SURF_interface
-* @brief Defines whether a given resource is working or not */
-typedef enum {
-  SURF_RESOURCE_ON = 1,                   /**< Up & ready        */
-  SURF_RESOURCE_OFF = 0                   /**< Down & broken     */
-} e_surf_resource_state_t;
-
 typedef enum {
   SURF_LINK_FULLDUPLEX = 2,
   SURF_LINK_SHARED = 1,
@@ -114,14 +107,14 @@ typedef struct {
   int core_amount;
   double speed_scale;
   tmgr_trace_t speed_trace;
-  e_surf_resource_state_t initial_state;
+  int initiallyOn;
   tmgr_trace_t state_trace;
   const char* coord;
   xbt_dict_t properties;
 } s_sg_platf_host_cbarg_t, *sg_platf_host_cbarg_t;
 
 #define SG_PLATF_HOST_INITIALIZER { \
-    NULL, 0, 1, 1, 1., NULL, SURF_RESOURCE_ON, NULL, \
+    NULL, 0, 1, 1, 1., NULL, 1/*ON*/, NULL, \
     NULL, NULL \
 }
 
@@ -146,14 +139,14 @@ typedef struct {
   tmgr_trace_t bandwidth_trace;
   double latency;
   tmgr_trace_t latency_trace;
-  e_surf_resource_state_t state;
+  int initiallyOn;
   tmgr_trace_t state_trace;
   e_surf_link_sharing_policy_t policy;
   xbt_dict_t properties;
 } s_sg_platf_link_cbarg_t, *sg_platf_link_cbarg_t;
 
 #define SG_PLATF_LINK_INITIALIZER {\
-  NULL, 0., NULL, 0., NULL, SURF_RESOURCE_ON, \
+  NULL, 0., NULL, 0., NULL, 1/*ON*/, \
   NULL, SURF_LINK_SHARED, NULL \
 }
 
index cd948d6..428e2b7 100644 (file)
@@ -56,7 +56,7 @@ XBT_PUBLIC(void) sg_host_init(void);
 
 // =========== user-level functions ===============
 XBT_PUBLIC(double) sg_host_get_available_speed(sg_host_t host);
-XBT_PUBLIC(int) sg_host_get_state(sg_host_t host);
+XBT_PUBLIC(int) sg_host_is_on(sg_host_t host);
 
 XBT_PUBLIC(int) sg_host_get_nb_pstates(sg_host_t host);
 XBT_PUBLIC(int) sg_host_get_pstate(sg_host_t host);
index c080e77..5b57f6b 100644 (file)
@@ -31,11 +31,11 @@ XBT_PUBLIC(tmgr_trace_t) tmgr_trace_generator_value(const char *id,
                                               probabilist_event_generator_t value_generator);
 XBT_PUBLIC(tmgr_trace_t) tmgr_trace_generator_state(const char *id,
                                               probabilist_event_generator_t date_generator,
-                                              e_surf_resource_state_t first_event_value);
+                                              int first_event_hostIsOn);
 XBT_PUBLIC(tmgr_trace_t) tmgr_trace_generator_avail_unavail(const char *id,
                                               probabilist_event_generator_t avail_duration_generator,
                                               probabilist_event_generator_t unavail_duration_generator,
-                                              e_surf_resource_state_t first_event_value);
+                                              int first_event_hostIsOn);
 
 XBT_PUBLIC(probabilist_event_generator_t) tmgr_event_generator_new_uniform(const char* id,
                                                                            double min,
index 7daa985..d953dfc 100644 (file)
@@ -94,7 +94,7 @@ int console_add_backbone(lua_State *L) {
   link.latency = surf_parse_get_time(lua_tostring(L, -1));
   lua_pop(L, 1);
 
-  link.state = SURF_RESOURCE_ON;
+  link.initiallyOn = 1;
 
   lua_pushstring(L, "sharing_policy");
   type = lua_gettable(L, -2);
@@ -218,9 +218,9 @@ int console_add_host(lua_State *L) {
   lua_pop(L, 1);
 
   if (state)
-    host.initial_state = SURF_RESOURCE_ON;
+    host.initiallyOn = 1;
   else
-    host.initial_state = SURF_RESOURCE_OFF;
+    host.initiallyOn = 0;
 
   //get trace state
   lua_pushstring(L, "state_file");
@@ -297,9 +297,9 @@ int  console_add_link(lua_State *L) {
   lua_pushstring(L, "state");
   lua_gettable(L, -2);
   if (!lua_isnumber(L,-1) || lua_tonumber(L, -1))
-    link.state = SURF_RESOURCE_ON;
+    link.initiallyOn = 1;
   else
-    link.state = SURF_RESOURCE_OFF;
+    link.initiallyOn = 0;
   lua_pop(L, 1);
 
   //get policy value
index 6d3265f..e9ead8a 100644 (file)
@@ -303,12 +303,19 @@ XBT_PUBLIC(xbt_dict_t) sg_host_get_properties(sg_host_t host);
 
 
 /** @brief Get the state of a surf resource (cpu, host, network, …) */
-XBT_PUBLIC(e_surf_resource_state_t) surf_resource_get_state(surf_cpp_resource_t resource);
+XBT_PUBLIC(int) surf_resource_is_on(surf_cpp_resource_t resource);
+/** @brief Get the state of a surf resource (cpu, host, network, …) */
+XBT_PUBLIC(int) surf_resource_is_off(surf_cpp_resource_t resource);
 
 /** @brief Set the state of a surf resource (cpu, host, network, …) */
-XBT_PUBLIC(void) surf_resource_set_state(surf_cpp_resource_t resource, e_surf_resource_state_t state);
-static inline void surf_host_set_state(surf_host_t host, e_surf_resource_state_t state) {
-       surf_resource_set_state((surf_cpp_resource_t)host, state);
+XBT_PUBLIC(void) surf_resource_turn_on(surf_cpp_resource_t resource);
+/** @brief Set the state of a surf resource (cpu, host, network, …) */
+XBT_PUBLIC(void) surf_resource_turn_off(surf_cpp_resource_t resource);
+static inline void surf_host_turn_on(surf_host_t host) {
+  surf_resource_turn_on((surf_cpp_resource_t)host);
+}
+static inline void surf_host_turn_off(surf_host_t host) {
+  surf_resource_turn_off((surf_cpp_resource_t)host);
 }
 
 /** @brief Get the available speed of cpu associated to a host */
index ee9ac40..58a3ba5 100644 (file)
@@ -280,7 +280,7 @@ void MSG_host_set_property_value(msg_host_t host, const char *name, char *value,
 int MSG_host_is_on(msg_host_t host)
 {
   xbt_assert((host != NULL), "Invalid parameters (host is NULL)");
-  return sg_host_get_state(host);
+  return sg_host_is_on(host);
 }
 /** @ingroup m_host_management
  *
@@ -291,7 +291,7 @@ int MSG_host_is_on(msg_host_t host)
 int MSG_host_is_off(msg_host_t host)
 {
   xbt_assert((host != NULL), "Invalid parameters (host is NULL)");
-  return !(sg_host_get_state(host));
+  return !(sg_host_is_on(host));
 }
 
 /** \ingroup m_host_management
index 527dc29..5f7b902 100644 (file)
@@ -59,7 +59,7 @@ void Host::turnOff() {
        p_inferior->off();
 }
 bool Host::isOn() {
-       return sg_host_get_state(p_inferior);
+       return sg_host_is_on(p_inferior);
 }
 
 boost::unordered_map<std::string, Storage&> &Host::mountedStorages() {
index 7f8881b..af13e1a 100644 (file)
@@ -137,8 +137,8 @@ double sg_host_get_available_speed(sg_host_t host){
 /** @brief Returns the state of a host.
  *  @return 1 if the host is active or 0 if it has crashed.
  */
-int sg_host_get_state(sg_host_t host) {
-       return host->p_cpu->getState();
+int sg_host_is_on(sg_host_t host) {
+       return host->p_cpu->isOn();
 }
 
 /** @brief Returns the total energy consumed by the host (in Joules).
@@ -190,8 +190,11 @@ void Host::off()
   simgrid::simix::simcall<void>(SIMCALL_HOST_OFF, this);
 }
 
-e_surf_resource_state_t Host::getState() {
-  return p_cpu->getState();
+bool Host::isOn() {
+  return p_cpu->isOn();
+}
+bool Host::isOff() {
+  return ! p_cpu->isOn();
 }
 
 
index 71bf7a5..57f1fac 100644 (file)
@@ -43,8 +43,8 @@ void SIMIX_host_on(sg_host_t h)
 
   xbt_assert((host != NULL), "Invalid parameters");
 
-  if (h->getState()==SURF_RESOURCE_OFF) {
-    surf_host_set_state(surf_host_resource_priv(h), SURF_RESOURCE_ON);
+  if (h->isOff()) {
+    surf_host_turn_on(surf_host_resource_priv(h));
 
     unsigned int cpt;
     smx_process_arg_t arg;
@@ -96,8 +96,8 @@ void SIMIX_host_off(sg_host_t h, smx_process_t issuer)
 
   xbt_assert((host != NULL), "Invalid parameters");
 
-  if (h->getState()==SURF_RESOURCE_ON) {
-       surf_host_set_state(surf_host_resource_priv(h), SURF_RESOURCE_OFF);
+  if (h->isOn()) {
+    surf_host_turn_off(surf_host_resource_priv(h));
 
     /* Clean Simulator data */
     if (xbt_swag_size(host->process_list) != 0) {
@@ -107,6 +107,8 @@ void SIMIX_host_off(sg_host_t h, smx_process_t issuer)
         XBT_DEBUG("Killing %s on %s by %s", process->name,  sg_host_get_name(process->host), issuer->name);
       }
     }
+  } else {
+    XBT_INFO("Host %s is already off",h->getName().c_str());
   }
 }
 
@@ -240,7 +242,7 @@ void SIMIX_host_add_auto_restart_process(sg_host_t host,
   arg->properties = properties;
   arg->auto_restart = auto_restart;
 
-  if( sg_host_get_state(host) == SURF_RESOURCE_OFF
+  if( ! sg_host_is_on(host)
       && !xbt_dict_get_or_null(watched_hosts_lib,sg_host_get_name(host))){
     xbt_dict_set(watched_hosts_lib,sg_host_get_name(host),host,NULL);
     XBT_DEBUG("Have pushed host %s to watched_hosts_lib because state == SURF_RESOURCE_OFF",sg_host_get_name(host));
@@ -499,7 +501,7 @@ void SIMIX_execution_finish(smx_synchro_t synchro)
             (int)synchro->state);
     }
     /* check if the host is down */
-    if (simcall->issuer->host->getState() != SURF_RESOURCE_ON) {
+    if (simcall->issuer->host->isOff()) {
       simcall->issuer->context->iwannadie = 1;
     }
 
@@ -517,7 +519,7 @@ void SIMIX_post_host_execute(smx_synchro_t synchro)
 {
   if (synchro->type == SIMIX_SYNC_EXECUTE && /* FIMXE: handle resource failure
                                                * for parallel tasks too */
-      synchro->execution.host->getState() == SURF_RESOURCE_OFF) {
+      synchro->execution.host->isOff()) {
     /* If the host running the synchro failed, notice it so that the asking
      * process can be killed if it runs on that host itself */
     synchro->state = SIMIX_FAILED;
index 1cac10f..a0b132c 100644 (file)
@@ -83,7 +83,7 @@ XBT_PRIVATE void SIMIX_vm_start(sg_host_t ind_vm);
 XBT_PRIVATE void SIMIX_vm_shutdown(sg_host_t ind_vm, smx_process_t issuer);
 // --
 
-XBT_PRIVATE int SIMIX_vm_get_state(sg_host_t ind_vm);
+XBT_PRIVATE e_surf_vm_state_t SIMIX_vm_get_state(sg_host_t ind_vm);
 // --
 XBT_PRIVATE void SIMIX_vm_migrate(sg_host_t ind_vm, sg_host_t ind_dst_pm);
 
index 9bac80e..9b1db2b 100644 (file)
@@ -61,7 +61,7 @@ smx_synchro_t SIMIX_file_read(smx_file_t fd, sg_size_t size, sg_host_t host)
   smx_synchro_t synchro;
 
   /* check if the host is active */
-  if (host->getState() != SURF_RESOURCE_ON) {
+  if (host->isOff()) {
     THROWF(host_error, 0, "Host %s failed, you cannot call this function",
            sg_host_get_name(host));
   }
@@ -93,7 +93,7 @@ smx_synchro_t SIMIX_file_write(smx_file_t fd, sg_size_t size, sg_host_t host)
   smx_synchro_t synchro;
 
   /* check if the host is active */
-  if (host->getState() != SURF_RESOURCE_ON) {
+  if (host->isOff()) {
     THROWF(host_error, 0, "Host %s failed, you cannot call this function",
            sg_host_get_name(host));
   }
@@ -125,7 +125,7 @@ smx_synchro_t SIMIX_file_open(const char* fullpath, sg_host_t host)
   smx_synchro_t synchro;
 
   /* check if the host is active */
-  if (host->getState() != SURF_RESOURCE_ON) {
+  if (host->isOff()) {
     THROWF(host_error, 0, "Host %s failed, you cannot call this function",
            sg_host_get_name(host));
   }
@@ -157,7 +157,7 @@ smx_synchro_t SIMIX_file_close(smx_file_t fd, sg_host_t host)
   smx_synchro_t synchro;
 
   /* check if the host is active */
-  if (host->getState() != SURF_RESOURCE_ON) {
+  if (host->isOff()) {
     THROWF(host_error, 0, "Host %s failed, you cannot call this function",
            sg_host_get_name(host));
   }
@@ -181,7 +181,7 @@ smx_synchro_t SIMIX_file_close(smx_file_t fd, sg_host_t host)
 int SIMIX_file_unlink(smx_file_t fd, sg_host_t host)
 {
   /* check if the host is active */
-  if (host->getState() != SURF_RESOURCE_ON) {
+  if (host->isOff()) {
     THROWF(host_error, 0, "Host %s failed, you cannot call this function",
            sg_host_get_name(host));
   }
@@ -373,7 +373,7 @@ void SIMIX_io_finish(smx_synchro_t synchro)
             (int)synchro->state);
     }
 
-    if (simcall->issuer->host->getState() != SURF_RESOURCE_ON) {
+    if (simcall->issuer->host->isOff()) {
       simcall->issuer->context->iwannadie = 1;
     }
 
index 21d5890..4f3c34a 100644 (file)
@@ -792,7 +792,7 @@ void SIMIX_comm_finish(smx_synchro_t synchro)
 
     /* Check out for errors */
 
-    if (simcall->issuer->host->getState() != SURF_RESOURCE_ON) {
+    if (simcall->issuer->host->isOff()) {
       simcall->issuer->context->iwannadie = 1;
       SMX_EXCEPTION(simcall->issuer, host_error, 0, "Host failed");
     } else
@@ -870,7 +870,7 @@ void SIMIX_comm_finish(smx_synchro_t synchro)
       }
     }
 
-    if (simcall->issuer->host->getState() != SURF_RESOURCE_ON) {
+    if (simcall->issuer->host->isOff()) {
       simcall->issuer->context->iwannadie = 1;
     }
 
index 891f989..c939390 100644 (file)
@@ -165,10 +165,8 @@ void SIMIX_create_maestro_process()
 void SIMIX_process_stop(smx_process_t arg) {
   /* execute the on_exit functions */
   SIMIX_process_on_exit_runall(arg);
-  /* Add the process to the list of process to restart, only if
-   * the host is down
-   */
-  if (arg->auto_restart && !sg_host_get_state(arg->host)) {
+  /* Add the process to the list of process to restart, only if the host is down */
+  if (arg->auto_restart && arg->host->isOff()) {
     SIMIX_host_add_auto_restart_process(arg->host,arg->name,arg->code, arg->data,
                                         sg_host_get_name(arg->host),
                                         SIMIX_timer_get_date(arg->kill_timer),
@@ -247,7 +245,7 @@ smx_process_t SIMIX_process_create(
 
   XBT_DEBUG("Start process %s on host '%s'", name, hostname);
 
-  if (!sg_host_get_state(host)) {
+  if (host->isOff()) {
     int i;
     XBT_WARN("Cannot launch process '%s' on failed host '%s'", name,
           hostname);
@@ -770,7 +768,7 @@ smx_synchro_t SIMIX_process_sleep(smx_process_t process, double duration)
   sg_host_t host = process->host;
 
   /* check if the host is active */
-  if (host->getState() != SURF_RESOURCE_ON) {
+  if (host->isOff()) {
     THROWF(host_error, 0, "Host %s failed, you cannot call this function",
            sg_host_get_name(host));
   }
@@ -812,7 +810,7 @@ void SIMIX_post_process_sleep(smx_synchro_t synchro)
         THROW_IMPOSSIBLE;
         break;
     }
-    if (simcall->issuer->host->getState() != SURF_RESOURCE_ON) {
+    if (simcall->issuer->host->isOff()) {
       simcall->issuer->context->iwannadie = 1;
     }
     simcall_process_sleep__set__result(simcall, state);
index ae74934..24cc2b9 100644 (file)
@@ -10,6 +10,7 @@
 #include "xbt/dict.h"
 #include "mc/mc.h"
 #include "src/surf/host_interface.hpp"
+#include "src/surf/virtual_machine.hpp"
 
 //If you need to log some stuffs, just uncomment these two lines and uses XBT_DEBUG for instance
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_vm, simix, "Logging specific to SIMIX (vms)");
@@ -92,16 +93,16 @@ static int __can_be_started(sg_host_t vm)
 void SIMIX_vm_start(sg_host_t ind_vm)
 {
   if (__can_be_started(ind_vm))
-    surf_host_set_state(surf_host_resource_priv(ind_vm),
-                            (e_surf_resource_state_t) SURF_VM_STATE_RUNNING);
+    static_cast<simgrid::surf::VirtualMachine*>(surf_host_resource_priv(ind_vm))
+      ->setState(SURF_VM_STATE_RUNNING);
   else
     THROWF(vm_error, 0, "The VM %s cannot be started", SIMIX_host_get_name(ind_vm));
 }
 
 
-int SIMIX_vm_get_state(sg_host_t ind_vm)
+e_surf_vm_state_t SIMIX_vm_get_state(sg_host_t ind_vm)
 {
-  return surf_host_resource_priv(ind_vm)->getState();
+  return static_cast<simgrid::surf::VirtualMachine*>(surf_host_resource_priv(ind_vm))->getState();
 }
 
 /**
@@ -344,8 +345,7 @@ void SIMIX_vm_shutdown(sg_host_t ind_vm, smx_process_t issuer)
   }
 
   /* FIXME: we may have to do something at the surf layer, e.g., vcpu action */
-  surf_host_set_state(surf_host_resource_priv(ind_vm),
-          (e_surf_resource_state_t) SURF_VM_STATE_CREATED);
+  static_cast<simgrid::surf::VirtualMachine*>(surf_host_resource_priv(ind_vm))->setState(SURF_VM_STATE_CREATED);
 }
 
 void simcall_HANDLER_vm_shutdown(smx_simcall_t simcall, sg_host_t ind_vm)
index d2fb281..ae4a965 100644 (file)
@@ -87,13 +87,13 @@ CpuCas01Model::~CpuCas01Model()
 Cpu *CpuCas01Model::createCpu(simgrid::Host *host, xbt_dynar_t speedPeak,
                                  int pstate, double speedScale,
                           tmgr_trace_t speedTrace, int core,
-                          e_surf_resource_state_t state_initial,
+                          int initiallyOn,
                           tmgr_trace_t state_trace)
 {
   xbt_assert(xbt_dynar_getfirst_as(speedPeak, double) > 0.0,
       "Speed has to be >0.0. Did you forget to specify the mandatory power attribute?");
   xbt_assert(core > 0, "Invalid number of cores %d. Must be larger than 0", core);
-  Cpu *cpu = new CpuCas01(this, host, speedPeak, pstate, speedScale, speedTrace, core, state_initial, state_trace);
+  Cpu *cpu = new CpuCas01(this, host, speedPeak, pstate, speedScale, speedTrace, core, initiallyOn, state_trace);
   return cpu;
 }
 
@@ -139,12 +139,12 @@ void CpuCas01Model::addTraces()
  ************/
 CpuCas01::CpuCas01(CpuCas01Model *model, simgrid::Host *host, xbt_dynar_t speedPeak,
                          int pstate, double speedScale, tmgr_trace_t speedTrace, int core,
-                         e_surf_resource_state_t stateInitial, tmgr_trace_t stateTrace)
+                         int initiallyOn, tmgr_trace_t stateTrace)
 : Cpu(model, host,
        lmm_constraint_new(model->getMaxminSystem(), this, core * speedScale * xbt_dynar_get_as(speedPeak, pstate, double)),
        speedPeak, pstate,
        core, xbt_dynar_get_as(speedPeak, pstate, double), speedScale,
-    stateInitial) {
+    initiallyOn) {
   p_speedEvent = NULL;
 
   XBT_DEBUG("CPU create: peak=%f, pstate=%d", m_speedPeak, m_pstate);
@@ -220,13 +220,13 @@ void CpuCas01::updateState(tmgr_trace_event_t event_type, double value, double d
     xbt_assert(m_core == 1, "FIXME: add state change code also for constraint_core[i]");
 
     if (value > 0) {
-      if(getState() == SURF_RESOURCE_OFF)
+      if(isOff())
         xbt_dynar_push_as(host_that_restart, char*, (char *)getName());
-      setState(SURF_RESOURCE_ON);
+      turnOn();
     } else {
       lmm_constraint_t cnst = getConstraint();
 
-      setState(SURF_RESOURCE_OFF);
+      turnOff();
 
       while ((var = lmm_get_var_from_cnst(getModel()->getMaxminSystem(), cnst, &elem))) {
         Action *action = static_cast<Action*>(lmm_variable_id(var));
@@ -253,7 +253,7 @@ CpuAction *CpuCas01::execute(double size)
 {
 
   XBT_IN("(%s,%g)", getName(), size);
-  CpuCas01Action *action = new CpuCas01Action(getModel(), size, getState() != SURF_RESOURCE_ON,
+  CpuCas01Action *action = new CpuCas01Action(getModel(), size, isOff(),
                                                              m_speedScale * m_speedPeak, getConstraint());
 
   XBT_OUT();
@@ -266,7 +266,7 @@ CpuAction *CpuCas01::sleep(double duration)
     duration = MAX(duration, sg_surf_precision);
 
   XBT_IN("(%s,%g)", getName(), duration);
-  CpuCas01Action *action = new CpuCas01Action(getModel(), 1.0, getState() != SURF_RESOURCE_ON,
+  CpuCas01Action *action = new CpuCas01Action(getModel(), 1.0, isOff(),
                                                       m_speedScale * m_speedPeak, getConstraint());
 
 
index c825a70..30b2bea 100644 (file)
@@ -30,7 +30,7 @@ public:
   Cpu *createCpu(simgrid::Host *host, xbt_dynar_t speedPeak, int pstate,
                    double speedScale,
                           tmgr_trace_t speedTrace, int core,
-                          e_surf_resource_state_t state_initial,
+                          int initiallyOn,
                           tmgr_trace_t state_trace) override;
   double shareResourcesFull(double now) override;
   void addTraces() override;
@@ -45,7 +45,7 @@ class CpuCas01 : public Cpu {
 public:
   CpuCas01(CpuCas01Model *model, simgrid::Host *host, xbt_dynar_t speedPeak,
         int pstate, double speedScale, tmgr_trace_t speedTrace, int core,
-        e_surf_resource_state_t stateInitial, tmgr_trace_t stateTrace) ;
+        int initiallyOn, tmgr_trace_t stateTrace) ;
   ~CpuCas01();
   void updateState(tmgr_trace_event_t event_type, double value, double date) override;
   CpuAction *execute(double size) override;
index 374db5c..ab78cd7 100644 (file)
@@ -134,16 +134,16 @@ void CpuModel::updateActionsStateFull(double now, double delta)
 Cpu::Cpu(Model *model, simgrid::Host *host,
             xbt_dynar_t speedPeakList, int pstate,
                 int core, double speedPeak, double speedScale,
-         e_surf_resource_state_t stateInitial)
- : Cpu(model, host, NULL/*constraint*/, speedPeakList, pstate, core, speedPeak, speedScale, stateInitial)
+                int initiallyOn)
+ : Cpu(model, host, NULL/*constraint*/, speedPeakList, pstate, core, speedPeak, speedScale, initiallyOn)
 {
 }
 
 Cpu::Cpu(Model *model, simgrid::Host *host, lmm_constraint_t constraint,
              xbt_dynar_t speedPeakList, int pstate,
                  int core, double speedPeak,
-        double speedScale, e_surf_resource_state_t stateInitial)
- : Resource(model, host->getName().c_str(), constraint, stateInitial)
+        double speedScale, int initiallyOn)
+ : Resource(model, host->getName().c_str(), constraint, initiallyOn)
  , m_core(core)
  , m_speedPeak(speedPeak)
  , m_speedScale(speedScale)
index 0ab1e48..861ab24 100644 (file)
@@ -56,7 +56,7 @@ public:
   virtual Cpu *createCpu(simgrid::Host *host, xbt_dynar_t speedPeak,
                       int pstate, double speedScale,
                           tmgr_trace_t speedTrace, int core,
-                          e_surf_resource_state_t state_initial,
+                          int initiallyOn,
                           tmgr_trace_t state_trace)=0;
 
   void updateActionsStateLazy(double now, double delta);
@@ -88,7 +88,7 @@ public:
   Cpu(simgrid::surf::Model *model, simgrid::Host *host, lmm_constraint_t constraint,
          xbt_dynar_t speedPeakList, int pstate,
          int core, double speedPeak, double speedScale,
-         e_surf_resource_state_t stateInitial);
+         int initiallyOn);
 
   /**
    * @brief Cpu constructor
@@ -103,7 +103,7 @@ public:
   Cpu(simgrid::surf::Model *model, simgrid::Host *host,
       xbt_dynar_t speedPeakList, int pstate,
          int core, double speedPeak, double speedScale,
-         e_surf_resource_state_t stateInitial);
+         int initiallyOn);
 
   ~Cpu();
 
@@ -182,7 +182,7 @@ public:
 
   /** @brief CpuAction constructor */
   CpuAction(simgrid::surf::Model *model, double cost, bool failed)
-    : Action(model, cost, failed) {} //FIXME:REMOVE
+    : Action(model, cost, failed) {} //FIXME:DEADCODE?
 
   /** @brief CpuAction constructor */
   CpuAction(simgrid::surf::Model *model, double cost, bool failed, lmm_variable_t var)
index d3735e3..8490a1e 100644 (file)
@@ -440,14 +440,14 @@ Cpu *CpuTiModel::createCpu(simgrid::Host *host,
                            double speedScale,
                            tmgr_trace_t speedTrace,
                            int core,
-                           e_surf_resource_state_t stateInitial,
+                           int initiallyOn,
                            tmgr_trace_t stateTrace)
 {
   xbt_assert(core==1,"Multi-core not handled with this model yet");
   xbt_assert(xbt_dynar_getfirst_as(speedPeak, double) > 0.0,
       "Speed has to be >0.0. Did you forget to specify the mandatory speed attribute?");
   CpuTi *cpu = new CpuTi(this, host, speedPeak, pstate, speedScale, speedTrace,
-                          core, stateInitial, stateTrace);
+                          core, initiallyOn, stateTrace);
   return cpu;
 }
 
@@ -549,8 +549,8 @@ void CpuTiModel::addTraces()
  ************/
 CpuTi::CpuTi(CpuTiModel *model, simgrid::Host *host, xbt_dynar_t speedPeak,
         int pstate, double speedScale, tmgr_trace_t speedTrace, int core,
-        e_surf_resource_state_t stateInitial, tmgr_trace_t stateTrace)
-  : Cpu(model, host, NULL, pstate, core, 0, speedScale, stateInitial)
+        int initiallyOn, tmgr_trace_t stateTrace)
+  : Cpu(model, host, NULL, pstate, core, 0, speedScale, initiallyOn)
 {
   xbt_assert(core==1,"Multi-core not handled by this model yet");
   m_core = core;
@@ -619,11 +619,11 @@ void CpuTi::updateState(tmgr_trace_event_t event_type,
 
   } else if (event_type == p_stateEvent) {
     if (value > 0) {
-      if(getState() == SURF_RESOURCE_OFF)
+      if(isOff())
         xbt_dynar_push_as(host_that_restart, char*, (char *)getName());
-      setState(SURF_RESOURCE_ON);
+      turnOn();
     } else {
-      setState(SURF_RESOURCE_OFF);
+      turnOff();
 
       /* put all action running on cpu to failed */
       for(ActionTiList::iterator it(p_actionSet->begin()), itend(p_actionSet->end())
@@ -794,7 +794,7 @@ void CpuTi::updateRemainingAmount(double now)
 CpuAction *CpuTi::execute(double size)
 {
   XBT_IN("(%s,%g)", getName(), size);
-  CpuTiAction *action = new CpuTiAction(static_cast<CpuTiModel*>(getModel()), size, getState() != SURF_RESOURCE_ON, this);
+  CpuTiAction *action = new CpuTiAction(static_cast<CpuTiModel*>(getModel()), size, isOff(), this);
 
   p_actionSet->push_back(*action);
 
@@ -809,7 +809,7 @@ CpuAction *CpuTi::sleep(double duration)
     duration = MAX(duration, sg_surf_precision);
 
   XBT_IN("(%s,%g)", getName(), duration);
-  CpuTiAction *action = new CpuTiAction(static_cast<CpuTiModel*>(getModel()), 1.0, getState() != SURF_RESOURCE_ON, this);
+  CpuTiAction *action = new CpuTiAction(static_cast<CpuTiModel*>(getModel()), 1.0, isOff(), this);
 
   action->m_maxDuration = duration;
   action->m_suspended = 2;
index ea5e699..d8df612 100644 (file)
@@ -115,7 +115,7 @@ class CpuTi : public Cpu {
 public:
   CpuTi(CpuTiModel *model, simgrid::Host *host, xbt_dynar_t speedPeak,
         int pstate, double speedScale, tmgr_trace_t speedTrace, int core,
-        e_surf_resource_state_t stateInitial, tmgr_trace_t stateTrace) ;
+        int initiallyOn, tmgr_trace_t stateTrace) ;
   ~CpuTi();
 
   void updateState(tmgr_trace_event_t event_type, double value, double date) override;
@@ -155,7 +155,7 @@ public:
   Cpu *createCpu(simgrid::Host *host,  xbt_dynar_t speedPeak,
                           int pstate, double speedScale,
                           tmgr_trace_t speedTrace, int core,
-                          e_surf_resource_state_t state_initial,
+                          int initiallyOn,
                           tmgr_trace_t state_trace);
   double shareResources(double now) override;
   void updateActionsState(double now, double delta) override;
index 8772f95..b2a6700 100644 (file)
@@ -88,7 +88,7 @@ void HostModel::adjustWeightOfDummyCpuActions()
  ************/
 simgrid::surf::signal<void(simgrid::surf::Host*)> Host::onCreation;
 simgrid::surf::signal<void(simgrid::surf::Host*)> Host::onDestruction;
-simgrid::surf::signal<void(simgrid::surf::Host*, e_surf_resource_state_t, e_surf_resource_state_t)> Host::onStateChange;
+simgrid::surf::signal<void(simgrid::surf::Host*)> Host::onStateChange;
 
 Host::Host(simgrid::surf::Model *model, const char *name, xbt_dict_t props,
                                 xbt_dynar_t storage, NetCard *netElm, Cpu *cpu)
@@ -115,7 +115,7 @@ Host::~Host()
        delete p_cpu;
        // FIXME: VM plays strange games, leading to segfaults if I do the expected thing of next line
        // delete p_netElm;
-       delete p_storage;
+       // delete p_storage;
 }
 /** @brief Fire the require callbacks and destroy the object
  *
@@ -139,16 +139,24 @@ void Host::attach(simgrid::Host* host)
   onCreation(this);
 }
 
-e_surf_resource_state_t Host::getState() {
-  return p_cpu->getState();
+bool Host::isOn() {
+  return p_cpu->isOn();
 }
-void Host::setState(e_surf_resource_state_t state){
-  e_surf_resource_state_t old = Resource::getState();
-  Resource::setState(state);
-  onStateChange(this, old, state);
-  p_cpu->setState(state);
+bool Host::isOff() {
+  return p_cpu->isOff();
+}
+void Host::turnOn(){
+  if (isOff()) {
+    p_cpu->turnOn();
+    onStateChange(this);
+  }
+}
+void Host::turnOff(){
+  if (isOn()) {
+    p_cpu->turnOff();
+    onStateChange(this);
+  }
 }
-
 
 simgrid::surf::Storage *Host::findStorageOnMountList(const char* mount)
 {
index b69e1a8..4c2a174 100644 (file)
@@ -81,7 +81,7 @@ public:
   /* callbacks */
   static simgrid::surf::signal<void(Host*)> onCreation;    /** Called on each newly created object */
   static simgrid::surf::signal<void(Host*)> onDestruction; /** Called just before destructing an object */
-  static simgrid::surf::signal<void(simgrid::surf::Host*, e_surf_resource_state_t, e_surf_resource_state_t)> onStateChange;
+  static simgrid::surf::signal<void(Host*)> onStateChange; /** Called when the machine is turned on or off */
 
 public:
   /**
@@ -125,8 +125,10 @@ private:
 public:
   void attach(simgrid::Host* host);
 
-  e_surf_resource_state_t getState();
-  void setState(e_surf_resource_state_t state);
+  bool isOn() override;
+  bool isOff() override;
+  void turnOn() override;
+  void turnOff() override;
 
   /** @brief Return the storage of corresponding mount point */
   virtual simgrid::surf::Storage *findStorageOnMountList(const char* storage);
index fba3ef6..cd1c12a 100644 (file)
@@ -52,7 +52,7 @@ HostL07Model::HostL07Model() : HostModel() {
   routing_model_create(surf_network_model->createLink("__loopback__",
                                                          498000000, NULL,
                                                          0.000015, NULL,
-                                                         SURF_RESOURCE_ON, NULL,
+                                                         1/*ON*/, NULL,
                                                          SURF_LINK_FATPIPE, NULL));
 }
 
@@ -166,7 +166,7 @@ void HostL07Model::updateActionsState(double /*now*/, double delta) {
       while ((cnst = lmm_get_cnst_from_var(p_maxminSystem, action->getVariable(), i++))) {
         void *constraint_id = lmm_constraint_id(cnst);
 
-        if (static_cast<Host*>(constraint_id)->getState() == SURF_RESOURCE_OFF) {
+        if (static_cast<Host*>(constraint_id)->isOff()) {
           XBT_DEBUG("Action (%p) Failed!!", action);
           action->finish();
           action->setState(SURF_ACTION_FAILED);
@@ -300,11 +300,11 @@ Action *NetworkL07Model::communicate(NetCard *src, NetCard *dst,
 Cpu *CpuL07Model::createCpu(simgrid::Host *host,  xbt_dynar_t powerPeakList,
                           int pstate, double power_scale,
                           tmgr_trace_t power_trace, int core,
-                          e_surf_resource_state_t state_initial,
+                          int initiallyOn,
                           tmgr_trace_t state_trace)
 {
   CpuL07 *cpu = new CpuL07(this, host, powerPeakList, pstate, power_scale, power_trace,
-                         core, state_initial, state_trace);
+                         core, initiallyOn, state_trace);
   return cpu;
 }
 
@@ -313,7 +313,7 @@ Link* NetworkL07Model::createLink(const char *name,
                                  tmgr_trace_t bw_trace,
                                  double lat_initial,
                                  tmgr_trace_t lat_trace,
-                                 e_surf_resource_state_t state_initial,
+                                 int initiallyOn,
                                  tmgr_trace_t state_trace,
                                  e_surf_link_sharing_policy_t policy,
                                  xbt_dict_t properties)
@@ -324,7 +324,7 @@ Link* NetworkL07Model::createLink(const char *name,
   Link* link = new LinkL07(this, name, properties,
                             bw_initial, bw_trace,
                                         lat_initial, lat_trace,
-                                        state_initial, state_trace,
+                                        initiallyOn, state_trace,
                                         policy);
   Link::onCreation(link);
   return link;
@@ -398,9 +398,9 @@ void HostL07Model::addTraces()
 CpuL07::CpuL07(CpuL07Model *model, simgrid::Host *host,
                     xbt_dynar_t speedPeakList, int pstate,
                                 double speedScale, tmgr_trace_t speedTrace,
-                        int core, e_surf_resource_state_t state_initial, tmgr_trace_t state_trace)
+                        int core, int initiallyOn, tmgr_trace_t state_trace)
  : Cpu(model, host, speedPeakList, pstate,
-          core, xbt_dynar_get_as(speedPeakList,pstate,double), speedScale, state_initial)
+          core, xbt_dynar_get_as(speedPeakList,pstate,double), speedScale, initiallyOn)
 {
   p_constraint = lmm_constraint_new(model->getMaxminSystem(), this, xbt_dynar_get_as(speedPeakList,pstate,double) * speedScale);
 
@@ -422,7 +422,7 @@ LinkL07::LinkL07(NetworkL07Model *model, const char* name, xbt_dict_t props,
                         tmgr_trace_t bw_trace,
                         double lat_initial,
                         tmgr_trace_t lat_trace,
-                        e_surf_resource_state_t state_initial,
+                        int initiallyOn,
                         tmgr_trace_t state_trace,
                         e_surf_link_sharing_policy_t policy)
  : Link(model, name, props, lmm_constraint_new(model->getMaxminSystem(), this, bw_initial), history, state_trace)
@@ -431,7 +431,10 @@ LinkL07::LinkL07(NetworkL07Model *model, const char* name, xbt_dict_t props,
   if (bw_trace)
     p_bwEvent = tmgr_history_add_trace(history, bw_trace, 0.0, 0, this);
 
-  setState(state_initial);
+  if (initiallyOn)
+    turnOn();
+  else
+    turnOff();
   m_latCurrent = lat_initial;
 
   if (lat_trace)
@@ -506,9 +509,9 @@ void CpuL07::updateState(tmgr_trace_event_t event_type, double value, double /*d
       p_speedEvent = NULL;
   } else if (event_type == p_stateEvent) {
     if (value > 0)
-      setState(SURF_RESOURCE_ON);
+      turnOn();
     else
-      setState(SURF_RESOURCE_OFF);
+      turnOff();
     if (tmgr_trace_event_free(event_type))
       p_stateEvent = NULL;
   } else {
@@ -530,9 +533,9 @@ void LinkL07::updateState(tmgr_trace_event_t event_type, double value, double da
       p_latEvent = NULL;
   } else if (event_type == p_stateEvent) {
     if (value > 0)
-      setState(SURF_RESOURCE_ON);
+      turnOn();
     else
-      setState(SURF_RESOURCE_OFF);
+      turnOff();
     if (tmgr_trace_event_free(event_type))
       p_stateEvent = NULL;
   } else {
index 8100346..1de3995 100644 (file)
@@ -60,7 +60,7 @@ public:
   Cpu *createCpu(simgrid::Host *host,  xbt_dynar_t speedPeakList,
                           int pstate, double speedScale,
                           tmgr_trace_t speedTrace, int core,
-                          e_surf_resource_state_t state_initial,
+                          int initiallyOn,
                           tmgr_trace_t state_trace) override;
   void addTraces() override {DIE_IMPOSSIBLE;};
 
@@ -76,7 +76,7 @@ public:
                  tmgr_trace_t bw_trace,
                  double lat_initial,
                  tmgr_trace_t lat_trace,
-                 e_surf_resource_state_t state_initial,
+                 int initiallyOn,
                  tmgr_trace_t state_trace,
                  e_surf_link_sharing_policy_t policy,
                  xbt_dict_t properties) override;
@@ -99,7 +99,7 @@ class CpuL07 : public Cpu {
 public:
   CpuL07(CpuL07Model *model, simgrid::Host *host, xbt_dynar_t speedPeakList, int pstate,
                 double power_scale, tmgr_trace_t power_trace,
-     int core, e_surf_resource_state_t state_initial, tmgr_trace_t state_trace);
+     int core, int initiallyOn, tmgr_trace_t state_trace);
   ~CpuL07();
   bool isUsed() override;
   void updateState(tmgr_trace_event_t event_type, double value, double date) override;
@@ -116,8 +116,7 @@ public:
           tmgr_trace_t bw_trace,
           double lat_initial,
           tmgr_trace_t lat_trace,
-          e_surf_resource_state_t
-          state_initial,
+          int initiallyOn,
           tmgr_trace_t state_trace,
           e_surf_link_sharing_policy_t policy);
   ~LinkL07(){ };
index f0fce7b..c83cd4a 100644 (file)
@@ -181,7 +181,7 @@ NetworkCm02Model::NetworkCm02Model()
 
   routing_model_create(createLink("__loopback__",
                                      498000000, NULL, 0.000015, NULL,
-                                     SURF_RESOURCE_ON, NULL,
+                                     1 /*SURF_RESOURCE_ON*/, NULL,
                                      SURF_LINK_FATPIPE, NULL));
 
   if (p_updateMechanism == UM_LAZY) {
@@ -197,7 +197,7 @@ Link* NetworkCm02Model::createLink(const char *name,
                                  tmgr_trace_t bw_trace,
                                  double lat_initial,
                                  tmgr_trace_t lat_trace,
-                                 e_surf_resource_state_t state_initial,
+                                 int initiallyOn,
                                  tmgr_trace_t state_trace,
                                  e_surf_link_sharing_policy_t policy,
                                  xbt_dict_t properties)
@@ -207,7 +207,7 @@ Link* NetworkCm02Model::createLink(const char *name,
              name);
 
   Link* link = new NetworkCm02Link(this, name, properties, p_maxminSystem, sg_bandwidth_factor * bw_initial, history,
-                                            state_initial, state_trace, bw_initial, bw_trace, lat_initial, lat_trace, policy);
+                                            initiallyOn, state_trace, bw_initial, bw_trace, lat_initial, lat_trace, policy);
   Link::onCreation(link);
   return link;
 }
@@ -357,7 +357,7 @@ Action *NetworkCm02Model::communicate(NetCard *src, NetCard *dst,
 
   xbt_dynar_foreach(route, i, _link) {
        link = static_cast<NetworkCm02Link*>(_link);
-    if (link->getState() == SURF_RESOURCE_OFF) {
+    if (link->isOff()) {
       failed = 1;
       break;
     }
@@ -366,7 +366,7 @@ Action *NetworkCm02Model::communicate(NetCard *src, NetCard *dst,
          routing_platf->getRouteAndLatency(dst, src, &back_route, NULL);
     xbt_dynar_foreach(back_route, i, _link) {
       link = static_cast<NetworkCm02Link*>(_link);
-      if (link->getState() == SURF_RESOURCE_OFF) {
+      if (link->isOff()) {
         failed = 1;
         break;
       }
@@ -513,7 +513,7 @@ NetworkCm02Link::NetworkCm02Link(NetworkCm02Model *model, const char *name, xbt_
                                   lmm_system_t system,
                                   double constraint_value,
                                   tmgr_history_t history,
-                                  e_surf_resource_state_t state_init,
+                                  int initiallyOn,
                                   tmgr_trace_t state_trace,
                                   double metric_peak,
                                   tmgr_trace_t metric_trace,
@@ -522,7 +522,10 @@ NetworkCm02Link::NetworkCm02Link(NetworkCm02Model *model, const char *name, xbt_
                                   e_surf_link_sharing_policy_t policy)
 : Link(model, name, props, lmm_constraint_new(system, this, constraint_value), history, state_trace)
 {
-  setState(state_init);
+  if (initiallyOn)
+    turnOn();
+  else
+    turnOff();
 
   p_speed.scale = 1.0;
   p_speed.peak = metric_peak;
@@ -558,13 +561,13 @@ void NetworkCm02Link::updateState(tmgr_trace_event_t event_type,
       p_latEvent = NULL;
   } else if (event_type == p_stateEvent) {
     if (value > 0)
-      setState(SURF_RESOURCE_ON);
+      turnOn();
     else {
       lmm_constraint_t cnst = getConstraint();
       lmm_variable_t var = NULL;
       lmm_element_t elem = NULL;
 
-      setState(SURF_RESOURCE_OFF);
+      turnOff();
       while ((var = lmm_get_var_from_cnst(getModel()->getMaxminSystem(), cnst, &elem))) {
         Action *action = static_cast<Action*>( lmm_variable_id(var) );
 
index e968bff..25b4de5 100644 (file)
@@ -51,7 +51,7 @@ public:
                  tmgr_trace_t bw_trace,
                  double lat_initial,
                  tmgr_trace_t lat_trace,
-                 e_surf_resource_state_t state_initial,
+                 int initiallyOn,
                  tmgr_trace_t state_trace,
                  e_surf_link_sharing_policy_t policy,
                  xbt_dict_t properties) override;
@@ -76,7 +76,7 @@ public:
                                   lmm_system_t system,
                                   double constraint_value,
                                   tmgr_history_t history,
-                                  e_surf_resource_state_t state_init,
+                                  int initiallyOn,
                                   tmgr_trace_t state_trace,
                                   double metric_peak,
                                   tmgr_trace_t metric_trace,
index a80825a..bd9b1ee 100644 (file)
@@ -40,7 +40,7 @@ public:
       tmgr_trace_t bw_trace,
       double lat_initial,
       tmgr_trace_t lat_trace,
-      e_surf_resource_state_t state_initial,
+      int initiallyOn,
       tmgr_trace_t state_trace,
       e_surf_link_sharing_policy_t policy,
       xbt_dict_t properties)          override { DIE_IMPOSSIBLE; }
index be4bc06..236a8ac 100644 (file)
@@ -97,7 +97,7 @@ void Link::linksExit() {
 
 simgrid::surf::signal<void(simgrid::surf::Link*)> Link::onCreation;
 simgrid::surf::signal<void(simgrid::surf::Link*)> Link::onDestruction;
-simgrid::surf::signal<void(simgrid::surf::Link*, e_surf_resource_state_t, e_surf_resource_state_t)> Link::onStateChange;
+simgrid::surf::signal<void(simgrid::surf::Link*, int, int)> Link::onStateChange; // signature: wasOn, currentlyOn
 
 simgrid::surf::signal<void(simgrid::surf::NetworkAction*, e_surf_action_state_t, e_surf_action_state_t)> networkActionStateChangedCallbacks;
 simgrid::surf::signal<void(simgrid::surf::NetworkAction*, simgrid::surf::NetCard *src, simgrid::surf::NetCard *dst, double size, double rate)> networkCommunicateCallbacks;
@@ -114,7 +114,7 @@ void netlink_parse_init(sg_platf_link_cbarg_t link){
                       link->bandwidth_trace,
                       link->latency,
                       link->latency_trace,
-                      link->state,
+                      link->initiallyOn,
                       link->state_trace, link->policy, link->properties);
     xbt_free(link_id);
     link_id = bprintf("%s_DOWN", link->id);
@@ -123,7 +123,7 @@ void netlink_parse_init(sg_platf_link_cbarg_t link){
                       link->bandwidth_trace,
                       link->latency,
                       link->latency_trace,
-                      link->state,
+                      link->initiallyOn,
                       link->state_trace, link->policy, link->properties);
     xbt_free(link_id);
   } else {
@@ -132,7 +132,7 @@ void netlink_parse_init(sg_platf_link_cbarg_t link){
                          link->bandwidth_trace,
                          link->latency,
                          link->latency_trace,
-                         link->state,
+                         link->initiallyOn,
                          link->state_trace, link->policy, link->properties);
   }
 }
@@ -255,10 +255,17 @@ int Link::sharingPolicy()
   return lmm_constraint_sharing_policy(getConstraint());
 }
 
-void Link::setState(e_surf_resource_state_t state){
-  e_surf_resource_state_t old = Resource::getState();
-  Resource::setState(state);
-  onStateChange(this, old, state);
+void Link::turnOn(){
+  if (isOff()) {
+    Resource::turnOn();
+    onStateChange(this, 0, 1);
+  }
+}
+void Link::turnOff(){
+  if (isOn()) {
+    Resource::turnOff();
+    onStateChange(this, 1, 0);
+  }
 }
 
 /**********
index 4cb6b80..cf080ee 100644 (file)
@@ -97,7 +97,7 @@ public:
                                    tmgr_trace_t bw_trace,
                                    double lat_initial,
                                    tmgr_trace_t lat_trace,
-                                   e_surf_resource_state_t state_initial,
+                                   int initiallyOn,
                                    tmgr_trace_t state_trace,
                                    e_surf_link_sharing_policy_t policy,
                                    xbt_dict_t properties)=0;
@@ -214,8 +214,8 @@ public:
   static simgrid::surf::signal<void(simgrid::surf::Link*)> onDestruction;
 
   /** @brief Callback signal fired when the state of a Link changes
-   *  Signature: `void(LinkAction *action, e_surf_resource_state_t oldState, e_surf_resource_state_t currentState)` */
-  static simgrid::surf::signal<void(simgrid::surf::Link*, e_surf_resource_state_t, e_surf_resource_state_t)> onStateChange;
+   *  Signature: `void(LinkAction *action, int previouslyOn, int currentlyOn)` */
+  static simgrid::surf::signal<void(simgrid::surf::Link*, int, int)> onStateChange;
 
 
   /** @brief Get the bandwidth in bytes per second of current Link */
@@ -236,7 +236,8 @@ public:
   /** @brief Check if the Link is used */
   bool isUsed();
 
-  void setState(e_surf_resource_state_t state);
+  void turnOn() override;
+  void turnOff() override;
 
   /* Using this object with the public part of
     model does not make sense */
index 163de0c..9ccded3 100644 (file)
@@ -57,7 +57,7 @@ static void parse_ns3_add_link(sg_platf_link_cbarg_t link)
                                      link->bandwidth_trace,
                                      link->latency,
                                      link->latency_trace,
-                                     link->state,
+                                     link->initiallyOn,
                                      link->state_trace,
                                      link->policy,
                                      link->properties);
@@ -288,7 +288,7 @@ Link* NetworkNS3Model::createLink(const char *name,
                                         tmgr_trace_t bw_trace,
                                         double lat_initial,
                                         tmgr_trace_t lat_trace,
-                                        e_surf_resource_state_t state_initial,
+                                        int initiallyOn,
                                         tmgr_trace_t state_trace,
                                         e_surf_link_sharing_policy_t policy,
                                         xbt_dict_t properties){
index e9c07a0..55c36b5 100644 (file)
@@ -48,7 +48,7 @@ public:
                                         tmgr_trace_t bw_trace,
                                         double lat_initial,
                                         tmgr_trace_t lat_trace,
-                                        e_surf_resource_state_t state_initial,
+                                        int initiallyOn,
                                         tmgr_trace_t state_trace,
                                         e_surf_link_sharing_policy_t policy,
                                         xbt_dict_t properties);
index bd0a4d6..1fddaab 100644 (file)
@@ -66,10 +66,13 @@ static void update_consumption(simgrid::surf::Host *host, HostEnergy *host_energ
        else
                cpu_load = lmm_constraint_get_usage(host->p_cpu->getConstraint()) / host->p_cpu->m_speedPeak;
 
+       if (cpu_load > 1) // A machine with a load > 1 consumes as much as a fully loaded machine, not mores
+         cpu_load = 1;
+
        double previous_energy = host_energy->total_energy;
 
        double instantaneous_consumption;
-       if (host->getState() == SURF_RESOURCE_OFF)
+       if (host->isOff())
                instantaneous_consumption = host_energy->watts_off;
        else
                instantaneous_consumption = host_energy->getCurrentWattsValue(cpu_load);
@@ -79,8 +82,8 @@ static void update_consumption(simgrid::surf::Host *host, HostEnergy *host_energ
        host_energy->total_energy = previous_energy + energy_this_step;
        host_energy->last_updated = finish_time;
 
-       XBT_DEBUG("[cpu_update_energy] period=[%.2f-%.2f]; current power peak=%.0E flop/s; consumption change: %.2f J -> %.2f J",
-                 start_time, finish_time, host->p_cpu->m_speedPeak, previous_energy, energy_this_step);
+       XBT_DEBUG("[update_energy of %s] period=[%.2f-%.2f]; current power peak=%.0E flop/s; consumption change: %.2f J -> %.2f J",
+           host->getName(), start_time, finish_time, host->p_cpu->m_speedPeak, previous_energy, energy_this_step);
 }
 
 /** \ingroup SURF_plugin_energy
@@ -92,59 +95,60 @@ void sg_energy_plugin_init() {
 
        simgrid::energy::surf_energy = new std::map<simgrid::surf::Host*, simgrid::energy::HostEnergy*>();
 
-    /* The following attaches an anonymous function to the Host::onCreation signal */
+       /* The following attaches an anonymous function to the Host::onCreation signal */
        /* Search for "C++ lambda" for more information on the syntax used here */
-    simgrid::surf::Host::onCreation.connect([](simgrid::surf::Host *host) {
-       (*simgrid::energy::surf_energy)[host] = new HostEnergy(host);
-    });
-
-    simgrid::surf::VMCreatedCallbacks.connect([](simgrid::surf::VirtualMachine* vm) {
-       std::map<simgrid::surf::Host*, HostEnergy*>::iterator host_energy_it =
-                       simgrid::energy::surf_energy->find(vm->p_hostPM->extension(simgrid::surf::Host::EXTENSION_ID));
-       xbt_assert(host_energy_it != simgrid::energy::surf_energy->end(), "The host is not in surf_energy.");
-       (*simgrid::energy::surf_energy)[vm] = host_energy_it->second;
-       host_energy_it->second->ref(); // protect the HostEnergy from getting deleted too early
-    });
-
-    simgrid::surf::Host::onDestruction.connect([](simgrid::surf::Host *host) {
-       std::map<simgrid::surf::Host*, HostEnergy*>::iterator host_energy_it = simgrid::energy::surf_energy->find(host);
-       xbt_assert(host_energy_it != simgrid::energy::surf_energy->end(), "The host is not in surf_energy.");
-
-       HostEnergy *host_energy = host_energy_it->second;
-       update_consumption(host, host_energy);
-
-       if (host_energy_it->second->refcount == 1) // Don't display anything for virtual CPUs
-               XBT_INFO("Total energy of host %s: %f Joules", host->getName(), host_energy->getConsumedEnergy());
-       host_energy_it->second->unref();
-       simgrid::energy::surf_energy->erase(host_energy_it);
-    });
-    simgrid::surf::CpuAction::onStateChange.connect([](simgrid::surf::CpuAction *action,
-                                                       e_surf_action_state_t old,
-                                                       e_surf_action_state_t cur) {
-       const char *name = getActionCpu(action)->getName();
-       simgrid::surf::Host *host = static_cast<simgrid::surf::Host*>(surf_host_resource_priv(sg_host_by_name(name)));
-
-       HostEnergy *host_energy = (*simgrid::energy::surf_energy)[host];
-
-       if(host_energy->last_updated < surf_get_clock())
-               update_consumption(host, host_energy);
-
-    });
-
-    simgrid::surf::Host::onStateChange.connect([]
-                                                                                               (simgrid::surf::Host *host,
-                                                                                                               e_surf_resource_state_t oldState,
-                                                                                                               e_surf_resource_state_t newState) {
-       HostEnergy *host_energy = (*simgrid::energy::surf_energy)[host];
-
-       if(host_energy->last_updated < surf_get_clock())
-               update_consumption(host, host_energy);
-    });
-
-    simgrid::surf::surfExitCallbacks.connect([]() {
-       delete simgrid::energy::surf_energy;
-       simgrid::energy::surf_energy = NULL;
-    });
+       simgrid::surf::Host::onCreation.connect([](simgrid::surf::Host *host) {
+         if (dynamic_cast<simgrid::surf::VirtualMachine*>(host)) // Ignore virtual machines
+           return;
+
+         (*simgrid::energy::surf_energy)[host] = new HostEnergy(host);
+       });
+
+       simgrid::surf::Host::onDestruction.connect([](simgrid::surf::Host *host) {
+         if (dynamic_cast<simgrid::surf::VirtualMachine*>(host)) // Ignore virtual machines
+           return;
+
+         std::map<simgrid::surf::Host*, HostEnergy*>::iterator host_energy_it = simgrid::energy::surf_energy->find(host);
+         xbt_assert(host_energy_it != simgrid::energy::surf_energy->end(), "The host is not in surf_energy.");
+
+         HostEnergy *host_energy = host_energy_it->second;
+         update_consumption(host, host_energy);
+
+         XBT_INFO("Total energy of host %s: %f Joules", host->getName(), host_energy->getConsumedEnergy());
+         host_energy_it->second->unref();
+         simgrid::energy::surf_energy->erase(host_energy_it);
+       });
+
+       simgrid::surf::CpuAction::onStateChange.connect([](simgrid::surf::CpuAction *action,
+           e_surf_action_state_t old,
+           e_surf_action_state_t cur) {
+         const char *name = getActionCpu(action)->getName();
+         simgrid::surf::Host *host = surf_host_resource_priv(sg_host_by_name(name));
+         simgrid::surf::VirtualMachine *vm = dynamic_cast<simgrid::surf::VirtualMachine*>(host);
+         if (vm) // If it's a VM, take the corresponding PM
+             host = surf_host_resource_priv(vm->getPm());
+
+         HostEnergy *host_energy = (*simgrid::energy::surf_energy)[host];
+
+         if(host_energy->last_updated < surf_get_clock())
+           update_consumption(host, host_energy);
+
+       });
+
+       simgrid::surf::Host::onStateChange.connect([] (simgrid::surf::Host *host) {
+         if (dynamic_cast<simgrid::surf::VirtualMachine*>(host)) // Ignore virtual machines
+           return;
+
+         HostEnergy *host_energy = (*simgrid::energy::surf_energy)[host];
+
+         if(host_energy->last_updated < surf_get_clock())
+           update_consumption(host, host_energy);
+       });
+
+       simgrid::surf::surfExitCallbacks.connect([]() {
+         delete simgrid::energy::surf_energy;
+         simgrid::energy::surf_energy = NULL;
+       });
   }
 }
 
@@ -204,19 +208,19 @@ double HostEnergy::getCurrentWattsValue(double cpu_load)
        int pstate = host->p_cpu->getPState();
        xbt_assert(pstate < (int)xbt_dynar_length(power_range_list),
                        "pstate %d >= power range amound %d",pstate,(int)xbt_dynar_length(power_range_list));
-    /* retrieve the power values associated with the current pstate */
-    xbt_dynar_t current_power_values = xbt_dynar_get_as( power_range_list, pstate, xbt_dynar_t);
+       /* retrieve the power values associated with the current pstate */
+       xbt_dynar_t current_power_values = xbt_dynar_get_as( power_range_list, pstate, xbt_dynar_t);
 
-    /* min_power corresponds to the idle power (cpu load = 0) */
-    /* max_power is the power consumed at 100% cpu load       */
-    double min_power = xbt_dynar_get_as(current_power_values, 0, double);
-    double max_power = xbt_dynar_get_as(current_power_values, 1, double);
-    double power_slope = max_power - min_power;
+       /* min_power corresponds to the idle power (cpu load = 0) */
+       /* max_power is the power consumed at 100% cpu load       */
+       double min_power = xbt_dynar_get_as(current_power_values, 0, double);
+       double max_power = xbt_dynar_get_as(current_power_values, 1, double);
+       double power_slope = max_power - min_power;
 
-    double current_power = min_power + cpu_load * power_slope;
+       double current_power = min_power + cpu_load * power_slope;
 
        XBT_DEBUG("[get_current_watts] min_power=%f, max_power=%f, slope=%f", min_power, max_power, power_slope);
-    XBT_DEBUG("[get_current_watts] Current power (watts) = %f, load = %f", current_power, cpu_load);
+       XBT_DEBUG("[get_current_watts] Current power (watts) = %f, load = %f", current_power, cpu_load);
 
        return current_power;
 }
index a178aa7..9cc96bd 100644 (file)
@@ -68,7 +68,7 @@ void sg_platf_new_host(sg_platf_host_cbarg_t host)
         host->speed_scale,
         host->speed_trace,
         host->core_amount,
-        host->initial_state,
+        host->initiallyOn,
         host->state_trace);
   surf_host_model->createHost(host->id, net, cpu, host->properties)->attach(h);
   if (TRACE_is_enabled() && TRACE_needs_platform())
index c9c3698..e9a35b7 100644 (file)
@@ -30,7 +30,7 @@ namespace surf {
 
 simgrid::surf::signal<void(simgrid::surf::Storage*)> storageCreatedCallbacks;
 simgrid::surf::signal<void(simgrid::surf::Storage*)> storageDestructedCallbacks;
-simgrid::surf::signal<void(simgrid::surf::Storage*, e_surf_resource_state_t, e_surf_resource_state_t)> storageStateChangedCallbacks;
+simgrid::surf::signal<void(simgrid::surf::Storage*, int, int)> storageStateChangedCallbacks; // signature: wasOn, isOn
 simgrid::surf::signal<void(simgrid::surf::StorageAction*, e_surf_action_state_t, e_surf_action_state_t)> storageActionStateChangedCallbacks;
 
 /*********
@@ -66,7 +66,7 @@ Storage::Storage(Model *model, const char *name, xbt_dict_t props,
  , p_writeActions(xbt_dynar_new(sizeof(Action*),NULL))
 {
   p_content = parseContent(content_name);
-  setState(SURF_RESOURCE_ON);
+  turnOn();
 }
 
 Storage::Storage(Model *model, const char *name, xbt_dict_t props,
@@ -82,7 +82,7 @@ Storage::Storage(Model *model, const char *name, xbt_dict_t props,
 {
   p_content = parseContent(content_name);
   p_attach = xbt_strdup(attach);
-  setState(SURF_RESOURCE_ON);
+  turnOn();
   XBT_DEBUG("Create resource with Bconnection '%f' Bread '%f' Bwrite '%f' and Size '%llu'", bconnection, bread, bwrite, size);
   p_constraintRead  = lmm_constraint_new(maxminSystem, this, bread);
   p_constraintWrite = lmm_constraint_new(maxminSystem, this, bwrite);
@@ -145,11 +145,17 @@ void Storage::updateState(tmgr_trace_event_t /*event_type*/, double /*value*/, d
   THROW_UNIMPLEMENTED;
 }
 
-void Storage::setState(e_surf_resource_state_t state)
-{
-  e_surf_resource_state_t old = Resource::getState();
-  Resource::setState(state);
-  storageStateChangedCallbacks(this, old, state);
+void Storage::turnOn() {
+  if (isOff()) {
+    Resource::turnOn();
+    storageStateChangedCallbacks(this, 0, 1);
+  }
+}
+void Storage::turnOff() {
+  if (isOn()) {
+    Resource::turnOff();
+    storageStateChangedCallbacks(this, 1, 0);
+  }
 }
 
 xbt_dict_t Storage::getContent()
index 631299e..125962e 100644 (file)
@@ -43,9 +43,9 @@ XBT_PUBLIC_DATA(simgrid::surf::signal<void(simgrid::surf::Storage*)>) storageDes
 
 /** @ingroup SURF_callbacks
  * @brief Callbacks handler which emit the callbacks after Storage State changed *
- * @details Callback functions have the following signature: `void(StorageAction *action, e_surf_resource_state_t old, e_surf_resource_state_t current)`
+ * @details Callback functions have the following signature: `void(StorageAction *action, int previouslyOn, int currentlyOn)`
  */
-XBT_PUBLIC_DATA(simgrid::surf::signal<void(simgrid::surf::Storage*, e_surf_resource_state_t, e_surf_resource_state_t)>) storageStateChangedCallbacks;
+XBT_PUBLIC_DATA(simgrid::surf::signal<void(simgrid::surf::Storage*, int, int)>) storageStateChangedCallbacks;
 
 /** @ingroup SURF_callbacks
  * @brief Callbacks handler which emit the callbacks after StorageAction State changed *
@@ -148,7 +148,8 @@ public:
    */
   void updateState(tmgr_trace_event_t event_type, double value, double date);
 
-  void setState(e_surf_resource_state_t state);
+  void turnOn() override;
+  void turnOff() override;
 
   xbt_dict_t p_content;
   char* p_contentType;
index f54f289..c21c670 100644 (file)
@@ -248,7 +248,7 @@ StorageAction *StorageN11::open(const char* mount, const char* path)
   file->mount = xbt_strdup(mount);
   file->current_position = 0;
 
-  StorageAction *action = new StorageN11Action(getModel(), 0, getState() != SURF_RESOURCE_ON, this, OPEN);
+  StorageAction *action = new StorageN11Action(getModel(), 0, isOff(), this, OPEN);
   action->p_file = file;
 
   return action;
@@ -272,7 +272,7 @@ StorageAction *StorageN11::close(surf_file_t fd)
   free(fd->name);
   free(fd->mount);
   xbt_free(fd);
-  StorageAction *action = new StorageN11Action(getModel(), 0, getState() != SURF_RESOURCE_ON, this, CLOSE);
+  StorageAction *action = new StorageN11Action(getModel(), 0, isOff(), this, CLOSE);
   return action;
 }
 
@@ -289,7 +289,7 @@ StorageAction *StorageN11::read(surf_file_t fd, sg_size_t size)
   else
     fd->current_position += size;
 
-  StorageAction *action = new StorageN11Action(getModel(), size, getState() != SURF_RESOURCE_ON, this, READ);
+  StorageAction *action = new StorageN11Action(getModel(), size, isOff(), this, READ);
   return action;
 }
 
@@ -298,7 +298,7 @@ StorageAction *StorageN11::write(surf_file_t fd, sg_size_t size)
   char *filename = fd->name;
   XBT_DEBUG("\tWrite file '%s' size '%llu/%llu'",filename,size,fd->size);
 
-  StorageAction *action = new StorageN11Action(getModel(), size, getState() != SURF_RESOURCE_ON, this, WRITE);
+  StorageAction *action = new StorageN11Action(getModel(), size, isOff(), this, WRITE);
   action->p_file = fd;
   /* Substract the part of the file that might disappear from the used sized on
    * the storage element */
index fc630e2..372bedc 100644 (file)
@@ -243,12 +243,17 @@ const char *surf_resource_name(surf_cpp_resource_t resource){
   return resource->getName();
 }
 
-e_surf_resource_state_t surf_resource_get_state(surf_cpp_resource_t resource){
-  return resource->getState();
+int surf_resource_is_on(surf_cpp_resource_t resource){
+  return resource->isOn();
 }
-
-void surf_resource_set_state(surf_cpp_resource_t resource, e_surf_resource_state_t state){
-  resource->setState(state);
+int surf_resource_is_off(surf_cpp_resource_t resource){
+  return resource->isOff();
+}
+void surf_resource_turn_on(surf_cpp_resource_t resource){
+  resource->turnOn();
+}
+void surf_resource_turn_off(surf_cpp_resource_t resource){
+  resource->turnOff();
 }
 
 surf_action_t surf_host_sleep(sg_host_t host, double duration){
index b05dfd7..d1c9c0d 100644 (file)
@@ -591,59 +591,52 @@ namespace surf {
 
 Resource::Resource()
 : p_name(NULL), p_model(NULL)
-{}
+{} // FIXME: DEADCODE?
 
 Resource::Resource(Model *model, const char *name)
-  : Resource(model, name, SURF_RESOURCE_ON)
-{}
+  : Resource(model, name, 1/*SURF_RESOURCE_ON*/)
+{} // FIXME: DEADCODE?
 
 Resource::Resource(Model *model, const char *name, lmm_constraint_t constraint)
-  : Resource(model, name, constraint, SURF_RESOURCE_ON)
+  : Resource(model, name, constraint, 1/*SURF_RESOURCE_ON*/)
 {}
   
-Resource::Resource(
-  Model *model, const char *name,
-  lmm_constraint_t constraint, e_surf_resource_state_t stateInit)
-  : p_name(xbt_strdup(name)), p_model(model)
-  , m_running(true), m_stateCurrent(stateInit), p_constraint(constraint)
+Resource::Resource(Model *model, const char *name, lmm_constraint_t constraint, int initiallyOn)
+  : p_name(xbt_strdup(name))
+  , p_model(model)
+  , m_isOn(initiallyOn)
+  , p_constraint(constraint)
 {}
 
-Resource::Resource(Model *model, const char *name, e_surf_resource_state_t stateInit)
-  : p_name(xbt_strdup(name)), p_model(model)
-  , m_running(true), m_stateCurrent(stateInit)
-{}
+Resource::Resource(Model *model, const char *name, int initiallyOn)
+  : p_name(xbt_strdup(name))
+  , p_model(model)
+  , m_isOn(initiallyOn)
+{} // FIXME: DEADCODE?
 
 
 Resource::~Resource() {
   xbt_free((void*)p_name);
 }
 
-e_surf_resource_state_t Resource::getState()
-{
-  return m_stateCurrent;
+bool Resource::isOn() {
+  return m_isOn;
 }
-
-void Resource::setState(e_surf_resource_state_t state)
-{
-  m_stateCurrent = state;
-}
-
-bool Resource::isOn()
-{
-  return m_running;
+bool Resource::isOff() {
+  return ! m_isOn;
 }
 
 void Resource::turnOn()
 {
-  if (!m_running) {
-    m_running = true;
+  if (!m_isOn) {
+    m_isOn = true;
   }
 }
 
 void Resource::turnOff()
 {
-  if (m_running) {
-    m_running = false;
+  if (m_isOn) {
+    m_isOn = false;
   }
 }
 
index 516a2c9..5855cca 100644 (file)
@@ -433,16 +433,16 @@ public:
    */
   Resource(Model *model, const char *name, lmm_constraint_t constraint);
 
-  Resource(Model *model, const char *name, lmm_constraint_t constraint, e_surf_resource_state_t stateInit);
+  Resource(Model *model, const char *name, lmm_constraint_t constraint, int initiallyOn);
 
   /**
    * @brief Resource constructor
    *
    * @param model Model associated to this Resource
    * @param name The name of the Resource
-   * @param stateInit the initial state of the Resource
+   * @param initiallyOn the initial state of the Resource
    */
-  Resource(Model *model, const char *name, e_surf_resource_state_t stateInit);
+  Resource(Model *model, const char *name, int initiallyOn);
 
   virtual ~Resource();
 
@@ -466,23 +466,18 @@ public:
   virtual bool isUsed()=0;
 
   /** @brief Check if the current Resource is active */
-  bool isOn();
+  virtual bool isOn();
+  /** @brief Check if the current Resource is shut down */
+  virtual bool isOff();
   /** @brief Turn on the current Resource */
-  void turnOn();
+  virtual void turnOn();
   /** @brief Turn off the current Resource */
-  void turnOff();
-
-  /** @brief Get the [state](\ref e_surf_resource_state_t) of the current Resource */
-  virtual e_surf_resource_state_t getState();
-  /** @brief Set the [state](\ref e_surf_resource_state_t) of the current Resource */
-  virtual void setState(e_surf_resource_state_t state);
+  virtual void turnOff();
 
 private:
   const char *p_name;
   Model *p_model;
-  bool m_running;
-  e_surf_resource_state_t m_stateCurrent;
-
+  bool m_isOn;
 
 public: /* LMM */
   /** @brief Get the lmm constraint associated to this Resource if it is part of a LMM component */
index a64fd47..857f147 100644 (file)
@@ -708,14 +708,14 @@ void sg_platf_new_cabinet(sg_platf_cabinet_cbarg_t cabinet)
     }
     s_sg_platf_host_cbarg_t host = SG_PLATF_HOST_INITIALIZER;
     memset(&host, 0, sizeof(host));
-    host.initial_state = SURF_RESOURCE_ON;
+    host.initiallyOn   = 1;
     host.pstate        = 0;
     host.speed_scale   = 1.0;
     host.core_amount   = 1;
 
     s_sg_platf_link_cbarg_t link = SG_PLATF_LINK_INITIALIZER;
     memset(&link, 0, sizeof(link));
-    link.state     = SURF_RESOURCE_ON;
+    link.initiallyOn = 1;
     link.policy    = SURF_LINK_FULLDUPLEX;
     link.latency   = cabinet->lat;
     link.bandwidth = cabinet->bw;
@@ -881,7 +881,7 @@ void routing_new_cluster(sg_platf_cluster_cbarg_t cluster)
       //host.power_peak = cluster->power;
       host.speed_scale = 1.0;
       host.core_amount = cluster->core_amount;
-      host.initial_state = SURF_RESOURCE_ON;
+      host.initiallyOn = 1;
       host.coord = "";
       sg_platf_new_host(&host);
       xbt_dynar_free(&host.speed_peak);
@@ -910,7 +910,7 @@ void routing_new_cluster(sg_platf_cluster_cbarg_t cluster)
         link.id        = tmp_link;
         link.bandwidth = cluster->loopback_bw;
         link.latency   = cluster->loopback_lat;
-        link.state     = SURF_RESOURCE_ON;
+        link.initiallyOn = 1;
         link.policy    = SURF_LINK_FATPIPE;
         sg_platf_new_link(&link);
         info_loop.link_up   = Link::byName(tmp_link);
@@ -931,7 +931,7 @@ void routing_new_cluster(sg_platf_cluster_cbarg_t cluster)
         link.id = tmp_link;
         link.bandwidth = cluster->limiter_link;
         link.latency = 0;
-        link.state = SURF_RESOURCE_ON;
+        link.initiallyOn = 1;
         link.policy = SURF_LINK_SHARED;
         sg_platf_new_link(&link);
         info_lim.link_up = Link::byName(tmp_link);
@@ -995,7 +995,7 @@ void routing_new_cluster(sg_platf_cluster_cbarg_t cluster)
     link.id        = link_backbone;
     link.bandwidth = cluster->bb_bw;
     link.latency   = cluster->bb_lat;
-    link.state     = SURF_RESOURCE_ON;
+    link.initiallyOn = 1;
     link.policy    = cluster->bb_sharing_policy;
 
     sg_platf_new_link(&link);
@@ -1040,7 +1040,7 @@ void sg_platf_new_peer(sg_platf_peer_cbarg_t peer)
   XBT_DEBUG("<host\tid=\"%s\"\tpower=\"%f\"/>", host_id, peer->speed);
   s_sg_platf_host_cbarg_t host = SG_PLATF_HOST_INITIALIZER;
   memset(&host, 0, sizeof(host));
-  host.initial_state = SURF_RESOURCE_ON;
+  host.initiallyOn = 1;
   host.id = host_id;
 
   host.speed_peak = xbt_dynar_new(sizeof(double), NULL);
@@ -1056,7 +1056,7 @@ void sg_platf_new_peer(sg_platf_peer_cbarg_t peer)
 
   s_sg_platf_link_cbarg_t link = SG_PLATF_LINK_INITIALIZER;
   memset(&link, 0, sizeof(link));
-  link.state   = SURF_RESOURCE_ON;
+  link.initiallyOn = 1;
   link.policy  = SURF_LINK_SHARED;
   link.latency = peer->lat;
 
index 04f9da6..4c92419 100644 (file)
@@ -157,7 +157,7 @@ void AsCluster::create_links_for_node(sg_platf_cluster_cbarg_t cluster, int id,
   link.id = link_id;
   link.bandwidth = cluster->bw;
   link.latency = cluster->lat;
-  link.state = SURF_RESOURCE_ON;
+  link.initiallyOn = 1;
   link.policy = cluster->sharing_policy;
   sg_platf_new_link(&link);
 
index 83ca962..7667c22 100644 (file)
@@ -508,7 +508,7 @@ FatTreeNode::FatTreeNode(sg_platf_cluster_cbarg_t cluster, int id, int level,
     memset(&linkTemplate, 0, sizeof(linkTemplate));
     linkTemplate.bandwidth = cluster->limiter_link;
     linkTemplate.latency = 0;
-    linkTemplate.state = SURF_RESOURCE_ON;
+    linkTemplate.initiallyOn = 1;
     linkTemplate.policy = SURF_LINK_SHARED;
     linkTemplate.id = bprintf("limiter_%d", id);
     sg_platf_new_link(&linkTemplate);
@@ -519,7 +519,7 @@ FatTreeNode::FatTreeNode(sg_platf_cluster_cbarg_t cluster, int id, int level,
     memset(&linkTemplate, 0, sizeof(linkTemplate));
     linkTemplate.bandwidth = cluster->loopback_bw;
     linkTemplate.latency = cluster->loopback_lat;
-    linkTemplate.state = SURF_RESOURCE_ON;
+    linkTemplate.initiallyOn = 1;
     linkTemplate.policy = SURF_LINK_FATPIPE;
     linkTemplate.id = bprintf("loopback_%d", id);
     sg_platf_new_link(&linkTemplate);
@@ -537,7 +537,7 @@ FatTreeLink::FatTreeLink(sg_platf_cluster_cbarg_t cluster,
   memset(&linkTemplate, 0, sizeof(linkTemplate));
   linkTemplate.bandwidth = cluster->bw;
   linkTemplate.latency = cluster->lat;
-  linkTemplate.state = SURF_RESOURCE_ON;
+  linkTemplate.initiallyOn = 1;
   linkTemplate.policy = cluster->sharing_policy; // sthg to do with that ?
   linkTemplate.id = bprintf("link_from_%d_to_%d_%d", downNode->id, upNode->id,
                             uniqueId);
index 645a313..ccbd304 100644 (file)
@@ -62,12 +62,12 @@ void AsClusterTorus::create_links_for_node(sg_platf_cluster_cbarg_t cluster, int
       memset(&link, 0, sizeof(link));
       current_dimension = xbt_dynar_get_as(p_dimensions, j, int);
       neighbour_rank_id = ( ((int) rank / dim_product) % current_dimension == current_dimension-1) ? rank - (current_dimension-1)*dim_product : rank + dim_product;
-      //name of neighbour is not right for non contiguous cluster radicals (as id != rank in this case)
+      //name of neighbor is not right for non contiguous cluster radicals (as id != rank in this case)
       link_id           = bprintf("%s_link_from_%i_to_%i", cluster->id, id, neighbour_rank_id);
       link.id           = link_id;
       link.bandwidth    = cluster->bw;
       link.latency      = cluster->lat;
-      link.state        = SURF_RESOURCE_ON;
+      link.initiallyOn  = 1;
       link.policy       = cluster->sharing_policy;
       sg_platf_new_link(&link);
       s_surf_parsing_link_up_down_t info;
index 6a81309..13002de 100644 (file)
@@ -472,9 +472,9 @@ void ETag_surfxml_host(void)    {
   xbt_assert((A_surfxml_host_state == A_surfxml_host_state_ON) ||
         (A_surfxml_host_state == A_surfxml_host_state_OFF), "Invalid state");
   if (A_surfxml_host_state == A_surfxml_host_state_ON)
-    host.initial_state = SURF_RESOURCE_ON;
+    host.initiallyOn = 1;
   if (A_surfxml_host_state == A_surfxml_host_state_OFF)
-    host.initial_state = SURF_RESOURCE_OFF;
+    host.initiallyOn = 1;
   host.coord = A_surfxml_host_coordinates;
 
   sg_platf_new_host(&host);
@@ -637,10 +637,10 @@ void ETag_surfxml_link(void){
 
   switch (A_surfxml_link_state) {
   case A_surfxml_link_state_ON:
-    link.state = SURF_RESOURCE_ON;
+    link.initiallyOn = 1;
     break;
   case A_surfxml_link_state_OFF:
-    link.state = SURF_RESOURCE_OFF;
+    link.initiallyOn = 0;
     break;
   default:
     surf_parse_error("invalid state for link %s", link.id);
@@ -698,7 +698,7 @@ void ETag_surfxml_backbone(void){
   link.id = A_surfxml_backbone_id;
   link.bandwidth = surf_parse_get_bandwidth(A_surfxml_backbone_bandwidth);
   link.latency = surf_parse_get_time(A_surfxml_backbone_latency);
-  link.state = SURF_RESOURCE_ON;
+  link.initiallyOn = 1;
   link.policy = SURF_LINK_SHARED;
 
   sg_platf_new_link(&link);
index 2f0478f..47f1b29 100644 (file)
@@ -81,7 +81,7 @@ tmgr_trace_t tmgr_trace_generator_value(const char *id,
  */
 tmgr_trace_t tmgr_trace_generator_state(const char *id,
                                   probabilist_event_generator_t date_generator,
-                                  e_surf_resource_state_t first_event_value)
+                                  int first_event_hostIsOn)
 {
   tmgr_trace_t trace = NULL;
 
@@ -91,7 +91,7 @@ tmgr_trace_t tmgr_trace_generator_state(const char *id,
   trace->s_probabilist.event_generator[0] = date_generator;
   trace->s_probabilist.event_generator[1] = date_generator;
   trace->s_probabilist.is_state_trace = 1;
-  trace->s_probabilist.next_event = (first_event_value==SURF_RESOURCE_ON ? 1 : 0);
+  trace->s_probabilist.next_event = first_event_hostIsOn;
 
   return trace;
 }
@@ -113,7 +113,7 @@ tmgr_trace_t tmgr_trace_generator_state(const char *id,
 tmgr_trace_t tmgr_trace_generator_avail_unavail(const char *id,
                                 probabilist_event_generator_t avail_duration_generator,
                                 probabilist_event_generator_t unavail_duration_generator,
-                                e_surf_resource_state_t first_event_value)
+                                int first_event_hostIsOn)
 {
   tmgr_trace_t trace = NULL;
 
@@ -123,7 +123,7 @@ tmgr_trace_t tmgr_trace_generator_avail_unavail(const char *id,
   trace->s_probabilist.event_generator[0] = unavail_duration_generator;
   trace->s_probabilist.event_generator[1] = avail_duration_generator;
   trace->s_probabilist.is_state_trace = 1;
-  trace->s_probabilist.next_event = (first_event_value==SURF_RESOURCE_ON ? 1 : 0);
+  trace->s_probabilist.next_event = first_event_hostIsOn;
 
   return trace;
 }
index dd64c88..cc11586 100644 (file)
@@ -33,7 +33,7 @@ VMModel::vm_list_t VMModel::ws_vms;
  * Resource *
  ************/
 
-VirtualMachine::VirtualMachine(Model *model, const char *name, xbt_dict_t props,simgrid::Host *hostPM)
+VirtualMachine::VirtualMachine(Model *model, const char *name, xbt_dict_t props, simgrid::Host *hostPM)
 : Host(model, name, props, NULL, NULL, NULL)
 , p_hostPM(hostPM)
 {
@@ -49,11 +49,29 @@ VirtualMachine::~VirtualMachine()
 {
   VMDestructedCallbacks(this);
   VMModel::ws_vms.erase(VMModel::vm_list_t::s_iterator_to(*this));
+  /* Free the cpu_action of the VM. */
+  XBT_ATTRIB_UNUSED int ret = p_action->unref();
+  xbt_assert(ret == 1, "Bug: some resource still remains");
 }
 
-void VirtualMachine::setState(e_surf_resource_state_t state){
-  Resource::setState(state);
-  VMStateChangedCallbacks(this);
+e_surf_vm_state_t VirtualMachine::getState() {
+  return p_vm_state;
+}
+
+void VirtualMachine::setState(e_surf_vm_state_t state) {
+  p_vm_state = state;
+}
+void VirtualMachine::turnOn() {
+  if (isOff()) {
+    Resource::turnOn();
+    VMStateChangedCallbacks(this);
+  }
+}
+void VirtualMachine::turnOff() {
+  if (isOn()) {
+    Resource::turnOff();
+    VMStateChangedCallbacks(this);
+  }
 }
 
 /** @brief returns the physical machine on which the VM is running **/
index c943946..7b78d6a 100644 (file)
@@ -68,8 +68,6 @@ public:
   /** @brief Destructor */
   ~VirtualMachine();
 
-  void setState(e_surf_resource_state_t state) override;
-
   /** @brief Suspend the VM */
   virtual void suspend()=0;
 
@@ -94,7 +92,17 @@ public:
   /* The vm object of the lower layer */
   CpuAction *p_action;
   simgrid::Host *p_hostPM;
-  e_surf_vm_state_t p_currentState;
+
+  void turnOn() override;
+  void turnOff() override;
+
+public:
+  e_surf_vm_state_t getState();
+  void setState(e_surf_vm_state_t state);
+protected:
+  e_surf_vm_state_t p_vm_state = SURF_VM_STATE_CREATED;
+
+
 public:
   boost::intrusive::list_member_hook<> vm_hook;
 };
index d326759..f073423 100644 (file)
@@ -180,7 +180,7 @@ VMHL13::VMHL13(VMModel *model, const char* name, xbt_dict_t props, sg_host_t hos
   sg_host_t host_VM = sg_host_by_name_or_create(name);
   host_VM->p_netcard = p_netElm;
 
-  p_currentState = SURF_VM_STATE_CREATED;
+  p_vm_state = SURF_VM_STATE_CREATED;
 
   // //// CPU  RELATED STUFF ////
   // Roughly, create a vcpu resource by using the values of the sub_cpu one.
@@ -192,7 +192,7 @@ VMHL13::VMHL13(VMModel *model, const char* name, xbt_dict_t props, sg_host_t hos
       1,                          // host->power_scale,
       NULL,                       // host->power_trace,
       1,                          // host->core_amount,
-      SURF_RESOURCE_ON,           // host->initial_state,
+      1/*ON*/,                    // host->initiallyOn,
       NULL);                      // host->state_trace,
 
   /* We create cpu_action corresponding to a VM process on the host operating system. */
@@ -203,64 +203,34 @@ VMHL13::VMHL13(VMModel *model, const char* name, xbt_dict_t props, sg_host_t hos
   XBT_INFO("Create VM(%s)@PM(%s) with %ld mounted disks", name, p_hostPM->getName().c_str(), xbt_dynar_length(p_storage));
 }
 
-/*
- * A physical host does not disappear in the current SimGrid code, but a VM may
- * disappear during a simulation.
- */
-VMHL13::~VMHL13()
-{
-  /* Free the cpu_action of the VM. */
-  XBT_ATTRIB_UNUSED int ret = p_action->unref();
-  xbt_assert(ret == 1, "Bug: some resource still remains");
-}
-
-void VMHL13::updateState(tmgr_trace_event_t /*event_type*/, double /*value*/, double /*date*/) {
-  THROW_IMPOSSIBLE;             /* This model does not implement parallel tasks */
-}
-
-bool VMHL13::isUsed() {
-  THROW_IMPOSSIBLE;             /* This model does not implement parallel tasks */
-  return -1;
-}
-
-e_surf_resource_state_t VMHL13::getState()
-{
-  return (e_surf_resource_state_t) p_currentState;
-}
-
-void VMHL13::setState(e_surf_resource_state_t state)
-{
-  p_currentState = (e_surf_vm_state_t) state;
-}
-
 void VMHL13::suspend()
 {
   p_action->suspend();
-  p_currentState = SURF_VM_STATE_SUSPENDED;
+  p_vm_state = SURF_VM_STATE_SUSPENDED;
 }
 
 void VMHL13::resume()
 {
   p_action->resume();
-  p_currentState = SURF_VM_STATE_RUNNING;
+  p_vm_state = SURF_VM_STATE_RUNNING;
 }
 
 void VMHL13::save()
 {
-  p_currentState = SURF_VM_STATE_SAVING;
+  p_vm_state = SURF_VM_STATE_SAVING;
 
   /* FIXME: do something here */
   p_action->suspend();
-  p_currentState = SURF_VM_STATE_SAVED;
+  p_vm_state = SURF_VM_STATE_SAVED;
 }
 
 void VMHL13::restore()
 {
-  p_currentState = SURF_VM_STATE_RESTORING;
+  p_vm_state = SURF_VM_STATE_RESTORING;
 
   /* FIXME: do something here */
   p_action->resume();
-  p_currentState = SURF_VM_STATE_RUNNING;
+  p_vm_state = SURF_VM_STATE_RUNNING;
 }
 
 /*
index df67e4f..04075eb 100644 (file)
@@ -51,7 +51,7 @@ public:
 class VMHL13 : public VirtualMachine {
 public:
   VMHL13(VMModel *model, const char* name, xbt_dict_t props, sg_host_t host_PM);
-  ~VMHL13();
+  ~VMHL13() {}
 
   void suspend() override;
   void resume() override;
@@ -61,15 +61,8 @@ public:
 
   void migrate(sg_host_t ind_dst_pm) override;
 
-  e_surf_resource_state_t getState() override;
-  void setState(e_surf_resource_state_t state) override;
-
   void setBound(double bound);
   void setAffinity(Cpu *cpu, unsigned long mask);
-
-  //FIXME: remove
-  void updateState(tmgr_trace_event_t event_type, double value, double date);
-  bool isUsed();
 };
 
 /**********