+/* Copyright (c) 2013-2014. The SimGrid Team.
+ * All rights reserved. */
+
+/* This program is free software; you can redistribute it and/or modify it
+ * under the terms of the license (GNU LGPL) which comes with this package. */
+
#include "cpu_ti.hpp"
#include "trace_mgr_private.h"
#include "xbt/heap.h"
/**
* \brief Auxiliary function to calculate the integral between a and b.
- * It simply calculates the integral at point a and b and returns the difference
+ * It simply calculates the integral at point a and b and returns the difference
* between them.
* \param trace Trace structure
* \param a Initial point
("a %f ind %d integral %f ind + 1 %f ind %f time +1 %f time %f",
a, ind, integral, p_integral[ind + 1], p_integral[ind],
p_timePoints[ind + 1], p_timePoints[ind]);
- double_update(&a_aux, p_timePoints[ind]);
+ double_update(&a_aux, p_timePoints[ind], sg_maxmin_precision*sg_surf_precision);
if (a_aux > 0)
integral +=
((p_integral[ind + 1] -
* It returns the date when the requested amount of flops is available
* \param trace Trace structure
* \param a Initial point
- * \param amount Amount of flops
+ * \param amount Amount of flops
* \return The date when amount is available.
*/
double CpuTiTrace::solveSimple(double a, double amount)
if (!power_trace) {
m_type = TRACE_FIXED;
m_value = value;
- XBT_DEBUG("No availability trace. Constant value = %lf", value);
+ XBT_DEBUG("No availability trace. Constant value = %f", value);
return;
}
m_lastTime = total_time;
m_total = p_trace->integrateSimple(0, total_time);
- XBT_DEBUG("Total integral %lf, last_time %lf ",
+ XBT_DEBUG("Total integral %f, last_time %f ",
m_total, m_lastTime);
}
/**
* \brief Binary search in array.
- * It returns the first point of the interval in which "a" is.
+ * It returns the first point of the interval in which "a" is.
* \param array Array
* \param a Value to search
* \param low Low bound to search in array
* CallBacks *
*************/
-static void parse_cpu_ti_init(sg_platf_host_cbarg_t host){
- ((CpuTiModelPtr)surf_cpu_model_pm)->parseInit(host);
-}
-
-static void add_traces_cpu_ti(){
- surf_cpu_model_pm->addTraces();
-}
-
static void cpu_ti_define_callbacks()
{
- sg_platf_host_add_cb(parse_cpu_ti_init);
- sg_platf_postparse_add_cb(add_traces_cpu_ti);
+ sg_platf_host_add_cb(parse_cpu_init);
+ sg_platf_postparse_add_cb(add_traces_cpu);
}
/*********
xbt_heap_free(p_tiActionHeap);
}
-void CpuTiModel::parseInit(sg_platf_host_cbarg_t host)
-{
- createResource(host->id,
- host->power_peak,
- host->pstate,
- host->power_scale,
- host->power_trace,
- host->core_amount,
- host->initial_state,
- host->state_trace,
- host->properties);
-}
-
-CpuTiPtr CpuTiModel::createResource(const char *name,
+CpuPtr CpuTiModel::createResource(const char *name,
xbt_dynar_t powerPeak,
int pstate,
double powerScale,
return cpu;
}
-CpuTiActionPtr CpuTiModel::createAction(double /*cost*/, bool /*failed*/)
-{
- return NULL;//new CpuTiAction(this, cost, failed);
-}
-
double CpuTiModel::shareResources(double now)
{
void *_cpu, *_cpu_next;
xbt_dict_foreach(trace_connect_list_power, cursor, trace_name, elm) {
tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name);
- CpuTiPtr cpu = dynamic_cast<CpuTiPtr>(static_cast<ResourcePtr>(surf_cpu_resource_priv(surf_cpu_resource_by_name(elm))));
+ CpuTiPtr cpu = static_cast<CpuTiPtr>(surf_cpu_resource_priv(surf_cpu_resource_by_name(elm)));
xbt_assert(cpu, "Host %s undefined", elm);
xbt_assert(trace, "Trace %s undefined", trace_name);
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(core, 0, powerScale) {
+: Cpu(model, name, properties, core, 0, powerScale)
+{
p_powerEvent = NULL;
- m_stateCurrent = stateInitial;
+ setState(stateInitial);
m_powerScale = powerScale;
m_core = core;
- tmgr_trace_t empty_trace;
- s_tmgr_event_t val;
+ tmgr_trace_t empty_trace;
+ s_tmgr_event_t val;
xbt_assert(core==1,"Multi-core not handled with this model yet");
- XBT_DEBUG("power scale %lf", powerScale);
+ XBT_DEBUG("power scale %f", powerScale);
p_availTrace = new CpuTiTgmr(powerTrace, powerScale);
CpuTiActionPtr action = NULL;
if (stateTrace)
p_stateEvent = tmgr_history_add_trace(history, stateTrace, 0.0, 0, static_cast<ResourcePtr>(this));
if (powerTrace && xbt_dynar_length(powerTrace->s_list.event_list) > 1) {
- // add a fake trace event if periodicity == 0
+ // add a fake trace event if periodicity == 0
xbt_dynar_get_cpy(powerTrace->s_list.event_list,
xbt_dynar_length(powerTrace->s_list.event_list) - 1, &val);
if (val.delta == 0) {
CpuTiTgmrPtr trace;
s_tmgr_event_t val;
- XBT_DEBUG("Finish trace date: %f value %lf date %f", surf_get_clock(),
+ XBT_DEBUG("Finish trace date: %f value %f date %f", surf_get_clock(),
value, date);
/* update remaining of actions and put in modified cpu swag */
updateRemainingAmount(date);
} else if (event_type == p_stateEvent) {
if (value > 0) {
- if(m_stateCurrent == SURF_RESOURCE_OFF)
+ if(getState() == SURF_RESOURCE_OFF)
xbt_dynar_push_as(host_that_restart, char*, (char *)getName());
- m_stateCurrent = SURF_RESOURCE_ON;
+ setState(SURF_RESOURCE_ON);
} else {
- m_stateCurrent = SURF_RESOURCE_OFF;
+ setState(SURF_RESOURCE_OFF);
/* put all action running on cpu to failed */
xbt_swag_foreach(_action, p_actionSet) {
CpuActionPtr CpuTi::execute(double size)
{
XBT_IN("(%s,%g)", getName(), size);
- CpuTiActionPtr action = new CpuTiAction(static_cast<CpuTiModelPtr>(getModel()), size, m_stateCurrent != SURF_RESOURCE_ON, this);
+ CpuTiActionPtr action = new CpuTiAction(static_cast<CpuTiModelPtr>(getModel()), size, getState() != SURF_RESOURCE_ON, this);
xbt_swag_insert(action, p_actionSet);
CpuActionPtr CpuTi::sleep(double duration)
{
if (duration > 0)
- duration = MAX(duration, MAXMIN_PRECISION);
+ duration = MAX(duration, sg_surf_precision);
XBT_IN("(%s,%g)", getName(), duration);
- CpuTiActionPtr action = new CpuTiAction(static_cast<CpuTiModelPtr>(getModel()), 1.0, m_stateCurrent != SURF_RESOURCE_ON, this);
+ CpuTiActionPtr action = new CpuTiAction(static_cast<CpuTiModelPtr>(getModel()), 1.0, getState() != SURF_RESOURCE_ON, this);
action->m_maxDuration = duration;
action->m_suspended = 2;
CpuTiAction::CpuTiAction(CpuTiModelPtr model_, double cost, bool failed,
CpuTiPtr cpu)
- : Action(model_, cost, failed)
- , CpuAction(model_, cost, failed)
+ : CpuAction(model_, cost, failed)
{
p_cpuListHookup.next = 0;
p_cpuListHookup.prev = 0;
void CpuTiAction::setState(e_surf_action_state_t state)
{
- Action::setState(state);
+ CpuAction::setState(state);
xbt_swag_insert(p_cpu, reinterpret_cast<CpuTiModelPtr>(getModel())->p_modifiedCpu);
}