Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
changing namespace for cpu_interface
[simgrid.git] / src / plugins / host_energy.cpp
index f10c827..f380c16 100644 (file)
@@ -244,7 +244,7 @@ double HostEnergy::get_current_watts_value()
   if (this->pstate_ == pstate_off_) // The host is off (or was off at the beginning of this time interval)
     return this->watts_off_;
 
-  double current_speed = host_->get_speed();
+  double current_speed = host_->get_pstate_speed(this->pstate_);
 
   double cpu_load;
 
@@ -252,16 +252,17 @@ double HostEnergy::get_current_watts_value()
     // Some users declare a pstate of speed 0 flops (e.g., to model boot time).
     // We consider that the machine is then fully loaded. That's arbitrary but it avoids a NaN
     cpu_load = 1;
-  else
+  else {
     cpu_load = host_->pimpl_cpu->get_constraint()->get_usage() / current_speed;
 
-  /** Divide by the number of cores here **/
-  cpu_load /= host_->pimpl_cpu->get_core_count();
+    /** Divide by the number of cores here **/
+    cpu_load /= host_->pimpl_cpu->get_core_count();
 
-  if (cpu_load > 1) // A machine with a load > 1 consumes as much as a fully loaded machine, not more
-    cpu_load = 1;
-  if (cpu_load > 0)
-    host_was_used_ = true;
+    if (cpu_load > 1) // A machine with a load > 1 consumes as much as a fully loaded machine, not more
+      cpu_load = 1;
+    if (cpu_load > 0)
+      host_was_used_ = true;
+  }
 
   /* The problem with this model is that the load is always 0 or 1, never something less.
    * Another possibility could be to model the total energy as
@@ -410,10 +411,10 @@ static void on_creation(simgrid::s4u::Host& host)
   host.extension_set(new HostEnergy(&host));
 }
 
-static void on_action_state_change(simgrid::surf::CpuAction* action,
+static void on_action_state_change(simgrid::kernel::resource::CpuAction const& action,
                                    simgrid::kernel::resource::Action::State /*previous*/)
 {
-  for (simgrid::surf::Cpu* const& cpu : action->cpus()) {
+  for (simgrid::kernel::resource::Cpu* const& cpu : action.cpus()) {
     simgrid::s4u::Host* host = cpu->get_host();
     if (host != nullptr) {
 
@@ -433,9 +434,9 @@ static void on_action_state_change(simgrid::surf::CpuAction* action,
 
 /* This callback is fired either when the host changes its state (on/off) ("onStateChange") or its speed
  * (because the user changed the pstate, or because of external trace events) ("onSpeedChange") */
-static void on_host_change(simgrid::s4u::Host& host)
+static void on_host_change(simgrid::s4u::Host const& host)
 {
-  if (dynamic_cast<simgrid::s4u::VirtualMachine*>(&host)) // Ignore virtual machines
+  if (dynamic_cast<simgrid::s4u::VirtualMachine const*>(&host)) // Ignore virtual machines
     return;
 
   HostEnergy* host_energy = host.extension<HostEnergy>();
@@ -443,9 +444,9 @@ static void on_host_change(simgrid::s4u::Host& host)
   host_energy->update();
 }
 
-static void on_host_destruction(simgrid::s4u::Host& host)
+static void on_host_destruction(simgrid::s4u::Host const& host)
 {
-  if (dynamic_cast<simgrid::s4u::VirtualMachine*>(&host)) // Ignore virtual machines
+  if (dynamic_cast<simgrid::s4u::VirtualMachine const*>(&host)) // Ignore virtual machines
     return;
 
   XBT_INFO("Energy consumption of host %s: %f Joules", host.get_cname(),
@@ -489,16 +490,16 @@ void sg_host_energy_plugin_init()
   simgrid::s4u::Host::on_speed_change.connect(&on_host_change);
   simgrid::s4u::Host::on_destruction.connect(&on_host_destruction);
   simgrid::s4u::on_simulation_end.connect(&on_simulation_end);
-  simgrid::surf::CpuAction::on_state_change.connect(&on_action_state_change);
+  simgrid::kernel::resource::CpuAction::on_state_change.connect(&on_action_state_change);
   // We may only have one actor on a node. If that actor executes something like
   //   compute -> recv -> compute
   // the recv operation will not trigger a "CpuAction::on_state_change". This means
   // that the next trigger would be the 2nd compute, hence ignoring the idle time
   // during the recv call. By updating at the beginning of a compute, we can
   // fix that. (If the cpu is not idle, this is not required.)
-  simgrid::kernel::activity::ExecImpl::on_creation.connect([](simgrid::kernel::activity::ExecImplPtr activity){
-    if (activity->host_ != nullptr) { // We only run on one host
-      simgrid::s4u::Host* host = activity->host_;
+  simgrid::kernel::activity::ExecImpl::on_creation.connect([](simgrid::kernel::activity::ExecImpl const& activity) {
+    if (activity.get_host_number() == 1) { // We only run on one host
+      simgrid::s4u::Host* host         = activity.get_host();
       simgrid::s4u::VirtualMachine* vm = dynamic_cast<simgrid::s4u::VirtualMachine*>(host);
       if (vm != nullptr)
         host = vm->get_pm();