- It is moved to the plugin only.
- In particular, there is nothing in the core headers anymore
- SMPI still defines some energy methods
- the command-line config still needs to know the init method
Also, I'm sorry, but I renamed simgrid::Host->(p_cpu/p_netcard) to
pimpl_cpu/pimpl_netcard. I should have separated the rename, sorry.
#include "simgrid/msg.h"
#include "xbt/sysdep.h" /* calloc */
-#include "simgrid/plugins.h"
+#include "simgrid/plugins/energy.h"
/* Create a log channel to have nice outputs. */
#include "xbt/log.h"
XBT_INFO("Energetic profile: %s",
MSG_host_get_property_value(host,"watt_per_state"));
XBT_INFO("Initial peak speed=%.0E flop/s; Energy dissipated =%.0E J",
- MSG_host_get_current_power_peak(host), MSG_host_get_consumed_energy(host));
+ MSG_host_get_current_power_peak(host), sg_host_get_consumed_energy(host));
double start = MSG_get_clock();
XBT_INFO("Sleep for 10 seconds");
MSG_process_sleep(10);
XBT_INFO("Done sleeping (duration: %.2f s). Current peak speed=%.0E; Energy dissipated=%.2f J",
MSG_get_clock()-start,
- MSG_host_get_current_power_peak(host), MSG_host_get_consumed_energy(host));
+ MSG_host_get_current_power_peak(host), sg_host_get_consumed_energy(host));
// Run a task
start = MSG_get_clock();
MSG_task_destroy(task1);
XBT_INFO("Task done (duration: %.2f s). Current peak speed=%.0E flop/s; Current consumption: from %.0fW to %.0fW depending on load; Energy dissipated=%.0f J",
MSG_get_clock()-start,
- MSG_host_get_current_power_peak(host), MSG_host_get_wattmin_at(host,MSG_host_get_pstate(host)),
- MSG_host_get_wattmax_at(host,MSG_host_get_pstate(host)),
- MSG_host_get_consumed_energy(host));
+ MSG_host_get_current_power_peak(host), sg_host_get_wattmin_at(host,MSG_host_get_pstate(host)),
+ sg_host_get_wattmax_at(host,MSG_host_get_pstate(host)),
+ sg_host_get_consumed_energy(host));
// ========= Change power peak =========
int pstate=2;
MSG_task_destroy(task1);
XBT_INFO("Task done (duration: %.2f s). Current peak speed=%.0E flop/s; Energy dissipated=%.0f J",
MSG_get_clock()-start,
- MSG_host_get_current_power_peak(host), MSG_host_get_consumed_energy(host));
+ MSG_host_get_current_power_peak(host), sg_host_get_consumed_energy(host));
start = MSG_get_clock();
XBT_INFO("Sleep for 4 seconds");
MSG_process_sleep(4);
XBT_INFO("Done sleeping (duration: %.2f s). Current peak speed=%.0E flop/s; Energy dissipated=%.0f J",
MSG_get_clock()-start,
- MSG_host_get_current_power_peak(host), MSG_host_get_consumed_energy(host));
+ MSG_host_get_current_power_peak(host), sg_host_get_consumed_energy(host));
// =========== Turn the other host off ==========
XBT_INFO("Turning MyHost2 off, and sleeping another 10 seconds. MyHost2 dissipated %.0f J so far.",
- MSG_host_get_consumed_energy(MSG_host_by_name("MyHost2")) );
+ sg_host_get_consumed_energy(MSG_host_by_name("MyHost2")) );
MSG_host_off(MSG_host_by_name("MyHost2"));
start = MSG_get_clock();
MSG_process_sleep(10);
XBT_INFO("Done sleeping (duration: %.2f s). Current peak speed=%.0E flop/s; Energy dissipated=%.0f J",
MSG_get_clock()-start,
- MSG_host_get_current_power_peak(host), MSG_host_get_consumed_energy(host));
+ MSG_host_get_current_power_peak(host), sg_host_get_consumed_energy(host));
return 0;
}
/* 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. */
-#include<stdio.h>
+#include <stdio.h>
#include "simgrid/msg.h"
#include "xbt/sysdep.h" /* calloc */
-#include "simgrid/plugins.h"
+#include "simgrid/plugins/energy.h"
/* Create a log channel to have nice outputs. */
#include "xbt/log.h"
XBT_INFO("Energetic profile: %s",
MSG_host_get_property_value(host1,"watt_per_state"));
XBT_INFO("Initial peak speed=%.0E flop/s; Energy dissipated =%.0E J",
- MSG_host_get_current_power_peak(host1), MSG_host_get_consumed_energy(host1));
+ MSG_host_get_current_power_peak(host1), sg_host_get_consumed_energy(host1));
XBT_INFO("Sleep for 10 seconds");
MSG_process_sleep(10);
XBT_INFO("Done sleeping. Current peak speed=%.0E; Energy dissipated=%.2f J",
- MSG_host_get_current_power_peak(host1), MSG_host_get_consumed_energy(host1));
+ MSG_host_get_current_power_peak(host1), sg_host_get_consumed_energy(host1));
simulate_shutdown(host1);
XBT_INFO("Host1 is now OFF. Current peak speed=%.0E flop/s; Energy dissipated=%.0f J",
- MSG_host_get_current_power_peak(host1), MSG_host_get_consumed_energy(host1));
+ MSG_host_get_current_power_peak(host1), sg_host_get_consumed_energy(host1));
XBT_INFO("Sleep for 10 seconds");
MSG_process_sleep(10);
XBT_INFO("Done sleeping. Current peak speed=%.0E; Energy dissipated=%.2f J",
- MSG_host_get_current_power_peak(host1), MSG_host_get_consumed_energy(host1));
+ MSG_host_get_current_power_peak(host1), sg_host_get_consumed_energy(host1));
simulate_bootup(host1);
XBT_INFO("Host1 is now ON again. Current peak speed=%.0E flop/s; Energy dissipated=%.0f J",
- MSG_host_get_current_power_peak(host1), MSG_host_get_consumed_energy(host1));
+ MSG_host_get_current_power_peak(host1), sg_host_get_consumed_energy(host1));
return 0;
#include "simgrid/msg.h"
#include "xbt/sysdep.h" /* calloc */
-#include "simgrid/plugins.h"
+#include "simgrid/plugins/energy.h"
/* Create a log channel to have nice outputs. */
#include "xbt/log.h"
int getCoreAmount();
/* FIXME: these should be protected, but it leads to many errors */
- surf::Cpu *p_cpu = nullptr;
- surf::NetCard *p_netcard = nullptr;
+ surf::Cpu *pimpl_cpu = nullptr;
+ surf::NetCard *pimpl_netcard = nullptr;
private:
simgrid::xbt::string name_ = "noname";
public:
double getPowerPeakAt(int pstate_index);
void setPState(int pstate_index);
int getPState();
- double getWattMinAt(int pstate);
- double getWattMaxAt(int pstate);
void getParams(vm_params_t params);
void setParams(vm_params_t params);
xbt_dict_t getMountedStorageList();
XBT_PUBLIC(int) sg_host_get_nb_pstates(sg_host_t host);
XBT_PUBLIC(int) sg_host_get_pstate(sg_host_t host);
XBT_PUBLIC(void) sg_host_set_pstate(sg_host_t host,int pstate);
-XBT_PUBLIC(double) sg_host_get_consumed_energy(sg_host_t host);
SG_END_DECL()
XBT_PUBLIC(xbt_swag_t) MSG_host_get_process_list(msg_host_t h);
XBT_PUBLIC(int) MSG_host_is_on(msg_host_t h);
XBT_PUBLIC(int) MSG_host_is_off(msg_host_t h);
-XBT_PUBLIC(double) MSG_host_get_wattmin_at(msg_host_t host, int pstate);
-XBT_PUBLIC(double) MSG_host_get_wattmax_at(msg_host_t host, int pstate);
XBT_PUBLIC(double) MSG_host_get_power_peak_at(msg_host_t h, int pstate);
XBT_PUBLIC(double) MSG_host_get_current_power_peak(msg_host_t h);
XBT_PUBLIC(xbt_dynar_t) MSG_host_get_attached_storage_list(msg_host_t host);
XBT_PUBLIC(xbt_dict_t) MSG_host_get_storage_content(msg_host_t host);
-XBT_PUBLIC(double) MSG_host_get_consumed_energy(msg_host_t h);
-
/*property handlers*/
XBT_PUBLIC(xbt_dict_t) MSG_host_get_properties(msg_host_t host);
XBT_PUBLIC(const char *) MSG_host_get_property_value(msg_host_t host,
+++ /dev/null
-/* Copyright (c) 2014. The SimGrid Team.
- * All rights reserved. */
-
-/* This program is free software; you can redistribute it and/or modify it
- * under the terms of the license (GNU LGPL) which comes with this package. */
-
-#ifndef PLUGINS_H_
-#define PLUGINS_H_
-
-SG_BEGIN_DECL()
-
-/** \ingroup SURF_plugins
- * \brief The cpu energy consumption plugin
- */
-XBT_PUBLIC(void) sg_energy_plugin_init(void);
-
-SG_END_DECL()
-
-#endif /* PLUGINS_H_ */
XBT_PUBLIC(double) simcall_host_get_current_power_peak(sg_host_t host);
XBT_PUBLIC(double) simcall_host_get_power_peak_at(sg_host_t host, int pstate_index);
-XBT_PUBLIC(double) simcall_host_get_wattmin_at(sg_host_t host, int pstate);
-XBT_PUBLIC(double) simcall_host_get_wattmax_at(sg_host_t host, int pstate);
XBT_PUBLIC(smx_synchro_t) simcall_process_execute(const char *name,
double flops_amount,
#include "surf/surf_routing.h"
#include "simgrid/platf_interface.h"
#include "simgrid/datatypes.h"
-#include "simgrid/plugins.h"
#include "simgrid/forward.h"
SG_BEGIN_DECL()
*/
XBT_PUBLIC(double) surf_host_get_power_peak_at(sg_host_t host, int pstate_index);
-XBT_PUBLIC(double) surf_host_get_wattmin_at(sg_host_t resource, int pstate);
-XBT_PUBLIC(double) surf_host_get_wattmax_at(sg_host_t resource, int pstate);
-
-/**
- * @brief Get the consumed energy (in joules) of an host
- *
- * @param host The surf host
- * @return The consumed energy
- */
-XBT_PUBLIC(double) surf_host_get_consumed_energy(sg_host_t host);
-
/**
* @brief Get the list of storages mounted on an host
*
//Search for network_element_t
switch (kind){
case INSTR_HOST:
- newContainer->net_elm = sg_host->p_netcard;
+ newContainer->net_elm = sg_host->pimpl_netcard;
if(!newContainer->net_elm) xbt_die("Element '%s' not found",name);
break;
case INSTR_ROUTER:
return sg_host_get_nb_pstates(host);
}
-/** \ingroup m_host_management
- * \brief Return the total energy consumed by a host (in Joules). See also @ref SURF_plugin_energy.
- *
- * \param host host to test
- * \return Returns the consumed energy
- */
-double MSG_host_get_consumed_energy(msg_host_t host) {
- xbt_assert((host != NULL), "Invalid parameters (host is NULL)");
- return sg_host_get_consumed_energy(host);
-}
-/** \ingroup m_host_management
- * \brief Returns the amount of watt dissipated at the given pstate when the host is idling
- *
- */
-double MSG_host_get_wattmin_at(msg_host_t host, int pstate){
- return host->getWattMinAt(pstate);
-}
-/** \ingroup m_host_management
- * \brief Returns the amount of watt dissipated at the given pstate when the host burns CPU at 100%
- *
- */
-double MSG_host_get_wattmax_at(msg_host_t host, int pstate){
- return host->getWattMaxAt(pstate);
-}
-
/** \ingroup m_host_management
* \brief Return the list of mount point names on an host.
* \param host a host
* @return 1 if the host is active or 0 if it has crashed.
*/
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).
- *
- * See also @ref SURF_plugin_energy.
- */
-double sg_host_get_consumed_energy(sg_host_t host) {
- return surf_host_get_consumed_energy(host);
+ return host->pimpl_cpu->isOn();
}
/** @brief Returns the number of power states for a host.
* See also @ref SURF_plugin_energy.
*/
int sg_host_get_nb_pstates(sg_host_t host) {
- return host->p_cpu->getNbPStates();
+ return host->pimpl_cpu->getNbPStates();
}
/** @brief Gets the pstate at which that host currently runs.
}
bool Host::isOn() {
- return p_cpu->isOn();
+ return pimpl_cpu->isOn();
}
bool Host::isOff() {
- return ! p_cpu->isOn();
+ return ! pimpl_cpu->isOn();
}
/** @brief Get the speed of the cpu associated to a host */
double Host::getSpeed() {
- return p_cpu->getSpeed(1.0);
+ return pimpl_cpu->getSpeed(1.0);
}
/** @brief Returns the number of core of the processor. */
int Host::getCoreAmount() {
- return p_cpu->getCore();
+ return pimpl_cpu->getCore();
}
Host* Host::by_name_or_null(const char* name)
void Host::setPState(int pstate_index)
{
simgrid::simix::kernel(std::bind(
- &simgrid::surf::Cpu::setPState, p_cpu, pstate_index
+ &simgrid::surf::Cpu::setPState, pimpl_cpu, pstate_index
));
}
/** @brief Retrieve the pstate at which the host is currently running */
int Host::getPState()
{
- return p_cpu->getPState();
-}
-
-/** Get the amount of watt dissipated at the given pstate when the host is idling */
-double Host::getWattMinAt(int pstate)
-{
- return simgrid::simix::kernel(std::bind(
- surf_host_get_wattmin_at, this, pstate
- ));
-}
-
-/** Get the amount of watt dissipated at the given pstate when the host burns CPU at 100% */
-double Host::getWattMaxAt(int pstate)
-{
- return simgrid::simix::kernel(std::bind(
- surf_host_get_wattmax_at, this, pstate
- ));
+ return pimpl_cpu->getPState();
}
void Host::getParams(vm_params_t params)
return host->getPowerPeakAt(pstate_index);
}
-/** \ingroup simix_host_management
- * \deprecated */
-double simcall_host_get_wattmin_at(msg_host_t host, int pstate)
-{
- return host->getWattMinAt(pstate);
-}
-
-/** \ingroup simix_host_management
- * \deprecated */
-double simcall_host_get_wattmax_at(msg_host_t host, int pstate)
-{
- return host->getWattMaxAt(pstate);
-}
-
/** \deprecated */
void simcall_host_get_params(sg_host_t vm, vm_params_t params)
{
/* set surf's action */
if (!MC_is_active() && !MC_record_replay_is_active()) {
- synchro->execution.surf_exec = issuer->host->p_cpu->execute(flops_amount);
+ synchro->execution.surf_exec = issuer->host->pimpl_cpu->execute(flops_amount);
synchro->execution.surf_exec->setData(synchro);
synchro->execution.surf_exec->setPriority(priority);
/* just a double check to confirm that this host is the host where this task is running. */
xbt_assert(synchro->execution.host == issuer->host);
static_cast<simgrid::surf::CpuAction*>(synchro->execution.surf_exec)
- ->setAffinity(issuer->host->p_cpu, affinity_mask);
+ ->setAffinity(issuer->host->pimpl_cpu, affinity_mask);
}
}
/* just a double check to confirm that this host is the host where this task is running. */
xbt_assert(synchro->execution.host == host);
static_cast<simgrid::surf::CpuAction*>(synchro->execution.surf_exec)
- ->setAffinity(host->p_cpu, mask);
+ ->setAffinity(host->pimpl_cpu, mask);
}
}
/* 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. */
+#include "simgrid/plugins/energy.h" // FIXME: this plugin should be separated from the core
#include "xbt/log.h"
#include "simgrid/simix.h"
#include "smpi/smpi.h"
/* connect all traces relative to hosts */
xbt_dict_foreach(trace_connect_list_host_avail, cursor, trace_name, elm) {
tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name);
- CpuCas01 *host = static_cast<CpuCas01*>(sg_host_by_name(elm)->p_cpu);
+ CpuCas01 *host = static_cast<CpuCas01*>(sg_host_by_name(elm)->pimpl_cpu);
xbt_assert(host, "Host %s undefined", elm);
xbt_assert(trace, "Trace %s undefined", trace_name);
xbt_dict_foreach(trace_connect_list_power, cursor, trace_name, elm) {
tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name);
- CpuCas01 *host = static_cast<CpuCas01*>(sg_host_by_name(elm)->p_cpu);
+ CpuCas01 *host = static_cast<CpuCas01*>(sg_host_by_name(elm)->pimpl_cpu);
xbt_assert(host, "Host %s undefined", elm);
xbt_assert(trace, "Trace %s undefined", trace_name);
, m_speedScale(speedScale)
, m_host(host)
{
- host->p_cpu = this;
+ host->pimpl_cpu = this;
xbt_assert(m_speedScale > 0, "Available speed has to be >0");
// Copy the power peak array:
/* connect all traces relative to hosts */
xbt_dict_foreach(trace_connect_list_host_avail, cursor, trace_name, elm) {
tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name);
- CpuTi *cpu = static_cast<CpuTi*>(sg_host_by_name(elm)->p_cpu);
+ CpuTi *cpu = static_cast<CpuTi*>(sg_host_by_name(elm)->pimpl_cpu);
xbt_assert(cpu, "Host %s undefined", elm);
xbt_assert(trace, "Trace %s undefined", trace_name);
xbt_dict_foreach(trace_connect_list_power, cursor, trace_name, elm) {
tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name);
- CpuTi *cpu = static_cast<CpuTi*>(sg_host_by_name(elm)->p_cpu);
+ CpuTi *cpu = static_cast<CpuTi*>(sg_host_by_name(elm)->pimpl_cpu);
xbt_assert(cpu, "Host %s undefined", elm);
xbt_assert(trace, "Trace %s undefined", trace_name);
Action *action =NULL;
if ((host_nb == 1)
&& (cost_or_zero(bytes_amount, 0) == 0.0)){
- action = host_list[0]->p_cpu->execute(flops_amount[0]);
+ action = host_list[0]->pimpl_cpu->execute(flops_amount[0]);
} else if ((host_nb == 1)
&& (cost_or_zero(flops_amount, 0) == 0.0)) {
- action = surf_network_model->communicate(host_list[0]->p_netcard,
- host_list[0]->p_netcard,
+ action = surf_network_model->communicate(host_list[0]->pimpl_netcard,
+ host_list[0]->pimpl_netcard,
bytes_amount[0], rate);
} else if ((host_nb == 2)
&& (cost_or_zero(flops_amount, 0) == 0.0)
}
}
if (nb == 1){
- action = surf_network_model->communicate(host_list[0]->p_netcard,
- host_list[1]->p_netcard,
+ action = surf_network_model->communicate(host_list[0]->pimpl_netcard,
+ host_list[1]->pimpl_netcard,
value, rate);
}
} else
this->p_netcardList->reserve(host_nb);
for (int i = 0; i<host_nb; i++)
- this->p_netcardList->push_back(host_list[i]->p_netcard);
+ this->p_netcardList->push_back(host_list[i]->pimpl_netcard);
/* Compute the number of affected resources... */
for (int i = 0; i < host_nb; i++) {
for (int i = 0; i < host_nb; i++)
lmm_expand(model->getMaxminSystem(),
- host_list[i]->p_cpu->getConstraint(),
+ host_list[i]->pimpl_cpu->getConstraint(),
this->getVariable(), flops_amount[i]);
for (int i = 0; i < host_nb; i++) {
/* Connect traces relative to cpu */
xbt_dict_foreach(trace_connect_list_host_avail, cursor, trace_name, elm) {
tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name);
- CpuL07 *host = static_cast<CpuL07*>(sg_host_by_name(elm)->p_cpu);
+ CpuL07 *host = static_cast<CpuL07*>(sg_host_by_name(elm)->pimpl_cpu);
xbt_assert(host, "Host %s undefined", elm);
xbt_assert(trace, "Trace %s undefined", trace_name);
xbt_dict_foreach(trace_connect_list_power, cursor, trace_name, elm) {
tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name);
- CpuL07 *host = static_cast<CpuL07*>(sg_host_by_name(elm)->p_cpu);
+ CpuL07 *host = static_cast<CpuL07*>(sg_host_by_name(elm)->pimpl_cpu);
xbt_assert(host, "Host %s undefined", elm);
xbt_assert(trace, "Trace %s undefined", trace_name);
/* 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. */
+#include <simgrid/plugins/energy.h>
+#include <simgrid/simix.hpp>
#include <src/surf/plugins/energy.hpp>
#include <src/surf/cpu_interface.hpp>
#include <src/surf/virtual_machine.hpp>
host->getName(), start_time, finish_time, host->p_cpu->m_speedPeak, previous_energy, energy_this_step);
}
-/** \ingroup SURF_plugin_energy
- * \brief Enable energy plugin
- * \details Enable energy plugin to get joules consumption of each cpu. You should call this function before #MSG_init().
- */
-void sg_energy_plugin_init() {
- if (simgrid::energy::surf_energy == NULL) {
-
- simgrid::energy::surf_energy = new std::map<simgrid::surf::Host*, simgrid::energy::HostEnergy*>();
-
- /* 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) {
- 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 = sg_host_by_name(name)->extension<simgrid::surf::Host>();
- simgrid::surf::VirtualMachine *vm = dynamic_cast<simgrid::surf::VirtualMachine*>(host);
- if (vm) // If it's a VM, take the corresponding PM
- host = vm->getPm()->extension<simgrid::surf::Host>();
-
- 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;
- });
- }
-}
-
namespace simgrid {
namespace energy {
return power_range_list;
}
+
+double surf_host_get_wattmin_at(sg_host_t host, int pstate){
+ xbt_assert(surf_energy!=NULL, "The Energy plugin is not active. Please call sg_energy_plugin_init() during initialization.");
+ std::map<simgrid::surf::Host*, HostEnergy*>::iterator hostIt = surf_energy->find(host->extension<simgrid::surf::Host>());
+ return hostIt->second->getWattMinAt(pstate);
+}
+double surf_host_get_wattmax_at(sg_host_t host, int pstate){
+ xbt_assert(surf_energy!=NULL, "The Energy plugin is not active. Please call sg_energy_plugin_init() during initialization.");
+ std::map<simgrid::surf::Host*, HostEnergy*>::iterator hostIt = surf_energy->find(host->extension<simgrid::surf::Host>());
+ return hostIt->second->getWattMaxAt(pstate);
+}
+
+double surf_host_get_consumed_energy(sg_host_t host){
+ xbt_assert(surf_energy!=NULL, "The Energy plugin is not active. Please call sg_energy_plugin_init() during initialization.");
+ std::map<simgrid::surf::Host*, HostEnergy*>::iterator hostIt = surf_energy->find(host->extension<simgrid::surf::Host>());
+ return hostIt->second->getConsumedEnergy();
+}
+
+}
+}
+
+/* **************************** Public interface *************************** */
+
+/** \ingroup SURF_plugin_energy
+ * \brief Enable energy plugin
+ * \details Enable energy plugin to get joules consumption of each cpu. You should call this function before #MSG_init().
+ */
+void sg_energy_plugin_init() {
+ if (simgrid::energy::surf_energy == NULL) {
+
+ simgrid::energy::surf_energy = new std::map<simgrid::surf::Host*, simgrid::energy::HostEnergy*>();
+
+ /* 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) {
+ 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 = sg_host_by_name(name)->extension<simgrid::surf::Host>();
+ simgrid::surf::VirtualMachine *vm = dynamic_cast<simgrid::surf::VirtualMachine*>(host);
+ if (vm) // If it's a VM, take the corresponding PM
+ host = vm->getPm()->extension<simgrid::surf::Host>();
+
+ 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;
+ });
+ }
+}
+
+/** @brief Returns the total energy consumed by the host so far (in Joules)
+ *
+ * See also @ref SURF_plugin_energy.
+ */
+double sg_host_get_consumed_energy(sg_host_t host) {
+ return simgrid::energy::surf_host_get_consumed_energy(host);
+}
+
+/** @brief Get the amount of watt dissipated at the given pstate when the host is idling */
+double sg_host_get_wattmin_at(sg_host_t host, int pstate) {
+ return simgrid::simix::kernel(std::bind(
+ simgrid::energy::surf_host_get_wattmin_at, host, pstate
+ ));
}
+/** @brief Returns the amount of watt dissipated at the given pstate when the host burns CPU at 100% */
+double sg_host_get_wattmax_at(sg_host_t host, int pstate) {
+ return simgrid::simix::kernel(std::bind(
+ simgrid::energy::surf_host_get_wattmax_at, host, pstate
+ ));
}
-/* Copyright (c) 2014-2015. The SimGrid Team.
+/* energy.hpp: internal interface to the energy plugin */
+
+/* Copyright (c) 2014-2016. The SimGrid Team.
* All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it
int refcount = 1;
};
+XBT_PUBLIC(double) surf_host_get_wattmin_at(sg_host_t resource, int pstate);
+XBT_PUBLIC(double) surf_host_get_wattmax_at(sg_host_t resource, int pstate);
+XBT_PUBLIC(double) surf_host_get_consumed_energy(sg_host_t host);
}
}
+
+
#endif /* ENERGY_CALLBACK_HPP_ */
* TOOLS *
*********/
-static simgrid::surf::Host *get_casted_host(sg_host_t host){
+static simgrid::surf::Host *get_casted_host(sg_host_t host){ //FIXME: killme
return host->extension<simgrid::surf::Host>();
}
}
surf_action_t surf_network_model_communicate(surf_network_model_t model, sg_host_t src, sg_host_t dst, double size, double rate){
- return model->communicate(src->p_netcard, dst->p_netcard, size, rate);
+ return model->communicate(src->pimpl_netcard, dst->pimpl_netcard, size, rate);
}
const char *surf_resource_name(surf_cpp_resource_t resource){
}
surf_action_t surf_host_sleep(sg_host_t host, double duration){
- return host->p_cpu->sleep(duration);
+ return host->pimpl_cpu->sleep(duration);
}
xbt_dict_t sg_host_get_properties(sg_host_t host) {
}
double surf_host_get_available_speed(sg_host_t host){
- return host->p_cpu->getAvailableSpeed();
+ return host->pimpl_cpu->getAvailableSpeed();
}
double surf_host_get_current_power_peak(sg_host_t host){
- return host->p_cpu->getCurrentPowerPeak();
+ return host->pimpl_cpu->getCurrentPowerPeak();
}
double surf_host_get_power_peak_at(sg_host_t host, int pstate_index){
- return host->p_cpu->getPowerPeakAt(pstate_index);
+ return host->pimpl_cpu->getPowerPeakAt(pstate_index);
}
-using simgrid::energy::HostEnergy;
-using simgrid::energy::surf_energy;
-
-double surf_host_get_wattmin_at(sg_host_t resource, int pstate){
- xbt_assert(surf_energy!=NULL, "The Energy plugin is not active. Please call sg_energy_plugin_init() during initialization.");
- std::map<simgrid::surf::Host*, HostEnergy*>::iterator hostIt = surf_energy->find(get_casted_host(resource));
- return hostIt->second->getWattMinAt(pstate);
-}
-double surf_host_get_wattmax_at(sg_host_t resource, int pstate){
- xbt_assert(surf_energy!=NULL, "The Energy plugin is not active. Please call sg_energy_plugin_init() during initialization.");
- std::map<simgrid::surf::Host*, HostEnergy*>::iterator hostIt = surf_energy->find(get_casted_host(resource));
- return hostIt->second->getWattMaxAt(pstate);
-}
-
-double surf_host_get_consumed_energy(sg_host_t resource){
- xbt_assert(surf_energy!=NULL, "The Energy plugin is not active. Please call sg_energy_plugin_init() during initialization.");
- std::map<simgrid::surf::Host*, HostEnergy*>::iterator hostIt = surf_energy->find(get_casted_host(resource));
- return hostIt->second->getConsumedEnergy();
-}
xbt_dict_t surf_host_get_mounted_storage_list(sg_host_t host){
return get_casted_host(host)->getMountedStorageList();
}
void surf_vm_destroy(sg_host_t vm){ // FIXME:DEADCODE
- vm->p_cpu = nullptr;
- vm->p_netcard = nullptr;
+ vm->pimpl_cpu = nullptr;
+ vm->pimpl_netcard = nullptr;
}
void surf_vm_suspend(sg_host_t vm){
}
void surf_vm_set_affinity(sg_host_t vm, sg_host_t host, unsigned long mask){
- return get_casted_vm(vm)->setAffinity(host->p_cpu, mask);
+ return get_casted_vm(vm)->setAffinity(host->pimpl_cpu, mask);
}
xbt_dict_t surf_storage_get_content(surf_resource_t resource){
}
void surf_cpu_action_set_affinity(surf_action_t action, sg_host_t host, unsigned long mask) {
- static_cast<simgrid::surf::CpuAction*>(action)->setAffinity(host->p_cpu, mask);
+ static_cast<simgrid::surf::CpuAction*>(action)->setAffinity(host->pimpl_cpu, mask);
}
void surf_cpu_action_set_bound(surf_action_t action, double bound) {
}
}
+#include <simgrid/plugins/energy.h> // FIXME: this plugin should not be linked to the core
+
s_surf_model_description_t surf_plugin_description[] = {
{"Energy", "Cpu energy consumption.", sg_energy_plugin_init},
{NULL, NULL, NULL} /* this array must be NULL terminated */
simgrid::surf::NetCard *sg_netcard_by_name_or_null(const char *name)
{
sg_host_t h = sg_host_by_name(name);
- simgrid::surf::NetCard *net_elm = h==NULL?NULL: h->p_netcard;
+ simgrid::surf::NetCard *net_elm = h==NULL?NULL: h->pimpl_netcard;
if (!net_elm)
net_elm = (simgrid::surf::NetCard*) xbt_lib_get_or_null(as_router_lib, name, ROUTING_ASR_LEVEL);
return net_elm;
*/
void sg_platf_new_netcard(sg_platf_host_link_cbarg_t netcard)
{
- simgrid::surf::NetCard *info = sg_host_by_name(netcard->id)->p_netcard;
+ simgrid::surf::NetCard *info = sg_host_by_name(netcard->id)->pimpl_netcard;
xbt_assert(info, "Host '%s' not found!", netcard->id);
xbt_assert(current_routing->p_modelDesc == &routing_models[SURF_MODEL_CLUSTER] ||
current_routing->p_modelDesc == &routing_models[SURF_MODEL_VIVALDI],
current_routing);
netcard->setId(current_routing->parsePU(netcard));
sg_host_t h = sg_host_by_name_or_create(host->id);
- h->p_netcard = netcard;
+ h->pimpl_netcard = netcard;
XBT_DEBUG("Having set name '%s' id '%d'", host->id, netcard->getId());
simgrid::surf::routingEdgeCreatedCallbacks(netcard);
As *AsGeneric::processingUnitsExist(char *element)
{
- As *element_as = sg_host_by_name(element)->p_netcard ->getRcComponent();
+ As *element_as = sg_host_by_name(element)->pimpl_netcard ->getRcComponent();
if (element_as == this)
return element_as;
return asExist(element_as);
#define cost_or_zero(array,pos) ((array)?(array)[pos]:0.0)
if ((host_nb == 1)
&& (cost_or_zero(bytes_amount, 0) == 0.0))
- return host_list[0]->p_cpu->execute(flops_amount[0]);
+ return host_list[0]->pimpl_cpu->execute(flops_amount[0]);
else if ((host_nb == 1)
&& (cost_or_zero(flops_amount, 0) == 0.0))
return surf_network_model_communicate(surf_network_model, host_list[0], host_list[0],bytes_amount[0], rate);
* from the VM name, we have to make sure that the system does not call the
* free callback for the network resource object. The network resource object
* is still used by the physical machine. */
- p_netElm = host_PM->p_netcard;
+ p_netElm = host_PM->pimpl_netcard;
sg_host_t host_VM = sg_host_by_name_or_create(name);
- host_VM->p_netcard = p_netElm;
+ host_VM->pimpl_netcard = p_netElm;
p_vm_state = SURF_VM_STATE_CREATED;
// //// CPU RELATED STUFF ////
// Roughly, create a vcpu resource by using the values of the sub_cpu one.
- CpuCas01 *sub_cpu = static_cast<CpuCas01*>(host_PM->p_cpu);
+ CpuCas01 *sub_cpu = static_cast<CpuCas01*>(host_PM->pimpl_cpu);
p_cpu = surf_cpu_model_vm->createCpu(host_VM, // the machine hosting the VM
sub_cpu->getSpeedPeakList(), // host->power_peak,
const char *pm_name_dst = surfHost_dst->getName();
/* update net_elm with that of the destination physical host */
- sg_host_by_name(vm_name)->p_netcard = p_netElm = sg_host_by_name(pm_name_dst)->p_netcard;
+ sg_host_by_name(vm_name)->pimpl_netcard = p_netElm = sg_host_by_name(pm_name_dst)->pimpl_netcard;
p_hostPM = host_dest;
/* Update vcpu's action for the new pm */
{
/* create a cpu action bound to the pm model at the destination. */
- CpuAction *new_cpu_action = static_cast<CpuAction*>(host_dest->p_cpu->execute(0));
+ CpuAction *new_cpu_action = static_cast<CpuAction*>(host_dest->pimpl_cpu->execute(0));
e_surf_action_state_t state = p_action->getState();
if (state != SURF_ACTION_DONE)
sg_host_t host1, host2;
xbt_dict_foreach(host_list, cursor_src, src, host1) // Routes from host
{
- value1 = sg_host_by_name(src)->p_netcard;
+ value1 = sg_host_by_name(src)->pimpl_netcard;
xbt_dict_foreach(host_list, cursor_dst, dst, host2) //to host
{
printf(" <route src=\"%s\" dst=\"%s\">\n "
,src
,dst);
xbt_dynar_t route=NULL;
- value2 = sg_host_by_name(dst)->p_netcard;
+ value2 = sg_host_by_name(dst)->pimpl_netcard;
routing_get_route_and_latency(value1, value2, &route,NULL);
for(i=0;i<xbt_dynar_length(route) ;i++)
{
printf(" <route src=\"%s\" dst=\"%s\">\n "
,src, dst);
xbt_dynar_t route=NULL;
- value2 = sg_host_by_name(dst)->p_netcard;
+ value2 = sg_host_by_name(dst)->pimpl_netcard;
routing_get_route_and_latency((sg_netcard_t)value1,(sg_netcard_t)value2,&route, NULL);
for(i=0;i<xbt_dynar_length(route) ;i++)
{
hostB = sg_host_by_name("Cpu B");
/* Let's check that those two processors exist */
- XBT_DEBUG("%s : %p", surf_cpu_name(hostA->p_cpu), hostA);
- XBT_DEBUG("%s : %p", surf_cpu_name(hostB->p_cpu), hostB);
+ XBT_DEBUG("%s : %p", surf_cpu_name(hostA->pimpl_cpu), hostA);
+ XBT_DEBUG("%s : %p", surf_cpu_name(hostB->pimpl_cpu), hostB);
/* Let's do something on it */
- actionA = hostA->p_cpu->execute(1000.0);
- actionB = hostB->p_cpu->execute(1000.0);
+ actionA = hostA->pimpl_cpu->execute(1000.0);
+ actionB = hostB->pimpl_cpu->execute(1000.0);
actionC = surf_host_sleep(hostB, 7.32);
/* Use whatever calling style you want... */
XBT_DEBUG("%s : %p", sg_host_get_name(hostB), hostB);
/* Let's do something on it */
- hostA->p_cpu->execute(1000.0);
- hostB->p_cpu->execute(1000.0);
+ hostA->pimpl_cpu->execute(1000.0);
+ hostB->pimpl_cpu->execute(1000.0);
surf_host_sleep(hostB, 7.32);
surf_network_model_communicate(surf_network_model, hostA, hostB, 150.0, -1.0);
include/simdag/simdag.h
include/simdag/datatypes.h
+ include/simgrid/plugins/energy.h
include/simgrid/instr.h
include/simgrid/msg.h
include/simgrid/simdag.h
include/simgrid/forward.h
include/simgrid/platf.h
include/simgrid/platf_generator.h
- include/simgrid/plugins.h
include/simgrid/simix.h
include/simgrid/simix.hpp
include/simgrid/host.h