/* Update global variables */
xbt_lib_set(host_lib,name,SIMIX_HOST_LEVEL,smx_host);
- return xbt_lib_get_or_null(host_lib, name, SIMIX_HOST_LEVEL);
+ return xbt_lib_get_elm_or_null(host_lib, name);//, SIMIX_HOST_LEVEL);
}
void SIMIX_pre_host_on(smx_simcall_t simcall, smx_host_t h)
return m_core;
}
+CpuLmm::CpuLmm(CpuModelPtr model, const char* name, xbt_dict_t properties, int core, double powerPeak, double powerScale)
+: ResourceLmm(), Cpu(model, name, properties, core, powerPeak, 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 = xbt_new(lmm_constraint_t, core);
+
+ int i;
+ for (i = 0; i < core; i++) {
+ /* just for a unique id, never used as a string. */
+ void *cnst_id = bprintf("%s:%i", name, i);
+ p_constraintCore[i] = lmm_constraint_new(p_model->p_maxminSystem, cnst_id, m_powerScale * m_powerPeak);
+ }
+}
+
+CpuLmm::~CpuLmm(){
+ if (p_constraintCore){
+ for (int i = 0; i < m_core; i++) {
+ void *cnst_id = p_constraintCore[i]->id;
+ //FIXME:lmm_constraint_free(p_model->p_maxminSystem, p_constraintCore[i]);
+ xbt_free(cnst_id);
+ }
+ xbt_free(p_constraintCore);
+ }
+}
+
/**********
* Action *
**********/
#include "surf.hpp"
+#include "maxmin_private.h"
#ifndef SURF_MODEL_CPU_H_
#define SURF_MODEL_CPU_H_
class Cpu : virtual public Resource {
public:
Cpu(){};
- Cpu(CpuModelPtr model, const char* name, xbt_dict_t properties) : Resource(model, name, properties) {};
+ Cpu(CpuModelPtr model, const char* name, xbt_dict_t properties, int core, double powerPeak, double powerScale)
+ : Resource(model, name, properties), m_core(core), m_powerPeak(powerPeak), m_powerScale(powerScale)
+ {};
virtual ActionPtr execute(double size)=0;
virtual ActionPtr sleep(double duration)=0;
virtual int getCore();
virtual double getConsumedEnergy()=0;
void addTraces(void);
+ int m_core;
double m_powerPeak; /*< CPU power peak */
double m_powerScale; /*< Percentage of CPU disponible */
- int m_core;
protected:
//virtual boost::shared_ptr<Action> execute(double size) = 0;
class CpuLmm : public ResourceLmm, public Cpu {
public:
- CpuLmm(){};
- CpuLmm(CpuModelPtr model, const char* name, xbt_dict_t properties) : ResourceLmm(), Cpu(model, name, properties) {};
+ CpuLmm() : p_constraintCore(NULL) {};
+ CpuLmm(CpuModelPtr model, const char* name, xbt_dict_t properties, int core, double powerPeak, double powerScale);
+ ~CpuLmm();
/* Note (hypervisor): */
lmm_constraint_t *p_constraintCore;
};
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,
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<ResourcePtr>(cpu));
- return (CpuCas01LmmPtr) xbt_lib_get_elm_or_null(host_lib, name);
+ return cpu;
}
double CpuCas01Model::shareResourcesFull(double /*now*/)
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) :
- Resource(model, name, properties), CpuLmm(model, name, properties) {
+ xbt_dict_t properties)
+: Resource(model, name, properties)
+, CpuLmm(model, name, properties, core, xbt_dynar_get_as(powerPeak, pstate, double), powerScale) {
p_powerEvent = NULL;
- m_powerPeak = xbt_dynar_get_as(powerPeak, pstate, double);
p_powerPeakList = powerPeak;
m_pstate = pstate;
XBT_DEBUG("CPU create: peak=%f, pstate=%d", m_powerPeak, m_pstate);
- m_powerScale = powerScale;
m_core = core;
p_stateCurrent = stateInitial;
if (powerTrace)
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_pm->p_maxminSystem, p_constraint,
m_core * m_powerScale *
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);
void (CpuCas01Model::*updateActionsState)(double now, double delta);
void parseInit(sg_platf_host_cbarg_t host);
- CpuCas01LmmPtr createResource(const char *name, xbt_dynar_t power_peak, int pstate,
+ CpuPtr 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,
public:
CpuCas01ActionLmm() {};
CpuCas01ActionLmm(ModelPtr model, double cost, bool failed): Action(model, cost, failed), CpuActionLmm(model, cost, failed) {};
+ ~CpuCas01ActionLmm() {};
void updateEnergy();
-
};
"Logging specific to the SURF CPU TRACE INTEGRATION module");
}
-static xbt_swag_t cpu_ti_running_action_set_that_does_not_need_being_checked;
-static xbt_swag_t cpu_ti_modified_cpu;
-static xbt_heap_t cpu_ti_action_heap;
-
static void cpu_ti_action_update_index_heap(void *action, int i);
/*********
void surf_cpu_model_init_ti()
{
xbt_assert(!surf_cpu_model_pm,"CPU model already initialized. This should not happen.");
+ xbt_assert(!surf_cpu_model_vm,"CPU model already initialized. This should not happen.");
+
surf_cpu_model_pm = new CpuTiModel();
+ surf_cpu_model_vm = new CpuTiModel();
+
cpu_ti_define_callbacks();
- ModelPtr model = static_cast<ModelPtr>(surf_cpu_model_pm);
- xbt_dynar_push(model_list, &model);
+ ModelPtr model_pm = static_cast<ModelPtr>(surf_cpu_model_pm);
+ ModelPtr model_vm = static_cast<ModelPtr>(surf_cpu_model_vm);
+ xbt_dynar_push(model_list, &model_pm);
+ xbt_dynar_push(model_list, &model_vm);
}
CpuTiModel::CpuTiModel() : CpuModel("cpu_ti")
{
- xbt_assert(!surf_cpu_model_pm,"CPU model already initialized. This should not happen.");
ActionPtr action = NULL;
- CpuTi cpu;
+ CpuTiPtr cpu;
- cpu_ti_running_action_set_that_does_not_need_being_checked =
+ p_runningActionSetThatDoesNotNeedBeingChecked =
xbt_swag_new(xbt_swag_offset(*action, p_stateHookup));
- cpu_ti_modified_cpu =
- xbt_swag_new(xbt_swag_offset(cpu, p_modifiedCpuHookup));
+ p_modifiedCpu =
+ xbt_swag_new(xbt_swag_offset(*cpu, p_modifiedCpuHookup));
- cpu_ti_action_heap = xbt_heap_new(8, NULL);
- xbt_heap_set_update_callback(cpu_ti_action_heap,
+ p_tiActionHeap = xbt_heap_new(8, NULL);
+ xbt_heap_set_update_callback(p_tiActionHeap,
cpu_ti_action_update_index_heap);
}
surf_cpu_model_pm = NULL;
- xbt_swag_free
- (cpu_ti_running_action_set_that_does_not_need_being_checked);
- xbt_swag_free(cpu_ti_modified_cpu);
- cpu_ti_running_action_set_that_does_not_need_being_checked = NULL;
- xbt_heap_free(cpu_ti_action_heap);
+ xbt_swag_free(p_runningActionSetThatDoesNotNeedBeingChecked);
+ xbt_swag_free(p_modifiedCpu);
+ xbt_heap_free(p_tiActionHeap);
}
void CpuTiModel::parseInit(sg_platf_host_cbarg_t host)
CpuTiPtr cpu = new CpuTi(this, name, powerPeak, pstate, powerScale, powerTrace,
core, stateInitial, stateTrace, cpuProperties);
xbt_lib_set(host_lib, name, SURF_CPU_LEVEL, static_cast<ResourcePtr>(cpu));
- return (CpuTiPtr) xbt_lib_get_elm_or_null(host_lib, name);
+ return cpu;
}
CpuTiActionPtr CpuTiModel::createAction(double /*cost*/, bool /*failed*/)
double min_action_duration = -1;
/* iterates over modified cpus to update share resources */
- xbt_swag_foreach_safe(_cpu, _cpu_next, cpu_ti_modified_cpu) {
+ xbt_swag_foreach_safe(_cpu, _cpu_next, p_modifiedCpu) {
static_cast<CpuTiPtr>(_cpu)->updateActionFinishDate(now);
}
/* get the min next event if heap not empty */
- if (xbt_heap_size(cpu_ti_action_heap) > 0)
- min_action_duration = xbt_heap_maxkey(cpu_ti_action_heap) - now;
+ if (xbt_heap_size(p_tiActionHeap) > 0)
+ min_action_duration = xbt_heap_maxkey(p_tiActionHeap) - now;
XBT_DEBUG("Share resources, min next event date: %f", min_action_duration);
void CpuTiModel::updateActionsState(double now, double /*delta*/)
{
- while ((xbt_heap_size(cpu_ti_action_heap) > 0)
- && (xbt_heap_maxkey(cpu_ti_action_heap) <= now)) {
- CpuTiActionPtr action = (CpuTiActionPtr) xbt_heap_pop(cpu_ti_action_heap);
+ while ((xbt_heap_size(p_tiActionHeap) > 0)
+ && (xbt_heap_maxkey(p_tiActionHeap) <= now)) {
+ CpuTiActionPtr action = (CpuTiActionPtr) xbt_heap_pop(p_tiActionHeap);
XBT_DEBUG("Action %p: finish", action);
action->m_finish = surf_get_clock();
/* set the remains to 0 due to precision problems when updating the remaining amount */
CpuTi::CpuTi(CpuTiModelPtr 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) :
- Resource(model, name, properties), Cpu(model, name, properties) {
+ xbt_dict_t properties)
+: Resource(model, name, properties)
+, Cpu(model, name, properties, core, 0, powerScale) {
p_powerEvent = NULL;
p_stateCurrent = stateInitial;
m_powerScale = powerScale;
value, date);
/* update remaining of actions and put in modified cpu swag */
updateRemainingAmount(date);
- xbt_swag_insert(this, cpu_ti_modified_cpu);
+ xbt_swag_insert(this, reinterpret_cast<CpuTiModelPtr>(p_model)->p_modifiedCpu);
power_trace = p_availTrace->p_powerTrace;
xbt_dynar_get_cpy(power_trace->s_list.event_list,
action->setState(SURF_ACTION_FAILED);
if (action->m_indexHeap >= 0) {
CpuTiActionPtr heap_act = (CpuTiActionPtr)
- xbt_heap_remove(cpu_ti_action_heap, action->m_indexHeap);
+ xbt_heap_remove(reinterpret_cast<CpuTiModelPtr>(p_model)->p_tiActionHeap, action->m_indexHeap);
if (heap_act != action)
DIE_IMPOSSIBLE;
}
XBT_DEBUG("action(%p) index %d", action, action->m_indexHeap);
if (action->m_indexHeap >= 0) {
CpuTiActionPtr heap_act = (CpuTiActionPtr)
- xbt_heap_remove(cpu_ti_action_heap, action->m_indexHeap);
+ xbt_heap_remove(reinterpret_cast<CpuTiModelPtr>(p_model)->p_tiActionHeap, action->m_indexHeap);
if (heap_act != action)
DIE_IMPOSSIBLE;
}
if (min_finish != NO_MAX_DURATION)
- xbt_heap_push(cpu_ti_action_heap, action, min_finish);
+ xbt_heap_push(reinterpret_cast<CpuTiModelPtr>(p_model)->p_tiActionHeap, action, min_finish);
XBT_DEBUG
("Update finish time: Cpu(%s) Action: %p, Start Time: %f Finish Time: %f Max duration %f",
action->m_maxDuration);
}
/* remove from modified cpu */
- xbt_swag_remove(this, cpu_ti_modified_cpu);
+ xbt_swag_remove(this, reinterpret_cast<CpuTiModelPtr>(p_model)->p_modifiedCpu);
}
bool CpuTi::isUsed()
action->p_cpu = this;
action->m_indexHeap = -1;
- xbt_swag_insert(this, cpu_ti_modified_cpu);
+ xbt_swag_insert(this, reinterpret_cast<CpuTiModelPtr>(p_model)->p_modifiedCpu);
xbt_swag_insert(action, p_actionSet);
/* Move to the *end* of the corresponding action set. This convention
is used to speed up update_resource_state */
xbt_swag_remove(static_cast<ActionPtr>(action), action->p_stateSet);
- action->p_stateSet = cpu_ti_running_action_set_that_does_not_need_being_checked;
+ action->p_stateSet = reinterpret_cast<CpuTiModelPtr>(p_model)->p_runningActionSetThatDoesNotNeedBeingChecked;
xbt_swag_insert(static_cast<ActionPtr>(action), action->p_stateSet);
}
XBT_OUT();
void CpuTiAction::setState(e_surf_action_state_t state)
{
Action::setState(state);
- xbt_swag_insert(p_cpu, cpu_ti_modified_cpu);
+ xbt_swag_insert(p_cpu, reinterpret_cast<CpuTiModelPtr>(p_model)->p_modifiedCpu);
}
int CpuTiAction::unref()
/* remove from action_set */
xbt_swag_remove(this, p_cpu->p_actionSet);
/* remove from heap */
- xbt_heap_remove(cpu_ti_action_heap, this->m_indexHeap);
- xbt_swag_insert(p_cpu, cpu_ti_modified_cpu);
+ xbt_heap_remove(reinterpret_cast<CpuTiModelPtr>(p_model)->p_tiActionHeap, this->m_indexHeap);
+ xbt_swag_insert(p_cpu, reinterpret_cast<CpuTiModelPtr>(p_model)->p_modifiedCpu);
delete this;
return 1;
}
void CpuTiAction::cancel()
{
this->setState(SURF_ACTION_FAILED);
- xbt_heap_remove(cpu_ti_action_heap, this->m_indexHeap);
- xbt_swag_insert(p_cpu, cpu_ti_modified_cpu);
+ xbt_heap_remove(p_model->p_actionHeap, this->m_indexHeap);
+ xbt_swag_insert(p_cpu, reinterpret_cast<CpuTiModelPtr>(p_model)->p_modifiedCpu);
return;
}
XBT_IN("(%p)", this);
if (m_suspended != 2) {
m_suspended = 1;
- xbt_heap_remove(cpu_ti_action_heap, m_indexHeap);
- xbt_swag_insert(p_cpu, cpu_ti_modified_cpu);
+ xbt_heap_remove(p_model->p_actionHeap, m_indexHeap);
+ xbt_swag_insert(p_cpu, reinterpret_cast<CpuTiModelPtr>(p_model)->p_modifiedCpu);
}
XBT_OUT();
}
XBT_IN("(%p)", this);
if (m_suspended != 2) {
m_suspended = 0;
- xbt_swag_insert(p_cpu, cpu_ti_modified_cpu);
+ xbt_swag_insert(p_cpu, reinterpret_cast<CpuTiModelPtr>(p_model)->p_modifiedCpu);
}
XBT_OUT();
}
/* add in action heap */
if (m_indexHeap >= 0) {
CpuTiActionPtr heap_act = (CpuTiActionPtr)
- xbt_heap_remove(cpu_ti_action_heap, m_indexHeap);
+ xbt_heap_remove(p_model->p_actionHeap, m_indexHeap);
if (heap_act != this)
DIE_IMPOSSIBLE;
}
- xbt_heap_push(cpu_ti_action_heap, this, min_finish);
+ xbt_heap_push(p_model->p_actionHeap, this, min_finish);
XBT_OUT();
}
{
XBT_IN("(%p,%g)", this, priority);
m_priority = priority;
- xbt_swag_insert(p_cpu, cpu_ti_modified_cpu);
+ xbt_swag_insert(p_cpu, reinterpret_cast<CpuTiModelPtr>(p_model)->p_modifiedCpu);
XBT_OUT();
}
void updateActionsState(double now, double delta);
void addTraces();
+ xbt_swag_t p_runningActionSetThatDoesNotNeedBeingChecked;
+ xbt_swag_t p_modifiedCpu;
+ xbt_heap_t p_tiActionHeap;
+
protected:
void NotifyResourceTurnedOn(ResourcePtr){};
void NotifyResourceTurnedOff(ResourcePtr){};
char *dst_name = dst->p_name;
XBT_IN("(%s,%s,%g,%g)", src_name, dst_name, size, rate);
- NetworkConstantActionLmmPtr action = new NetworkConstantActionLmm(this, sg_latency_factor);
+ NetworkConstantActionLmmPtr action = new NetworkConstantActionLmm(this, size, sg_latency_factor);
XBT_OUT();
return action;
**********/
class NetworkConstantActionLmm : public NetworkCm02ActionLmm {
public:
- NetworkConstantActionLmm(NetworkConstantModelPtr model, double latency):
- Action(model, 0, false), NetworkCm02ActionLmm(model, 0, false), m_latInit(latency) {
+ NetworkConstantActionLmm(NetworkConstantModelPtr model, double size, double latency):
+ Action(model, size, false), NetworkCm02ActionLmm(model, 0, false), m_latInit(latency) {
m_latency = latency;
if (m_latency <= 0.0) {
p_stateSet = p_model->p_doneActionSet;
m_maxDuration(NO_MAX_DURATION),
m_cost(cost),
p_model(model),
- m_refcount(1)
+ m_refcount(1),
+ p_data(NULL)
{
#ifdef HAVE_TRACING
p_category = NULL;
class ResourceLmm: virtual public Resource {
public:
- ResourceLmm() { p_power.event = NULL; };
+ ResourceLmm() : p_constraint(NULL) {
+ p_power.event = NULL;
+ };
ResourceLmm(surf_model_t model, const char *name, xbt_dict_t props,
lmm_system_t system,
double constraint_value,
tmgr_trace_t state_trace,
double metric_peak,
tmgr_trace_t metric_trace);
- ~ResourceLmm() {};
+ ~ResourceLmm() {
+ };
lmm_constraint_t p_constraint;
tmgr_trace_event_t p_stateEvent;
s_surf_metric_t p_power;
int m_refcount;
#ifdef HAVE_TRACING
#endif
- e_UM_t p_updateMechanism;
+ //FIXME:removee_UM_t p_updateMechanism;
private:
int resourceUsed(void *resource_id);
*/
#include "vm_workstation.hpp"
#include "cpu_cas01.hpp"
-#include "maxmin_private.h"
extern "C" {
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_vm_workstation, surf,
{
WorkstationVM2013LmmPtr ws = new WorkstationVM2013Lmm(this, name, NULL, static_cast<surf_resource_t>(ind_phys_workstation));
- xbt_lib_set(host_lib, name, SURF_WKS_LEVEL, ws);
+ xbt_lib_set(host_lib, name, SURF_WKS_LEVEL, static_cast<ResourcePtr>(ws));
/* TODO:
* - check how network requests are scheduled between distinct processes competing for the same card.
/************
* Resource *
************/
-
WorkstationVM2013Lmm::WorkstationVM2013Lmm(WorkstationVMModelPtr model, const char* name, xbt_dict_t props,
surf_resource_t ind_phys_workstation)
: Resource(model, name, props),
/* We can assume one core and cas01 cpu for the first step.
* Do xbt_lib_set(host_lib, name, SURF_CPU_LEVEL, cpu) if you get the resource. */
- static_cast<CpuCas01ModelPtr>(surf_cpu_model_vm)->createResource(name, // name
+ p_cpu = static_cast<CpuCas01ModelPtr>(surf_cpu_model_vm)->createResource(name, // name
sub_cpu->p_powerPeakList, // host->power_peak,
sub_cpu->m_pstate,
1, // host->power_scale,
int ret = p_action->unref();
xbt_assert(ret == 1, "Bug: some resource still remains");
- /* Free the cpu resource of the VM. If using power_trace, we will have to
- * free other objects than lmm_constraint. */
- lmm_constraint_free(cpu->p_model->p_maxminSystem, cpu->p_constraint);
- for (int i = 0; i < cpu->m_core; i++) {
- void *cnst_id = cpu->p_constraintCore[i]->id;
- lmm_constraint_free(cpu->p_model->p_maxminSystem, cpu->p_constraintCore[i]);
- xbt_free(cnst_id);
- }
-
- xbt_free(cpu->p_constraintCore);
-
+ /* Free the cpu resource of the VM. If using power_trace, we will have to */
delete cpu;
/* Free the network resource of the VM. */
}
CpuL07::CpuL07(CpuL07ModelPtr model, const char* name, xbt_dict_t props)
- : Resource(model, name, props), CpuLmm(model, name, props) {
+ : Resource(model, name, props), CpuLmm() {
}