+Cpu::Cpu(){
+ surf_callback_emit(cpuCreatedCallbacks, this);
+}
+
+Cpu::Cpu(ModelPtr model, const char *name, xbt_dict_t props,
+ int core, double powerPeak, double powerScale)
+ : Resource(model, name, props)
+ , m_core(core)
+ , m_powerPeak(powerPeak)
+ , m_powerScale(powerScale)
+ , p_constraintCore(NULL)
+ , p_constraintCoreId(NULL)
+{
+ surf_callback_emit(cpuCreatedCallbacks, this);
+}
+
+Cpu::Cpu(ModelPtr model, const char *name, xbt_dict_t props,
+ lmm_constraint_t constraint, int core, double powerPeak, double powerScale)
+ : Resource(model, name, props, constraint)
+ , m_core(core)
+ , m_powerPeak(powerPeak)
+ , m_powerScale(powerScale)
+{
+ surf_callback_emit(cpuCreatedCallbacks, this);
+ /* At now, we assume that a VM does not have a multicore CPU. */
+ if (core > 1)
+ xbt_assert(model == surf_cpu_model_pm);
+
+ p_constraintCore = NULL;
+ p_constraintCoreId = NULL;
+ if (model->getUpdateMechanism() != UM_UNDEFINED) {
+ p_constraintCore = xbt_new(lmm_constraint_t, core);
+ p_constraintCoreId = xbt_new(void*, core);
+
+ int i;
+ for (i = 0; i < core; i++) {
+ /* just for a unique id, never used as a string. */
+ p_constraintCoreId[i] = bprintf("%s:%i", name, i);
+ p_constraintCore[i] = lmm_constraint_new(model->getMaxminSystem(), p_constraintCoreId[i], m_powerScale * m_powerPeak);
+ }
+ }
+}
+
+Cpu::~Cpu(){
+ surf_callback_emit(cpuDestructedCallbacks, this);
+ if (p_constraintCoreId){
+ for (int i = 0; i < m_core; i++) {
+ xbt_free(p_constraintCoreId[i]);
+ }
+ xbt_free(p_constraintCore);
+ }
+ if (p_constraintCoreId)
+ xbt_free(p_constraintCoreId);
+}
+
+double Cpu::getCurrentPowerPeak()
+{
+ return m_powerPeak;
+}