This keeps the main files clean of any energy related code.
Cpu::Cpu(){
surf_callback_emit(cpuCreatedCallbacks, this);
- physCpu = NULL;
}
Cpu::Cpu(Model *model, const char *name, xbt_dict_t props,
, p_constraintCoreId(NULL)
{
surf_callback_emit(cpuCreatedCallbacks, this);
- physCpu = NULL;
}
Cpu::Cpu(Model *model, const char *name, xbt_dict_t props,
p_constraintCore[i] = lmm_constraint_new(model->getMaxminSystem(), p_constraintCoreId[i], m_powerScale * m_powerPeak);
}
}
- physCpu = NULL;
}
Cpu::~Cpu(){
surf_callback_emit(cpuStateChangedCallbacks, this, old, state);
}
-void Cpu::setPhysicalCPU(Cpu *physCpu)
-{
- if (!surf_energy)
- return;
- this->physCpu = physCpu;
- XBT_DEBUG("The CPU is virtual so associate the cpu energy to the physical cpu instead of creating a new one");
- std::map<Cpu*, CpuEnergy*>::iterator cpu_energy_it = surf_energy->find(physCpu);
- xbt_assert(cpu_energy_it != surf_energy->end(), "The cpu is not in surf_energy.");
- (*surf_energy)[this] = cpu_energy_it->second;
-}
-
-Cpu* Cpu::getPhysicalCPU(void)
-{
- return physCpu;
-}
-
/**********
* Action *
**********/
*/
XBT_PUBLIC_CLASS CpuModel : public Model {
public:
- /** @brief Constructor */
CpuModel() : Model() {};
/**
void addTraces(void);
int m_core;
double m_powerPeak; /*< CPU power peak */
- double m_powerScale; /*< Percentage of CPU disponible */
+ double m_powerScale; /*< Percentage of CPU available */
/* Note (hypervisor): */
lmm_constraint_t *p_constraintCore;
void **p_constraintCoreId;
-
- // ////
- // Adrien - Oct 2015. Additional code related to VM energy extensions
- /* TODO:
- 1./ create a VirtualCpuModel that inherits from CpuModel or create
- a VirtualCpuCas01Model that inherit from CpuCas01Model
- => Question: not sure which one is really useful :( The objective is to
- be able to create a VirtualCpu instead of a Cpu (i.e. a CpuCas01 to be exact).
- 2. create VirtualCpu class that inherits from Cpu or create
- a VirtualCpuCas01 class that inherits from CpuCas01 (same issue as the one described above).
- Such modifications would enable us to remove the isVirtual method and
- actually use the polymorphism feature of C++. It will also enable us
- to overwrite the cpu_energy hashmap in energyCpuCreateCallBack instead of invoking
- setVirtual().
- So to make a long story short, it will be cleaner from the software viewpoint
- and patches welcome ;) - Adrien October 20 2015
- */
- Cpu *physCpu = NULL;
-
- /** @brief Specify the physical CPU of the current CPU (which is a vCPU) */
- void setPhysicalCPU(Cpu *physCpu);
-
- /** @brief Get the physical if the current one is a vCPU, or NULL if it's already a physical CPU */
- Cpu* getPhysicalCPU(void);
-
- // Adrien - Oct 2015. End of additional code related to VM energy extensions
- // ////
};
/**********
#include "energy.hpp"
#include "../cpu_cas01.hpp"
+#include "../virtual_machine.hpp"
/** @addtogroup SURF_plugin_energy
(*surf_energy)[cpu] = new CpuEnergy(cpu);
}
+static void energyVMCreatedCallback(VirtualMachine* vm) {
+ std::map<Cpu*, CpuEnergy*>::iterator cpu_energy_it = surf_energy->find(vm->p_subWs->p_cpu);
+ xbt_assert(cpu_energy_it != surf_energy->end(), "The cpu is not in surf_energy.");
+ (*surf_energy)[vm->p_cpu] = cpu_energy_it->second;
+ cpu_energy_it->second->ref(); // protect the CpuEnergy from getting deleted too early
+}
/* Computes the consumption so far. Called lazily on need. */
static void update_consumption(Cpu *cpu, CpuEnergy *cpu_energy) {
CpuEnergy *cpu_energy = cpu_energy_it->second;
update_consumption(cpu, cpu_energy);
- // Do nothing if that's a virtual CPU, only act for physical CPUs
- if(cpu->getPhysicalCPU() == NULL){
- XBT_INFO("Total energy of host %s: %f Joules", cpu->getName(), cpu_energy->getConsumedEnergy());
- delete cpu_energy_it->second;
- surf_energy->erase(cpu_energy_it);
- }
-
+ if (cpu_energy_it->second->refcount == 1) // Don't display anything for virtual CPUs
+ XBT_INFO("Total energy of host %s: %f Joules", cpu->getName(), cpu_energy->getConsumedEnergy());
+ cpu_energy_it->second->unref();
+ surf_energy->erase(cpu_energy_it);
}
static void energyCpuActionStateChangedCallback(CpuAction *action, e_surf_action_state_t old, e_surf_action_state_t cur){
if (surf_energy == NULL) {
surf_energy = new std::map<Cpu*, CpuEnergy*>();
surf_callback_connect(cpuCreatedCallbacks, energyCpuCreatedCallback);
+ surf_callback_connect(VMCreatedCallbacks, energyVMCreatedCallback);
surf_callback_connect(cpuDestructedCallbacks, energyCpuDestructedCallback);
surf_callback_connect(cpuActionStateChangedCallbacks, energyCpuActionStateChangedCallback);
surf_callback_connect(surfExitCallbacks, sg_energy_plugin_exit);
double total_energy; /*< Total energy consumed by the host */
double last_updated; /*< Timestamp of the last energy update event*/
Cpu *cpu;
+
+ void unref() {if (--refcount == 0) delete this;}
+ void ref() {refcount++;}
+ int refcount = 1;
};
#endif /* ENERGY_CALLBACK_HPP_ */
VMModel::ws_vms.push_back(*this);
xbt_lib_set(host_lib, name, SURF_HOST_LEVEL, this);
-
- surf_callback_emit(VMCreatedCallbacks, this);
}
/*
*************/
/** @ingroup SURF_callbacks
- * @brief Callbacks fired after VM creation. Signature: `void(VM*)`
+ * @brief Callbacks fired after VM creation. Signature: `void(VirtualMachine*)`
*/
extern XBT_PRIVATE surf_callback(void, VirtualMachine*) VMCreatedCallbacks;
/** @ingroup SURF_callbacks
- * @brief Callbacks fired after VM destruction. Signature: `void(VM*)`
+ * @brief Callbacks fired after VM destruction. Signature: `void(VirtualMachine*)`
*/
extern XBT_PRIVATE surf_callback(void, VirtualMachine*) VMDestructedCallbacks;
/** @ingroup SURF_callbacks
- * @brief Callbacks after VM State changes. Signature: `void(VMAction*)`
+ * @brief Callbacks after VM State changes. Signature: `void(VirtualMachine*)`
*/
extern XBT_PRIVATE surf_callback(void, VirtualMachine*) VMStateChangedCallbacks;
/* The vm object of the lower layer */
CpuAction *p_action;
- Host *p_subWs; // Pointer to the ''host'' OS
+ Host *p_subWs;
e_surf_vm_state_t p_currentState;
public:
boost::intrusive::list_member_hook<> vm_hook;
surf_resource_t host_PM)
: VirtualMachine(model, name, props, NULL, NULL)
{
- Host *sub_ws = static_cast<Host*>(surf_host_resource_priv(host_PM));
+ Host *sub_ws = surf_host_resource_priv(host_PM);
/* Currently, we assume a VM has no storage. */
p_storage = NULL;
NULL, // host->state_trace,
NULL); // host->properties,
- p_cpu->setPhysicalCPU(sub_cpu);
-
/* We create cpu_action corresponding to a VM process on the host operating system. */
/* FIXME: TODO: we have to periodically input GUESTOS_NOISE to the system? how ? */
// vm_ws->cpu_action = surf_cpu_model_pm->extension.cpu.execute(host_PM, GUESTOS_NOISE);
XBT_INFO("Create VM(%s)@PM(%s) with %ld mounted disks", name, sub_ws->getName(), xbt_dynar_length(p_storage));
+ surf_callback_emit(VMCreatedCallbacks, this);
}
/*