X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/d0ffc37686edcc803601f76ab51fdfed5fc2f241..191e4e2f00fb2f5fecb9f648f195b47a5ec61682:/src/surf/cpu_cas01.cpp diff --git a/src/surf/cpu_cas01.cpp b/src/surf/cpu_cas01.cpp index 61e1e9ee39..648e0c4ec6 100644 --- a/src/surf/cpu_cas01.cpp +++ b/src/surf/cpu_cas01.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2009-2011. The SimGrid Team. +/* Copyright (c) 2009-2011, 2013. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -6,28 +6,22 @@ #include "cpu_cas01.hpp" #include "cpu_ti.hpp" -#include "surf.hpp" #include "maxmin_private.h" #include "simgrid/sg_config.h" -extern "C" { XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_cpu_cas, surf_cpu, "Logging specific to the SURF CPU IMPROVED module"); -} - -static xbt_swag_t - cpu_running_action_set_that_does_not_need_being_checked = NULL; /************* * CallBacks * *************/ static void parse_cpu_init(sg_platf_host_cbarg_t host){ - ((CpuCas01ModelPtr)surf_cpu_model)->parseInit(host); + ((CpuCas01ModelPtr)surf_cpu_model_pm)->parseInit(host); } static void cpu_add_traces_cpu(){ - surf_cpu_model->addTraces(); + surf_cpu_model_pm->addTraces(); } static void cpu_define_callbacks() @@ -43,24 +37,28 @@ void surf_cpu_model_init_Cas01() { char *optim = xbt_cfg_get_string(_sg_cfg_set, "cpu/optim"); - if (surf_cpu_model) - return; + xbt_assert(!surf_cpu_model_pm); + xbt_assert(!surf_cpu_model_vm); if (!strcmp(optim, "TI")) { surf_cpu_model_init_ti(); return; } - surf_cpu_model = new CpuCas01Model(); + surf_cpu_model_pm = new CpuCas01Model(); + surf_cpu_model_vm = new CpuCas01Model(); + cpu_define_callbacks(); - ModelPtr model = static_cast(surf_cpu_model); - xbt_dynar_push(model_list, &model); + ModelPtr model_pm = static_cast(surf_cpu_model_pm); + ModelPtr model_vm = static_cast(surf_cpu_model_vm); + xbt_dynar_push(model_list, &model_pm); + xbt_dynar_push(model_list, &model_vm); } CpuCas01Model::CpuCas01Model() : CpuModel("cpu") { - ActionPtr action; - ActionLmmPtr actionlmm; + ActionPtr action = NULL; + ActionLmmPtr actionlmm = NULL; char *optim = xbt_cfg_get_string(_sg_cfg_set, "cpu/optim"); int select = xbt_cfg_get_boolean(_sg_cfg_set, "cpu/maxmin_selective_update"); @@ -80,7 +78,7 @@ CpuCas01Model::CpuCas01Model() : CpuModel("cpu") xbt_die("Unsupported optimization (%s) for this model", optim); } - cpu_running_action_set_that_does_not_need_being_checked = + p_cpuRunningActionSetThatDoesNotNeedBeingChecked = xbt_swag_new(xbt_swag_offset(*action, p_stateHookup)); if (p_updateMechanism == UM_LAZY) { @@ -114,10 +112,9 @@ CpuCas01Model::~CpuCas01Model() xbt_heap_free(p_actionHeap); xbt_swag_free(p_modifiedSet); - surf_cpu_model = NULL; + surf_cpu_model_pm = NULL; - xbt_swag_free(cpu_running_action_set_that_does_not_need_being_checked); - cpu_running_action_set_that_does_not_need_being_checked = NULL; + xbt_swag_free(p_cpuRunningActionSetThatDoesNotNeedBeingChecked); } void CpuCas01Model::parseInit(sg_platf_host_cbarg_t host) @@ -133,7 +130,7 @@ void CpuCas01Model::parseInit(sg_platf_host_cbarg_t host) host->properties); } -CpuCas01LmmPtr CpuCas01Model::createResource(const char *name, xbt_dynar_t power_peak, +CpuPtr CpuCas01Model::createResource(const char *name, xbt_dynar_t power_peak, int pstate, double power_scale, tmgr_trace_t power_trace, int core, e_surf_resource_state_t state_initial, @@ -144,16 +141,17 @@ CpuCas01LmmPtr CpuCas01Model::createResource(const char *name, xbt_dynar_t power xbt_assert(!surf_cpu_resource_priv(surf_cpu_resource_by_name(name)), "Host '%s' declared several times in the platform file", name); - xbt_assert(power_peak > 0, "Power has to be >0"); + xbt_assert(xbt_dynar_getfirst_as(power_peak, double) > 0.0, + "Power has to be >0.0"); xbt_assert(core > 0, "Invalid number of cores %d", core); cpu = new CpuCas01Lmm(this, name, power_peak, pstate, power_scale, power_trace, core, state_initial, state_trace, cpu_properties); xbt_lib_set(host_lib, name, SURF_CPU_LEVEL, static_cast(cpu)); - return (CpuCas01LmmPtr) xbt_lib_get_elm_or_null(host_lib, name); + return cpu; } -double CpuCas01Model::shareResourcesFull(double now) +double CpuCas01Model::shareResourcesFull(double /*now*/) { return Model::shareResourcesMaxMin(p_runningActionSet, p_maxminSystem, lmm_solve); @@ -196,11 +194,12 @@ void CpuCas01Model::addTraces() * Resource * ************/ CpuCas01Lmm::CpuCas01Lmm(CpuCas01ModelPtr model, const char *name, xbt_dynar_t powerPeak, - int pstate, double powerScale, tmgr_trace_t powerTrace, int core, - e_surf_resource_state_t stateInitial, tmgr_trace_t stateTrace, - xbt_dict_t properties) : - CpuLmm(model, name, properties), Resource(model, name, properties) { - m_powerPeak = xbt_dynar_get_as(powerPeak, pstate, double); + int pstate, double powerScale, tmgr_trace_t powerTrace, int core, + e_surf_resource_state_t stateInitial, tmgr_trace_t stateTrace, + xbt_dict_t properties) +: Resource(model, name, properties) +, CpuLmm(model, name, properties, core, xbt_dynar_get_as(powerPeak, pstate, double), powerScale) { + p_powerEvent = NULL; p_powerPeakList = powerPeak; m_pstate = pstate; @@ -211,7 +210,6 @@ CpuCas01Lmm::CpuCas01Lmm(CpuCas01ModelPtr model, const char *name, xbt_dynar_t p XBT_DEBUG("CPU create: peak=%f, pstate=%d", m_powerPeak, m_pstate); - m_powerScale = powerScale; m_core = core; p_stateCurrent = stateInitial; if (powerTrace) @@ -231,7 +229,6 @@ CpuCas01Lmm::~CpuCas01Lmm(){ xbt_dynar_free(&p_energy->power_range_watts_list); xbt_dynar_free(&p_powerPeakList); xbt_free(p_energy); - return; } bool CpuCas01Lmm::isUsed() @@ -245,8 +242,11 @@ void CpuCas01Lmm::updateState(tmgr_trace_event_t event_type, double value, doubl lmm_element_t elem = NULL; if (event_type == p_powerEvent) { + /* TODO (Hypervisor): do the same thing for constraint_core[i] */ + xbt_assert(m_core == 1, "FIXME: add power scaling code also for constraint_core[i]"); + m_powerScale = value; - lmm_update_constraint_bound(surf_cpu_model->p_maxminSystem, p_constraint, + lmm_update_constraint_bound(surf_cpu_model_pm->p_maxminSystem, p_constraint, m_core * m_powerScale * m_powerPeak); #ifdef HAVE_TRACING @@ -255,16 +255,19 @@ void CpuCas01Lmm::updateState(tmgr_trace_event_t event_type, double value, doubl m_powerPeak); #endif while ((var = lmm_get_var_from_cnst - (surf_cpu_model->p_maxminSystem, p_constraint, &elem))) { + (surf_cpu_model_pm->p_maxminSystem, p_constraint, &elem))) { CpuCas01ActionLmmPtr action = static_cast(static_cast(lmm_variable_id(var))); - lmm_update_variable_bound(surf_cpu_model->p_maxminSystem, + lmm_update_variable_bound(surf_cpu_model_pm->p_maxminSystem, action->p_variable, m_powerScale * m_powerPeak); } if (tmgr_trace_event_free(event_type)) p_powerEvent = NULL; } else if (event_type == p_stateEvent) { + /* TODO (Hypervisor): do the same thing for constraint_core[i] */ + xbt_assert(m_core == 1, "FIXME: add state change code also for constraint_core[i]"); + if (value > 0) { if(p_stateCurrent == SURF_RESOURCE_OFF) xbt_dynar_push_as(host_that_restart, char*, (char *)m_name); @@ -274,7 +277,7 @@ void CpuCas01Lmm::updateState(tmgr_trace_event_t event_type, double value, doubl p_stateCurrent = SURF_RESOURCE_OFF; - while ((var = lmm_get_var_from_cnst(surf_cpu_model->p_maxminSystem, cnst, &elem))) { + while ((var = lmm_get_var_from_cnst(surf_cpu_model_pm->p_maxminSystem, cnst, &elem))) { ActionLmmPtr action = static_cast(lmm_variable_id(var)); if (action->getState() == SURF_ACTION_RUNNING || @@ -299,21 +302,21 @@ ActionPtr CpuCas01Lmm::execute(double size) { XBT_IN("(%s,%g)", m_name, size); - CpuCas01ActionLmmPtr action = new CpuCas01ActionLmm(surf_cpu_model, size, p_stateCurrent != SURF_RESOURCE_ON); + CpuCas01ActionLmmPtr action = new CpuCas01ActionLmm(surf_cpu_model_pm, size, p_stateCurrent != SURF_RESOURCE_ON); action->m_suspended = 0; /* Should be useless because of the calloc but it seems to help valgrind... */ action->p_variable = - lmm_variable_new(surf_cpu_model->p_maxminSystem, static_cast(action), + lmm_variable_new(surf_cpu_model_pm->p_maxminSystem, static_cast(action), action->m_priority, m_powerScale * m_powerPeak, 1); - if (surf_cpu_model->p_updateMechanism == UM_LAZY) { + if (surf_cpu_model_pm->p_updateMechanism == UM_LAZY) { action->m_indexHeap = -1; action->m_lastUpdate = surf_get_clock(); action->m_lastValue = 0.0; } - lmm_expand(surf_cpu_model->p_maxminSystem, p_constraint, + lmm_expand(surf_cpu_model_pm->p_maxminSystem, p_constraint, action->p_variable, 1.0); XBT_OUT(); return action; @@ -334,18 +337,18 @@ ActionPtr CpuCas01Lmm::sleep(double duration) /* Move to the *end* of the corresponding action set. This convention is used to speed up update_resource_state */ xbt_swag_remove(static_cast(action), action->p_stateSet); - action->p_stateSet = cpu_running_action_set_that_does_not_need_being_checked; + action->p_stateSet = static_cast(p_model)->p_cpuRunningActionSetThatDoesNotNeedBeingChecked; xbt_swag_insert(static_cast(action), action->p_stateSet); } - lmm_update_variable_weight(surf_cpu_model->p_maxminSystem, + lmm_update_variable_weight(surf_cpu_model_pm->p_maxminSystem, action->p_variable, 0.0); - if (surf_cpu_model->p_updateMechanism == UM_LAZY) { // remove action from the heap - action->heapRemove(surf_cpu_model->p_actionHeap); + if (surf_cpu_model_pm->p_updateMechanism == UM_LAZY) { // remove action from the heap + action->heapRemove(surf_cpu_model_pm->p_actionHeap); // this is necessary for a variable with weight 0 since such // variables are ignored in lmm and we need to set its max_duration // correctly at the next call to share_resources - xbt_swag_insert_at_head(static_cast(action), surf_cpu_model->p_modifiedSet); + xbt_swag_insert_at_head(static_cast(action), surf_cpu_model_pm->p_modifiedSet); } XBT_OUT(); @@ -459,7 +462,7 @@ double CpuCas01Lmm::getCurrentPowerPeak() double CpuCas01Lmm::getPowerPeakAt(int pstate_index) { xbt_dynar_t plist = p_powerPeakList; - xbt_assert((pstate_index <= xbt_dynar_length(plist)), "Invalid parameters (pstate index out of bounds)"); + xbt_assert((pstate_index <= (int)xbt_dynar_length(plist)), "Invalid parameters (pstate index out of bounds)"); return xbt_dynar_get_as(plist, pstate_index, double); } @@ -472,7 +475,7 @@ int CpuCas01Lmm::getNbPstates() void CpuCas01Lmm::setPowerPeakAt(int pstate_index) { xbt_dynar_t plist = p_powerPeakList; - xbt_assert((pstate_index <= xbt_dynar_length(plist)), "Invalid parameters (pstate index out of bounds)"); + xbt_assert((pstate_index <= (int)xbt_dynar_length(plist)), "Invalid parameters (pstate index out of bounds)"); double new_power_peak = xbt_dynar_get_as(plist, pstate_index, double); m_pstate = pstate_index;