+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)
+{
+ /* 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(){
+ if (getModel()->getUpdateMechanism() != UM_UNDEFINED){
+ for (int i = 0; i < m_core; i++) {
+ xbt_free(p_constraintCoreId[i]);
+ }
+ xbt_free(p_constraintCore);
+ xbt_free(p_constraintCoreId);
+ }
+}
+