host_parameters.core_amount = 1;
host_parameters.speed_scale = 1;
host_parameters.speed_trace = NULL;
- host_parameters.initial_state = SURF_RESOURCE_ON;
+ host_parameters.initiallyOn = 1;
host_parameters.state_trace = NULL;
host_parameters.coord = NULL;
host_parameters.properties = NULL;
//Latency from 0ms to 100ms
link_parameters.latency = RngStream_RandU01(rng_stream) / 10.0;
link_parameters.latency_trace = NULL;
- link_parameters.state = SURF_RESOURCE_ON;
+ link_parameters.initiallyOn = 1;
link_parameters.state_trace = NULL;
link_parameters.policy = SURF_LINK_SHARED;
link_parameters.properties = NULL;
> [ 6.000000] (6:p31@vm_host3) This worker is done.
> [ 6.000000] (7:p32@vm_host3) This worker is done.
> [ 10.000000] (0:@) Total simulation time: 10.00; All hosts must have the exact same energy consumption.
+> [ 10.000000] (0:@) Total energy of host MyHost1: 1600.000000 Joules
> [ 10.000000] (0:@) Total energy of host MyHost2: 1600.000000 Joules
-> [ 10.000000] (0:@) Total energy of host vm_host1: 1600.000000 Joules
-> [ 10.000000] (0:@) Total energy of host vm_host3: 1600.000000 Joules
+> [ 10.000000] (0:@) Total energy of host MyHost3: 1600.000000 Joules
host_parameters.core_amount = 1;
host_parameters.speed_scale = 1;
host_parameters.speed_trace = NULL;
- host_parameters.initial_state = SURF_RESOURCE_ON;
+ host_parameters.initiallyOn = 1;
host_parameters.state_trace = NULL;
host_parameters.coord = NULL;
host_parameters.properties = NULL;
link_parameters.bandwidth_trace = NULL;
link_parameters.latency = 0.01;
link_parameters.latency_trace = NULL;
- link_parameters.state = SURF_RESOURCE_ON;
+ link_parameters.initiallyOn = 1;
link_parameters.state_trace = NULL;
link_parameters.policy = SURF_LINK_SHARED;
link_parameters.properties = NULL;
tmgr_trace_generator_avail_unavail(bprintf("state_link_%ld", edge->id),
avail_generator,
unavail_generator,
- SURF_RESOURCE_ON);
+ 1/*ON*/);
platf_graph_link_label(edge, &link_parameters);
host_parameters.core_amount = 1;
host_parameters.speed_scale = 1;
host_parameters.speed_trace = NULL;
- host_parameters.initial_state = SURF_RESOURCE_ON;
+ host_parameters.initiallyOn = 1;
host_parameters.state_trace = NULL;
host_parameters.coord = NULL;
host_parameters.properties = NULL;
link_parameters.bandwidth_trace = NULL;
link_parameters.latency = 0.01;
link_parameters.latency_trace = NULL;
- link_parameters.state = SURF_RESOURCE_ON;
+ link_parameters.initiallyOn = 1;
link_parameters.state_trace = NULL;
link_parameters.policy = SURF_LINK_SHARED;
link_parameters.properties = NULL;
simgrid::xbt::string const& getName() const { return name_; }
void on();
void off();
- e_surf_resource_state_t getState();
+ bool isOn();
+ bool isOff();
xbt_dict_t getProperties();
xbt_swag_t getProcessList();
double getCurrentPowerPeak();
typedef void *sg_routing_link_t; /* FIXME:The actual type is model-dependent so use void* instead*/
-/** @ingroup SURF_interface
-* @brief Defines whether a given resource is working or not */
-typedef enum {
- SURF_RESOURCE_ON = 1, /**< Up & ready */
- SURF_RESOURCE_OFF = 0 /**< Down & broken */
-} e_surf_resource_state_t;
-
typedef enum {
SURF_LINK_FULLDUPLEX = 2,
SURF_LINK_SHARED = 1,
int core_amount;
double speed_scale;
tmgr_trace_t speed_trace;
- e_surf_resource_state_t initial_state;
+ int initiallyOn;
tmgr_trace_t state_trace;
const char* coord;
xbt_dict_t properties;
} s_sg_platf_host_cbarg_t, *sg_platf_host_cbarg_t;
#define SG_PLATF_HOST_INITIALIZER { \
- NULL, 0, 1, 1, 1., NULL, SURF_RESOURCE_ON, NULL, \
+ NULL, 0, 1, 1, 1., NULL, 1/*ON*/, NULL, \
NULL, NULL \
}
tmgr_trace_t bandwidth_trace;
double latency;
tmgr_trace_t latency_trace;
- e_surf_resource_state_t state;
+ int initiallyOn;
tmgr_trace_t state_trace;
e_surf_link_sharing_policy_t policy;
xbt_dict_t properties;
} s_sg_platf_link_cbarg_t, *sg_platf_link_cbarg_t;
#define SG_PLATF_LINK_INITIALIZER {\
- NULL, 0., NULL, 0., NULL, SURF_RESOURCE_ON, \
+ NULL, 0., NULL, 0., NULL, 1/*ON*/, \
NULL, SURF_LINK_SHARED, NULL \
}
// =========== user-level functions ===============
XBT_PUBLIC(double) sg_host_get_available_speed(sg_host_t host);
-XBT_PUBLIC(int) sg_host_get_state(sg_host_t host);
+XBT_PUBLIC(int) sg_host_is_on(sg_host_t host);
XBT_PUBLIC(int) sg_host_get_nb_pstates(sg_host_t host);
XBT_PUBLIC(int) sg_host_get_pstate(sg_host_t host);
probabilist_event_generator_t value_generator);
XBT_PUBLIC(tmgr_trace_t) tmgr_trace_generator_state(const char *id,
probabilist_event_generator_t date_generator,
- e_surf_resource_state_t first_event_value);
+ int first_event_hostIsOn);
XBT_PUBLIC(tmgr_trace_t) tmgr_trace_generator_avail_unavail(const char *id,
probabilist_event_generator_t avail_duration_generator,
probabilist_event_generator_t unavail_duration_generator,
- e_surf_resource_state_t first_event_value);
+ int first_event_hostIsOn);
XBT_PUBLIC(probabilist_event_generator_t) tmgr_event_generator_new_uniform(const char* id,
double min,
link.latency = surf_parse_get_time(lua_tostring(L, -1));
lua_pop(L, 1);
- link.state = SURF_RESOURCE_ON;
+ link.initiallyOn = 1;
lua_pushstring(L, "sharing_policy");
type = lua_gettable(L, -2);
lua_pop(L, 1);
if (state)
- host.initial_state = SURF_RESOURCE_ON;
+ host.initiallyOn = 1;
else
- host.initial_state = SURF_RESOURCE_OFF;
+ host.initiallyOn = 0;
//get trace state
lua_pushstring(L, "state_file");
lua_pushstring(L, "state");
lua_gettable(L, -2);
if (!lua_isnumber(L,-1) || lua_tonumber(L, -1))
- link.state = SURF_RESOURCE_ON;
+ link.initiallyOn = 1;
else
- link.state = SURF_RESOURCE_OFF;
+ link.initiallyOn = 0;
lua_pop(L, 1);
//get policy value
/** @brief Get the state of a surf resource (cpu, host, network, …) */
-XBT_PUBLIC(e_surf_resource_state_t) surf_resource_get_state(surf_cpp_resource_t resource);
+XBT_PUBLIC(int) surf_resource_is_on(surf_cpp_resource_t resource);
+/** @brief Get the state of a surf resource (cpu, host, network, …) */
+XBT_PUBLIC(int) surf_resource_is_off(surf_cpp_resource_t resource);
/** @brief Set the state of a surf resource (cpu, host, network, …) */
-XBT_PUBLIC(void) surf_resource_set_state(surf_cpp_resource_t resource, e_surf_resource_state_t state);
-static inline void surf_host_set_state(surf_host_t host, e_surf_resource_state_t state) {
- surf_resource_set_state((surf_cpp_resource_t)host, state);
+XBT_PUBLIC(void) surf_resource_turn_on(surf_cpp_resource_t resource);
+/** @brief Set the state of a surf resource (cpu, host, network, …) */
+XBT_PUBLIC(void) surf_resource_turn_off(surf_cpp_resource_t resource);
+static inline void surf_host_turn_on(surf_host_t host) {
+ surf_resource_turn_on((surf_cpp_resource_t)host);
+}
+static inline void surf_host_turn_off(surf_host_t host) {
+ surf_resource_turn_off((surf_cpp_resource_t)host);
}
/** @brief Get the available speed of cpu associated to a host */
int MSG_host_is_on(msg_host_t host)
{
xbt_assert((host != NULL), "Invalid parameters (host is NULL)");
- return sg_host_get_state(host);
+ return sg_host_is_on(host);
}
/** @ingroup m_host_management
*
int MSG_host_is_off(msg_host_t host)
{
xbt_assert((host != NULL), "Invalid parameters (host is NULL)");
- return !(sg_host_get_state(host));
+ return !(sg_host_is_on(host));
}
/** \ingroup m_host_management
p_inferior->off();
}
bool Host::isOn() {
- return sg_host_get_state(p_inferior);
+ return sg_host_is_on(p_inferior);
}
boost::unordered_map<std::string, Storage&> &Host::mountedStorages() {
/** @brief Returns the state of a host.
* @return 1 if the host is active or 0 if it has crashed.
*/
-int sg_host_get_state(sg_host_t host) {
- return host->p_cpu->getState();
+int sg_host_is_on(sg_host_t host) {
+ return host->p_cpu->isOn();
}
/** @brief Returns the total energy consumed by the host (in Joules).
simgrid::simix::simcall<void>(SIMCALL_HOST_OFF, this);
}
-e_surf_resource_state_t Host::getState() {
- return p_cpu->getState();
+bool Host::isOn() {
+ return p_cpu->isOn();
+}
+bool Host::isOff() {
+ return ! p_cpu->isOn();
}
xbt_assert((host != NULL), "Invalid parameters");
- if (h->getState()==SURF_RESOURCE_OFF) {
- surf_host_set_state(surf_host_resource_priv(h), SURF_RESOURCE_ON);
+ if (h->isOff()) {
+ surf_host_turn_on(surf_host_resource_priv(h));
unsigned int cpt;
smx_process_arg_t arg;
xbt_assert((host != NULL), "Invalid parameters");
- if (h->getState()==SURF_RESOURCE_ON) {
- surf_host_set_state(surf_host_resource_priv(h), SURF_RESOURCE_OFF);
+ if (h->isOn()) {
+ surf_host_turn_off(surf_host_resource_priv(h));
/* Clean Simulator data */
if (xbt_swag_size(host->process_list) != 0) {
XBT_DEBUG("Killing %s on %s by %s", process->name, sg_host_get_name(process->host), issuer->name);
}
}
+ } else {
+ XBT_INFO("Host %s is already off",h->getName().c_str());
}
}
arg->properties = properties;
arg->auto_restart = auto_restart;
- if( sg_host_get_state(host) == SURF_RESOURCE_OFF
+ if( ! sg_host_is_on(host)
&& !xbt_dict_get_or_null(watched_hosts_lib,sg_host_get_name(host))){
xbt_dict_set(watched_hosts_lib,sg_host_get_name(host),host,NULL);
XBT_DEBUG("Have pushed host %s to watched_hosts_lib because state == SURF_RESOURCE_OFF",sg_host_get_name(host));
(int)synchro->state);
}
/* check if the host is down */
- if (simcall->issuer->host->getState() != SURF_RESOURCE_ON) {
+ if (simcall->issuer->host->isOff()) {
simcall->issuer->context->iwannadie = 1;
}
{
if (synchro->type == SIMIX_SYNC_EXECUTE && /* FIMXE: handle resource failure
* for parallel tasks too */
- synchro->execution.host->getState() == SURF_RESOURCE_OFF) {
+ synchro->execution.host->isOff()) {
/* If the host running the synchro failed, notice it so that the asking
* process can be killed if it runs on that host itself */
synchro->state = SIMIX_FAILED;
XBT_PRIVATE void SIMIX_vm_shutdown(sg_host_t ind_vm, smx_process_t issuer);
// --
-XBT_PRIVATE int SIMIX_vm_get_state(sg_host_t ind_vm);
+XBT_PRIVATE e_surf_vm_state_t SIMIX_vm_get_state(sg_host_t ind_vm);
// --
XBT_PRIVATE void SIMIX_vm_migrate(sg_host_t ind_vm, sg_host_t ind_dst_pm);
smx_synchro_t synchro;
/* check if the host is active */
- if (host->getState() != SURF_RESOURCE_ON) {
+ if (host->isOff()) {
THROWF(host_error, 0, "Host %s failed, you cannot call this function",
sg_host_get_name(host));
}
smx_synchro_t synchro;
/* check if the host is active */
- if (host->getState() != SURF_RESOURCE_ON) {
+ if (host->isOff()) {
THROWF(host_error, 0, "Host %s failed, you cannot call this function",
sg_host_get_name(host));
}
smx_synchro_t synchro;
/* check if the host is active */
- if (host->getState() != SURF_RESOURCE_ON) {
+ if (host->isOff()) {
THROWF(host_error, 0, "Host %s failed, you cannot call this function",
sg_host_get_name(host));
}
smx_synchro_t synchro;
/* check if the host is active */
- if (host->getState() != SURF_RESOURCE_ON) {
+ if (host->isOff()) {
THROWF(host_error, 0, "Host %s failed, you cannot call this function",
sg_host_get_name(host));
}
int SIMIX_file_unlink(smx_file_t fd, sg_host_t host)
{
/* check if the host is active */
- if (host->getState() != SURF_RESOURCE_ON) {
+ if (host->isOff()) {
THROWF(host_error, 0, "Host %s failed, you cannot call this function",
sg_host_get_name(host));
}
(int)synchro->state);
}
- if (simcall->issuer->host->getState() != SURF_RESOURCE_ON) {
+ if (simcall->issuer->host->isOff()) {
simcall->issuer->context->iwannadie = 1;
}
/* Check out for errors */
- if (simcall->issuer->host->getState() != SURF_RESOURCE_ON) {
+ if (simcall->issuer->host->isOff()) {
simcall->issuer->context->iwannadie = 1;
SMX_EXCEPTION(simcall->issuer, host_error, 0, "Host failed");
} else
}
}
- if (simcall->issuer->host->getState() != SURF_RESOURCE_ON) {
+ if (simcall->issuer->host->isOff()) {
simcall->issuer->context->iwannadie = 1;
}
void SIMIX_process_stop(smx_process_t arg) {
/* execute the on_exit functions */
SIMIX_process_on_exit_runall(arg);
- /* Add the process to the list of process to restart, only if
- * the host is down
- */
- if (arg->auto_restart && !sg_host_get_state(arg->host)) {
+ /* Add the process to the list of process to restart, only if the host is down */
+ if (arg->auto_restart && arg->host->isOff()) {
SIMIX_host_add_auto_restart_process(arg->host,arg->name,arg->code, arg->data,
sg_host_get_name(arg->host),
SIMIX_timer_get_date(arg->kill_timer),
XBT_DEBUG("Start process %s on host '%s'", name, hostname);
- if (!sg_host_get_state(host)) {
+ if (host->isOff()) {
int i;
XBT_WARN("Cannot launch process '%s' on failed host '%s'", name,
hostname);
sg_host_t host = process->host;
/* check if the host is active */
- if (host->getState() != SURF_RESOURCE_ON) {
+ if (host->isOff()) {
THROWF(host_error, 0, "Host %s failed, you cannot call this function",
sg_host_get_name(host));
}
THROW_IMPOSSIBLE;
break;
}
- if (simcall->issuer->host->getState() != SURF_RESOURCE_ON) {
+ if (simcall->issuer->host->isOff()) {
simcall->issuer->context->iwannadie = 1;
}
simcall_process_sleep__set__result(simcall, state);
#include "xbt/dict.h"
#include "mc/mc.h"
#include "src/surf/host_interface.hpp"
+#include "src/surf/virtual_machine.hpp"
//If you need to log some stuffs, just uncomment these two lines and uses XBT_DEBUG for instance
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_vm, simix, "Logging specific to SIMIX (vms)");
void SIMIX_vm_start(sg_host_t ind_vm)
{
if (__can_be_started(ind_vm))
- surf_host_set_state(surf_host_resource_priv(ind_vm),
- (e_surf_resource_state_t) SURF_VM_STATE_RUNNING);
+ static_cast<simgrid::surf::VirtualMachine*>(surf_host_resource_priv(ind_vm))
+ ->setState(SURF_VM_STATE_RUNNING);
else
THROWF(vm_error, 0, "The VM %s cannot be started", SIMIX_host_get_name(ind_vm));
}
-int SIMIX_vm_get_state(sg_host_t ind_vm)
+e_surf_vm_state_t SIMIX_vm_get_state(sg_host_t ind_vm)
{
- return surf_host_resource_priv(ind_vm)->getState();
+ return static_cast<simgrid::surf::VirtualMachine*>(surf_host_resource_priv(ind_vm))->getState();
}
/**
}
/* FIXME: we may have to do something at the surf layer, e.g., vcpu action */
- surf_host_set_state(surf_host_resource_priv(ind_vm),
- (e_surf_resource_state_t) SURF_VM_STATE_CREATED);
+ static_cast<simgrid::surf::VirtualMachine*>(surf_host_resource_priv(ind_vm))->setState(SURF_VM_STATE_CREATED);
}
void simcall_HANDLER_vm_shutdown(smx_simcall_t simcall, sg_host_t ind_vm)
Cpu *CpuCas01Model::createCpu(simgrid::Host *host, xbt_dynar_t speedPeak,
int pstate, double speedScale,
tmgr_trace_t speedTrace, int core,
- e_surf_resource_state_t state_initial,
+ int initiallyOn,
tmgr_trace_t state_trace)
{
xbt_assert(xbt_dynar_getfirst_as(speedPeak, double) > 0.0,
"Speed has to be >0.0. Did you forget to specify the mandatory power attribute?");
xbt_assert(core > 0, "Invalid number of cores %d. Must be larger than 0", core);
- Cpu *cpu = new CpuCas01(this, host, speedPeak, pstate, speedScale, speedTrace, core, state_initial, state_trace);
+ Cpu *cpu = new CpuCas01(this, host, speedPeak, pstate, speedScale, speedTrace, core, initiallyOn, state_trace);
return cpu;
}
************/
CpuCas01::CpuCas01(CpuCas01Model *model, simgrid::Host *host, xbt_dynar_t speedPeak,
int pstate, double speedScale, tmgr_trace_t speedTrace, int core,
- e_surf_resource_state_t stateInitial, tmgr_trace_t stateTrace)
+ int initiallyOn, tmgr_trace_t stateTrace)
: Cpu(model, host,
lmm_constraint_new(model->getMaxminSystem(), this, core * speedScale * xbt_dynar_get_as(speedPeak, pstate, double)),
speedPeak, pstate,
core, xbt_dynar_get_as(speedPeak, pstate, double), speedScale,
- stateInitial) {
+ initiallyOn) {
p_speedEvent = NULL;
XBT_DEBUG("CPU create: peak=%f, pstate=%d", m_speedPeak, m_pstate);
xbt_assert(m_core == 1, "FIXME: add state change code also for constraint_core[i]");
if (value > 0) {
- if(getState() == SURF_RESOURCE_OFF)
+ if(isOff())
xbt_dynar_push_as(host_that_restart, char*, (char *)getName());
- setState(SURF_RESOURCE_ON);
+ turnOn();
} else {
lmm_constraint_t cnst = getConstraint();
- setState(SURF_RESOURCE_OFF);
+ turnOff();
while ((var = lmm_get_var_from_cnst(getModel()->getMaxminSystem(), cnst, &elem))) {
Action *action = static_cast<Action*>(lmm_variable_id(var));
{
XBT_IN("(%s,%g)", getName(), size);
- CpuCas01Action *action = new CpuCas01Action(getModel(), size, getState() != SURF_RESOURCE_ON,
+ CpuCas01Action *action = new CpuCas01Action(getModel(), size, isOff(),
m_speedScale * m_speedPeak, getConstraint());
XBT_OUT();
duration = MAX(duration, sg_surf_precision);
XBT_IN("(%s,%g)", getName(), duration);
- CpuCas01Action *action = new CpuCas01Action(getModel(), 1.0, getState() != SURF_RESOURCE_ON,
+ CpuCas01Action *action = new CpuCas01Action(getModel(), 1.0, isOff(),
m_speedScale * m_speedPeak, getConstraint());
Cpu *createCpu(simgrid::Host *host, xbt_dynar_t speedPeak, int pstate,
double speedScale,
tmgr_trace_t speedTrace, int core,
- e_surf_resource_state_t state_initial,
+ int initiallyOn,
tmgr_trace_t state_trace) override;
double shareResourcesFull(double now) override;
void addTraces() override;
public:
CpuCas01(CpuCas01Model *model, simgrid::Host *host, xbt_dynar_t speedPeak,
int pstate, double speedScale, tmgr_trace_t speedTrace, int core,
- e_surf_resource_state_t stateInitial, tmgr_trace_t stateTrace) ;
+ int initiallyOn, tmgr_trace_t stateTrace) ;
~CpuCas01();
void updateState(tmgr_trace_event_t event_type, double value, double date) override;
CpuAction *execute(double size) override;
Cpu::Cpu(Model *model, simgrid::Host *host,
xbt_dynar_t speedPeakList, int pstate,
int core, double speedPeak, double speedScale,
- e_surf_resource_state_t stateInitial)
- : Cpu(model, host, NULL/*constraint*/, speedPeakList, pstate, core, speedPeak, speedScale, stateInitial)
+ int initiallyOn)
+ : Cpu(model, host, NULL/*constraint*/, speedPeakList, pstate, core, speedPeak, speedScale, initiallyOn)
{
}
Cpu::Cpu(Model *model, simgrid::Host *host, lmm_constraint_t constraint,
xbt_dynar_t speedPeakList, int pstate,
int core, double speedPeak,
- double speedScale, e_surf_resource_state_t stateInitial)
- : Resource(model, host->getName().c_str(), constraint, stateInitial)
+ double speedScale, int initiallyOn)
+ : Resource(model, host->getName().c_str(), constraint, initiallyOn)
, m_core(core)
, m_speedPeak(speedPeak)
, m_speedScale(speedScale)
virtual Cpu *createCpu(simgrid::Host *host, xbt_dynar_t speedPeak,
int pstate, double speedScale,
tmgr_trace_t speedTrace, int core,
- e_surf_resource_state_t state_initial,
+ int initiallyOn,
tmgr_trace_t state_trace)=0;
void updateActionsStateLazy(double now, double delta);
Cpu(simgrid::surf::Model *model, simgrid::Host *host, lmm_constraint_t constraint,
xbt_dynar_t speedPeakList, int pstate,
int core, double speedPeak, double speedScale,
- e_surf_resource_state_t stateInitial);
+ int initiallyOn);
/**
* @brief Cpu constructor
Cpu(simgrid::surf::Model *model, simgrid::Host *host,
xbt_dynar_t speedPeakList, int pstate,
int core, double speedPeak, double speedScale,
- e_surf_resource_state_t stateInitial);
+ int initiallyOn);
~Cpu();
/** @brief CpuAction constructor */
CpuAction(simgrid::surf::Model *model, double cost, bool failed)
- : Action(model, cost, failed) {} //FIXME:REMOVE
+ : Action(model, cost, failed) {} //FIXME:DEADCODE?
/** @brief CpuAction constructor */
CpuAction(simgrid::surf::Model *model, double cost, bool failed, lmm_variable_t var)
double speedScale,
tmgr_trace_t speedTrace,
int core,
- e_surf_resource_state_t stateInitial,
+ int initiallyOn,
tmgr_trace_t stateTrace)
{
xbt_assert(core==1,"Multi-core not handled with this model yet");
xbt_assert(xbt_dynar_getfirst_as(speedPeak, double) > 0.0,
"Speed has to be >0.0. Did you forget to specify the mandatory speed attribute?");
CpuTi *cpu = new CpuTi(this, host, speedPeak, pstate, speedScale, speedTrace,
- core, stateInitial, stateTrace);
+ core, initiallyOn, stateTrace);
return cpu;
}
************/
CpuTi::CpuTi(CpuTiModel *model, simgrid::Host *host, xbt_dynar_t speedPeak,
int pstate, double speedScale, tmgr_trace_t speedTrace, int core,
- e_surf_resource_state_t stateInitial, tmgr_trace_t stateTrace)
- : Cpu(model, host, NULL, pstate, core, 0, speedScale, stateInitial)
+ int initiallyOn, tmgr_trace_t stateTrace)
+ : Cpu(model, host, NULL, pstate, core, 0, speedScale, initiallyOn)
{
xbt_assert(core==1,"Multi-core not handled by this model yet");
m_core = core;
} else if (event_type == p_stateEvent) {
if (value > 0) {
- if(getState() == SURF_RESOURCE_OFF)
+ if(isOff())
xbt_dynar_push_as(host_that_restart, char*, (char *)getName());
- setState(SURF_RESOURCE_ON);
+ turnOn();
} else {
- setState(SURF_RESOURCE_OFF);
+ turnOff();
/* put all action running on cpu to failed */
for(ActionTiList::iterator it(p_actionSet->begin()), itend(p_actionSet->end())
CpuAction *CpuTi::execute(double size)
{
XBT_IN("(%s,%g)", getName(), size);
- CpuTiAction *action = new CpuTiAction(static_cast<CpuTiModel*>(getModel()), size, getState() != SURF_RESOURCE_ON, this);
+ CpuTiAction *action = new CpuTiAction(static_cast<CpuTiModel*>(getModel()), size, isOff(), this);
p_actionSet->push_back(*action);
duration = MAX(duration, sg_surf_precision);
XBT_IN("(%s,%g)", getName(), duration);
- CpuTiAction *action = new CpuTiAction(static_cast<CpuTiModel*>(getModel()), 1.0, getState() != SURF_RESOURCE_ON, this);
+ CpuTiAction *action = new CpuTiAction(static_cast<CpuTiModel*>(getModel()), 1.0, isOff(), this);
action->m_maxDuration = duration;
action->m_suspended = 2;
public:
CpuTi(CpuTiModel *model, simgrid::Host *host, xbt_dynar_t speedPeak,
int pstate, double speedScale, tmgr_trace_t speedTrace, int core,
- e_surf_resource_state_t stateInitial, tmgr_trace_t stateTrace) ;
+ int initiallyOn, tmgr_trace_t stateTrace) ;
~CpuTi();
void updateState(tmgr_trace_event_t event_type, double value, double date) override;
Cpu *createCpu(simgrid::Host *host, xbt_dynar_t speedPeak,
int pstate, double speedScale,
tmgr_trace_t speedTrace, int core,
- e_surf_resource_state_t state_initial,
+ int initiallyOn,
tmgr_trace_t state_trace);
double shareResources(double now) override;
void updateActionsState(double now, double delta) override;
************/
simgrid::surf::signal<void(simgrid::surf::Host*)> Host::onCreation;
simgrid::surf::signal<void(simgrid::surf::Host*)> Host::onDestruction;
-simgrid::surf::signal<void(simgrid::surf::Host*, e_surf_resource_state_t, e_surf_resource_state_t)> Host::onStateChange;
+simgrid::surf::signal<void(simgrid::surf::Host*)> Host::onStateChange;
Host::Host(simgrid::surf::Model *model, const char *name, xbt_dict_t props,
xbt_dynar_t storage, NetCard *netElm, Cpu *cpu)
onCreation(this);
}
-e_surf_resource_state_t Host::getState() {
- return p_cpu->getState();
+bool Host::isOn() {
+ return p_cpu->isOn();
}
-void Host::setState(e_surf_resource_state_t state){
- e_surf_resource_state_t old = Resource::getState();
- Resource::setState(state);
- onStateChange(this, old, state);
- p_cpu->setState(state);
+bool Host::isOff() {
+ return p_cpu->isOff();
+}
+void Host::turnOn(){
+ if (isOff()) {
+ p_cpu->turnOn();
+ onStateChange(this);
+ }
+}
+void Host::turnOff(){
+ if (isOn()) {
+ p_cpu->turnOff();
+ onStateChange(this);
+ }
}
-
simgrid::surf::Storage *Host::findStorageOnMountList(const char* mount)
{
/* callbacks */
static simgrid::surf::signal<void(Host*)> onCreation; /** Called on each newly created object */
static simgrid::surf::signal<void(Host*)> onDestruction; /** Called just before destructing an object */
- static simgrid::surf::signal<void(simgrid::surf::Host*, e_surf_resource_state_t, e_surf_resource_state_t)> onStateChange;
+ static simgrid::surf::signal<void(Host*)> onStateChange; /** Called when the machine is turned on or off */
public:
/**
public:
void attach(simgrid::Host* host);
- e_surf_resource_state_t getState();
- void setState(e_surf_resource_state_t state);
+ bool isOn() override;
+ bool isOff() override;
+ void turnOn() override;
+ void turnOff() override;
/** @brief Return the storage of corresponding mount point */
virtual simgrid::surf::Storage *findStorageOnMountList(const char* storage);
routing_model_create(surf_network_model->createLink("__loopback__",
498000000, NULL,
0.000015, NULL,
- SURF_RESOURCE_ON, NULL,
+ 1/*ON*/, NULL,
SURF_LINK_FATPIPE, NULL));
}
while ((cnst = lmm_get_cnst_from_var(p_maxminSystem, action->getVariable(), i++))) {
void *constraint_id = lmm_constraint_id(cnst);
- if (static_cast<Host*>(constraint_id)->getState() == SURF_RESOURCE_OFF) {
+ if (static_cast<Host*>(constraint_id)->isOff()) {
XBT_DEBUG("Action (%p) Failed!!", action);
action->finish();
action->setState(SURF_ACTION_FAILED);
Cpu *CpuL07Model::createCpu(simgrid::Host *host, xbt_dynar_t powerPeakList,
int pstate, double power_scale,
tmgr_trace_t power_trace, int core,
- e_surf_resource_state_t state_initial,
+ int initiallyOn,
tmgr_trace_t state_trace)
{
CpuL07 *cpu = new CpuL07(this, host, powerPeakList, pstate, power_scale, power_trace,
- core, state_initial, state_trace);
+ core, initiallyOn, state_trace);
return cpu;
}
tmgr_trace_t bw_trace,
double lat_initial,
tmgr_trace_t lat_trace,
- e_surf_resource_state_t state_initial,
+ int initiallyOn,
tmgr_trace_t state_trace,
e_surf_link_sharing_policy_t policy,
xbt_dict_t properties)
Link* link = new LinkL07(this, name, properties,
bw_initial, bw_trace,
lat_initial, lat_trace,
- state_initial, state_trace,
+ initiallyOn, state_trace,
policy);
Link::onCreation(link);
return link;
CpuL07::CpuL07(CpuL07Model *model, simgrid::Host *host,
xbt_dynar_t speedPeakList, int pstate,
double speedScale, tmgr_trace_t speedTrace,
- int core, e_surf_resource_state_t state_initial, tmgr_trace_t state_trace)
+ int core, int initiallyOn, tmgr_trace_t state_trace)
: Cpu(model, host, speedPeakList, pstate,
- core, xbt_dynar_get_as(speedPeakList,pstate,double), speedScale, state_initial)
+ core, xbt_dynar_get_as(speedPeakList,pstate,double), speedScale, initiallyOn)
{
p_constraint = lmm_constraint_new(model->getMaxminSystem(), this, xbt_dynar_get_as(speedPeakList,pstate,double) * speedScale);
tmgr_trace_t bw_trace,
double lat_initial,
tmgr_trace_t lat_trace,
- e_surf_resource_state_t state_initial,
+ int initiallyOn,
tmgr_trace_t state_trace,
e_surf_link_sharing_policy_t policy)
: Link(model, name, props, lmm_constraint_new(model->getMaxminSystem(), this, bw_initial), history, state_trace)
if (bw_trace)
p_bwEvent = tmgr_history_add_trace(history, bw_trace, 0.0, 0, this);
- setState(state_initial);
+ if (initiallyOn)
+ turnOn();
+ else
+ turnOff();
m_latCurrent = lat_initial;
if (lat_trace)
p_speedEvent = NULL;
} else if (event_type == p_stateEvent) {
if (value > 0)
- setState(SURF_RESOURCE_ON);
+ turnOn();
else
- setState(SURF_RESOURCE_OFF);
+ turnOff();
if (tmgr_trace_event_free(event_type))
p_stateEvent = NULL;
} else {
p_latEvent = NULL;
} else if (event_type == p_stateEvent) {
if (value > 0)
- setState(SURF_RESOURCE_ON);
+ turnOn();
else
- setState(SURF_RESOURCE_OFF);
+ turnOff();
if (tmgr_trace_event_free(event_type))
p_stateEvent = NULL;
} else {
Cpu *createCpu(simgrid::Host *host, xbt_dynar_t speedPeakList,
int pstate, double speedScale,
tmgr_trace_t speedTrace, int core,
- e_surf_resource_state_t state_initial,
+ int initiallyOn,
tmgr_trace_t state_trace) override;
void addTraces() override {DIE_IMPOSSIBLE;};
tmgr_trace_t bw_trace,
double lat_initial,
tmgr_trace_t lat_trace,
- e_surf_resource_state_t state_initial,
+ int initiallyOn,
tmgr_trace_t state_trace,
e_surf_link_sharing_policy_t policy,
xbt_dict_t properties) override;
public:
CpuL07(CpuL07Model *model, simgrid::Host *host, xbt_dynar_t speedPeakList, int pstate,
double power_scale, tmgr_trace_t power_trace,
- int core, e_surf_resource_state_t state_initial, tmgr_trace_t state_trace);
+ int core, int initiallyOn, tmgr_trace_t state_trace);
~CpuL07();
bool isUsed() override;
void updateState(tmgr_trace_event_t event_type, double value, double date) override;
tmgr_trace_t bw_trace,
double lat_initial,
tmgr_trace_t lat_trace,
- e_surf_resource_state_t
- state_initial,
+ int initiallyOn,
tmgr_trace_t state_trace,
e_surf_link_sharing_policy_t policy);
~LinkL07(){ };
routing_model_create(createLink("__loopback__",
498000000, NULL, 0.000015, NULL,
- SURF_RESOURCE_ON, NULL,
+ 1 /*SURF_RESOURCE_ON*/, NULL,
SURF_LINK_FATPIPE, NULL));
if (p_updateMechanism == UM_LAZY) {
tmgr_trace_t bw_trace,
double lat_initial,
tmgr_trace_t lat_trace,
- e_surf_resource_state_t state_initial,
+ int initiallyOn,
tmgr_trace_t state_trace,
e_surf_link_sharing_policy_t policy,
xbt_dict_t properties)
name);
Link* link = new NetworkCm02Link(this, name, properties, p_maxminSystem, sg_bandwidth_factor * bw_initial, history,
- state_initial, state_trace, bw_initial, bw_trace, lat_initial, lat_trace, policy);
+ initiallyOn, state_trace, bw_initial, bw_trace, lat_initial, lat_trace, policy);
Link::onCreation(link);
return link;
}
xbt_dynar_foreach(route, i, _link) {
link = static_cast<NetworkCm02Link*>(_link);
- if (link->getState() == SURF_RESOURCE_OFF) {
+ if (link->isOff()) {
failed = 1;
break;
}
routing_platf->getRouteAndLatency(dst, src, &back_route, NULL);
xbt_dynar_foreach(back_route, i, _link) {
link = static_cast<NetworkCm02Link*>(_link);
- if (link->getState() == SURF_RESOURCE_OFF) {
+ if (link->isOff()) {
failed = 1;
break;
}
lmm_system_t system,
double constraint_value,
tmgr_history_t history,
- e_surf_resource_state_t state_init,
+ int initiallyOn,
tmgr_trace_t state_trace,
double metric_peak,
tmgr_trace_t metric_trace,
e_surf_link_sharing_policy_t policy)
: Link(model, name, props, lmm_constraint_new(system, this, constraint_value), history, state_trace)
{
- setState(state_init);
+ if (initiallyOn)
+ turnOn();
+ else
+ turnOff();
p_speed.scale = 1.0;
p_speed.peak = metric_peak;
p_latEvent = NULL;
} else if (event_type == p_stateEvent) {
if (value > 0)
- setState(SURF_RESOURCE_ON);
+ turnOn();
else {
lmm_constraint_t cnst = getConstraint();
lmm_variable_t var = NULL;
lmm_element_t elem = NULL;
- setState(SURF_RESOURCE_OFF);
+ turnOff();
while ((var = lmm_get_var_from_cnst(getModel()->getMaxminSystem(), cnst, &elem))) {
Action *action = static_cast<Action*>( lmm_variable_id(var) );
tmgr_trace_t bw_trace,
double lat_initial,
tmgr_trace_t lat_trace,
- e_surf_resource_state_t state_initial,
+ int initiallyOn,
tmgr_trace_t state_trace,
e_surf_link_sharing_policy_t policy,
xbt_dict_t properties) override;
lmm_system_t system,
double constraint_value,
tmgr_history_t history,
- e_surf_resource_state_t state_init,
+ int initiallyOn,
tmgr_trace_t state_trace,
double metric_peak,
tmgr_trace_t metric_trace,
tmgr_trace_t bw_trace,
double lat_initial,
tmgr_trace_t lat_trace,
- e_surf_resource_state_t state_initial,
+ int initiallyOn,
tmgr_trace_t state_trace,
e_surf_link_sharing_policy_t policy,
xbt_dict_t properties) override { DIE_IMPOSSIBLE; }
simgrid::surf::signal<void(simgrid::surf::Link*)> Link::onCreation;
simgrid::surf::signal<void(simgrid::surf::Link*)> Link::onDestruction;
-simgrid::surf::signal<void(simgrid::surf::Link*, e_surf_resource_state_t, e_surf_resource_state_t)> Link::onStateChange;
+simgrid::surf::signal<void(simgrid::surf::Link*, int, int)> Link::onStateChange; // signature: wasOn, currentlyOn
simgrid::surf::signal<void(simgrid::surf::NetworkAction*, e_surf_action_state_t, e_surf_action_state_t)> networkActionStateChangedCallbacks;
simgrid::surf::signal<void(simgrid::surf::NetworkAction*, simgrid::surf::NetCard *src, simgrid::surf::NetCard *dst, double size, double rate)> networkCommunicateCallbacks;
link->bandwidth_trace,
link->latency,
link->latency_trace,
- link->state,
+ link->initiallyOn,
link->state_trace, link->policy, link->properties);
xbt_free(link_id);
link_id = bprintf("%s_DOWN", link->id);
link->bandwidth_trace,
link->latency,
link->latency_trace,
- link->state,
+ link->initiallyOn,
link->state_trace, link->policy, link->properties);
xbt_free(link_id);
} else {
link->bandwidth_trace,
link->latency,
link->latency_trace,
- link->state,
+ link->initiallyOn,
link->state_trace, link->policy, link->properties);
}
}
return lmm_constraint_sharing_policy(getConstraint());
}
-void Link::setState(e_surf_resource_state_t state){
- e_surf_resource_state_t old = Resource::getState();
- Resource::setState(state);
- onStateChange(this, old, state);
+void Link::turnOn(){
+ if (isOff()) {
+ Resource::turnOn();
+ onStateChange(this, 0, 1);
+ }
+}
+void Link::turnOff(){
+ if (isOn()) {
+ Resource::turnOff();
+ onStateChange(this, 1, 0);
+ }
}
/**********
tmgr_trace_t bw_trace,
double lat_initial,
tmgr_trace_t lat_trace,
- e_surf_resource_state_t state_initial,
+ int initiallyOn,
tmgr_trace_t state_trace,
e_surf_link_sharing_policy_t policy,
xbt_dict_t properties)=0;
static simgrid::surf::signal<void(simgrid::surf::Link*)> onDestruction;
/** @brief Callback signal fired when the state of a Link changes
- * Signature: `void(LinkAction *action, e_surf_resource_state_t oldState, e_surf_resource_state_t currentState)` */
- static simgrid::surf::signal<void(simgrid::surf::Link*, e_surf_resource_state_t, e_surf_resource_state_t)> onStateChange;
+ * Signature: `void(LinkAction *action, int previouslyOn, int currentlyOn)` */
+ static simgrid::surf::signal<void(simgrid::surf::Link*, int, int)> onStateChange;
/** @brief Get the bandwidth in bytes per second of current Link */
/** @brief Check if the Link is used */
bool isUsed();
- void setState(e_surf_resource_state_t state);
+ void turnOn() override;
+ void turnOff() override;
/* Using this object with the public part of
model does not make sense */
link->bandwidth_trace,
link->latency,
link->latency_trace,
- link->state,
+ link->initiallyOn,
link->state_trace,
link->policy,
link->properties);
tmgr_trace_t bw_trace,
double lat_initial,
tmgr_trace_t lat_trace,
- e_surf_resource_state_t state_initial,
+ int initiallyOn,
tmgr_trace_t state_trace,
e_surf_link_sharing_policy_t policy,
xbt_dict_t properties){
tmgr_trace_t bw_trace,
double lat_initial,
tmgr_trace_t lat_trace,
- e_surf_resource_state_t state_initial,
+ int initiallyOn,
tmgr_trace_t state_trace,
e_surf_link_sharing_policy_t policy,
xbt_dict_t properties);
else
cpu_load = lmm_constraint_get_usage(host->p_cpu->getConstraint()) / host->p_cpu->m_speedPeak;
+ if (cpu_load > 1) // A machine with a load > 1 consumes as much as a fully loaded machine, not mores
+ cpu_load = 1;
+
double previous_energy = host_energy->total_energy;
double instantaneous_consumption;
- if (host->getState() == SURF_RESOURCE_OFF)
+ if (host->isOff())
instantaneous_consumption = host_energy->watts_off;
else
instantaneous_consumption = host_energy->getCurrentWattsValue(cpu_load);
host_energy->total_energy = previous_energy + energy_this_step;
host_energy->last_updated = finish_time;
- XBT_DEBUG("[cpu_update_energy] period=[%.2f-%.2f]; current power peak=%.0E flop/s; consumption change: %.2f J -> %.2f J",
- start_time, finish_time, host->p_cpu->m_speedPeak, previous_energy, energy_this_step);
+ XBT_DEBUG("[update_energy of %s] period=[%.2f-%.2f]; current power peak=%.0E flop/s; consumption change: %.2f J -> %.2f J",
+ host->getName(), start_time, finish_time, host->p_cpu->m_speedPeak, previous_energy, energy_this_step);
}
/** \ingroup SURF_plugin_energy
simgrid::energy::surf_energy = new std::map<simgrid::surf::Host*, simgrid::energy::HostEnergy*>();
- /* The following attaches an anonymous function to the Host::onCreation signal */
+ /* The following attaches an anonymous function to the Host::onCreation signal */
/* Search for "C++ lambda" for more information on the syntax used here */
- simgrid::surf::Host::onCreation.connect([](simgrid::surf::Host *host) {
- (*simgrid::energy::surf_energy)[host] = new HostEnergy(host);
- });
-
- simgrid::surf::VMCreatedCallbacks.connect([](simgrid::surf::VirtualMachine* vm) {
- std::map<simgrid::surf::Host*, HostEnergy*>::iterator host_energy_it =
- simgrid::energy::surf_energy->find(vm->p_hostPM->extension(simgrid::surf::Host::EXTENSION_ID));
- xbt_assert(host_energy_it != simgrid::energy::surf_energy->end(), "The host is not in surf_energy.");
- (*simgrid::energy::surf_energy)[vm] = host_energy_it->second;
- host_energy_it->second->ref(); // protect the HostEnergy from getting deleted too early
- });
-
- simgrid::surf::Host::onDestruction.connect([](simgrid::surf::Host *host) {
- std::map<simgrid::surf::Host*, HostEnergy*>::iterator host_energy_it = simgrid::energy::surf_energy->find(host);
- xbt_assert(host_energy_it != simgrid::energy::surf_energy->end(), "The host is not in surf_energy.");
-
- HostEnergy *host_energy = host_energy_it->second;
- update_consumption(host, host_energy);
-
- if (host_energy_it->second->refcount == 1) // Don't display anything for virtual CPUs
- XBT_INFO("Total energy of host %s: %f Joules", host->getName(), host_energy->getConsumedEnergy());
- host_energy_it->second->unref();
- simgrid::energy::surf_energy->erase(host_energy_it);
- });
- simgrid::surf::CpuAction::onStateChange.connect([](simgrid::surf::CpuAction *action,
- e_surf_action_state_t old,
- e_surf_action_state_t cur) {
- const char *name = getActionCpu(action)->getName();
- simgrid::surf::Host *host = static_cast<simgrid::surf::Host*>(surf_host_resource_priv(sg_host_by_name(name)));
-
- HostEnergy *host_energy = (*simgrid::energy::surf_energy)[host];
-
- if(host_energy->last_updated < surf_get_clock())
- update_consumption(host, host_energy);
-
- });
-
- simgrid::surf::Host::onStateChange.connect([]
- (simgrid::surf::Host *host,
- e_surf_resource_state_t oldState,
- e_surf_resource_state_t newState) {
- HostEnergy *host_energy = (*simgrid::energy::surf_energy)[host];
-
- if(host_energy->last_updated < surf_get_clock())
- update_consumption(host, host_energy);
- });
-
- simgrid::surf::surfExitCallbacks.connect([]() {
- delete simgrid::energy::surf_energy;
- simgrid::energy::surf_energy = NULL;
- });
+ simgrid::surf::Host::onCreation.connect([](simgrid::surf::Host *host) {
+ if (dynamic_cast<simgrid::surf::VirtualMachine*>(host)) // Ignore virtual machines
+ return;
+
+ (*simgrid::energy::surf_energy)[host] = new HostEnergy(host);
+ });
+
+ simgrid::surf::Host::onDestruction.connect([](simgrid::surf::Host *host) {
+ if (dynamic_cast<simgrid::surf::VirtualMachine*>(host)) // Ignore virtual machines
+ return;
+
+ std::map<simgrid::surf::Host*, HostEnergy*>::iterator host_energy_it = simgrid::energy::surf_energy->find(host);
+ xbt_assert(host_energy_it != simgrid::energy::surf_energy->end(), "The host is not in surf_energy.");
+
+ HostEnergy *host_energy = host_energy_it->second;
+ update_consumption(host, host_energy);
+
+ XBT_INFO("Total energy of host %s: %f Joules", host->getName(), host_energy->getConsumedEnergy());
+ host_energy_it->second->unref();
+ simgrid::energy::surf_energy->erase(host_energy_it);
+ });
+
+ simgrid::surf::CpuAction::onStateChange.connect([](simgrid::surf::CpuAction *action,
+ e_surf_action_state_t old,
+ e_surf_action_state_t cur) {
+ const char *name = getActionCpu(action)->getName();
+ simgrid::surf::Host *host = surf_host_resource_priv(sg_host_by_name(name));
+ simgrid::surf::VirtualMachine *vm = dynamic_cast<simgrid::surf::VirtualMachine*>(host);
+ if (vm) // If it's a VM, take the corresponding PM
+ host = surf_host_resource_priv(vm->getPm());
+
+ HostEnergy *host_energy = (*simgrid::energy::surf_energy)[host];
+
+ if(host_energy->last_updated < surf_get_clock())
+ update_consumption(host, host_energy);
+
+ });
+
+ simgrid::surf::Host::onStateChange.connect([] (simgrid::surf::Host *host) {
+ if (dynamic_cast<simgrid::surf::VirtualMachine*>(host)) // Ignore virtual machines
+ return;
+
+ HostEnergy *host_energy = (*simgrid::energy::surf_energy)[host];
+
+ if(host_energy->last_updated < surf_get_clock())
+ update_consumption(host, host_energy);
+ });
+
+ simgrid::surf::surfExitCallbacks.connect([]() {
+ delete simgrid::energy::surf_energy;
+ simgrid::energy::surf_energy = NULL;
+ });
}
}
int pstate = host->p_cpu->getPState();
xbt_assert(pstate < (int)xbt_dynar_length(power_range_list),
"pstate %d >= power range amound %d",pstate,(int)xbt_dynar_length(power_range_list));
- /* retrieve the power values associated with the current pstate */
- xbt_dynar_t current_power_values = xbt_dynar_get_as( power_range_list, pstate, xbt_dynar_t);
+ /* retrieve the power values associated with the current pstate */
+ xbt_dynar_t current_power_values = xbt_dynar_get_as( power_range_list, pstate, xbt_dynar_t);
- /* min_power corresponds to the idle power (cpu load = 0) */
- /* max_power is the power consumed at 100% cpu load */
- double min_power = xbt_dynar_get_as(current_power_values, 0, double);
- double max_power = xbt_dynar_get_as(current_power_values, 1, double);
- double power_slope = max_power - min_power;
+ /* min_power corresponds to the idle power (cpu load = 0) */
+ /* max_power is the power consumed at 100% cpu load */
+ double min_power = xbt_dynar_get_as(current_power_values, 0, double);
+ double max_power = xbt_dynar_get_as(current_power_values, 1, double);
+ double power_slope = max_power - min_power;
- double current_power = min_power + cpu_load * power_slope;
+ double current_power = min_power + cpu_load * power_slope;
XBT_DEBUG("[get_current_watts] min_power=%f, max_power=%f, slope=%f", min_power, max_power, power_slope);
- XBT_DEBUG("[get_current_watts] Current power (watts) = %f, load = %f", current_power, cpu_load);
+ XBT_DEBUG("[get_current_watts] Current power (watts) = %f, load = %f", current_power, cpu_load);
return current_power;
}
host->speed_scale,
host->speed_trace,
host->core_amount,
- host->initial_state,
+ host->initiallyOn,
host->state_trace);
surf_host_model->createHost(host->id, net, cpu, host->properties)->attach(h);
if (TRACE_is_enabled() && TRACE_needs_platform())
simgrid::surf::signal<void(simgrid::surf::Storage*)> storageCreatedCallbacks;
simgrid::surf::signal<void(simgrid::surf::Storage*)> storageDestructedCallbacks;
-simgrid::surf::signal<void(simgrid::surf::Storage*, e_surf_resource_state_t, e_surf_resource_state_t)> storageStateChangedCallbacks;
+simgrid::surf::signal<void(simgrid::surf::Storage*, int, int)> storageStateChangedCallbacks; // signature: wasOn, isOn
simgrid::surf::signal<void(simgrid::surf::StorageAction*, e_surf_action_state_t, e_surf_action_state_t)> storageActionStateChangedCallbacks;
/*********
, p_writeActions(xbt_dynar_new(sizeof(Action*),NULL))
{
p_content = parseContent(content_name);
- setState(SURF_RESOURCE_ON);
+ turnOn();
}
Storage::Storage(Model *model, const char *name, xbt_dict_t props,
{
p_content = parseContent(content_name);
p_attach = xbt_strdup(attach);
- setState(SURF_RESOURCE_ON);
+ turnOn();
XBT_DEBUG("Create resource with Bconnection '%f' Bread '%f' Bwrite '%f' and Size '%llu'", bconnection, bread, bwrite, size);
p_constraintRead = lmm_constraint_new(maxminSystem, this, bread);
p_constraintWrite = lmm_constraint_new(maxminSystem, this, bwrite);
THROW_UNIMPLEMENTED;
}
-void Storage::setState(e_surf_resource_state_t state)
-{
- e_surf_resource_state_t old = Resource::getState();
- Resource::setState(state);
- storageStateChangedCallbacks(this, old, state);
+void Storage::turnOn() {
+ if (isOff()) {
+ Resource::turnOn();
+ storageStateChangedCallbacks(this, 0, 1);
+ }
+}
+void Storage::turnOff() {
+ if (isOn()) {
+ Resource::turnOff();
+ storageStateChangedCallbacks(this, 1, 0);
+ }
}
xbt_dict_t Storage::getContent()
/** @ingroup SURF_callbacks
* @brief Callbacks handler which emit the callbacks after Storage State changed *
- * @details Callback functions have the following signature: `void(StorageAction *action, e_surf_resource_state_t old, e_surf_resource_state_t current)`
+ * @details Callback functions have the following signature: `void(StorageAction *action, int previouslyOn, int currentlyOn)`
*/
-XBT_PUBLIC_DATA(simgrid::surf::signal<void(simgrid::surf::Storage*, e_surf_resource_state_t, e_surf_resource_state_t)>) storageStateChangedCallbacks;
+XBT_PUBLIC_DATA(simgrid::surf::signal<void(simgrid::surf::Storage*, int, int)>) storageStateChangedCallbacks;
/** @ingroup SURF_callbacks
* @brief Callbacks handler which emit the callbacks after StorageAction State changed *
*/
void updateState(tmgr_trace_event_t event_type, double value, double date);
- void setState(e_surf_resource_state_t state);
+ void turnOn() override;
+ void turnOff() override;
xbt_dict_t p_content;
char* p_contentType;
file->mount = xbt_strdup(mount);
file->current_position = 0;
- StorageAction *action = new StorageN11Action(getModel(), 0, getState() != SURF_RESOURCE_ON, this, OPEN);
+ StorageAction *action = new StorageN11Action(getModel(), 0, isOff(), this, OPEN);
action->p_file = file;
return action;
free(fd->name);
free(fd->mount);
xbt_free(fd);
- StorageAction *action = new StorageN11Action(getModel(), 0, getState() != SURF_RESOURCE_ON, this, CLOSE);
+ StorageAction *action = new StorageN11Action(getModel(), 0, isOff(), this, CLOSE);
return action;
}
else
fd->current_position += size;
- StorageAction *action = new StorageN11Action(getModel(), size, getState() != SURF_RESOURCE_ON, this, READ);
+ StorageAction *action = new StorageN11Action(getModel(), size, isOff(), this, READ);
return action;
}
char *filename = fd->name;
XBT_DEBUG("\tWrite file '%s' size '%llu/%llu'",filename,size,fd->size);
- StorageAction *action = new StorageN11Action(getModel(), size, getState() != SURF_RESOURCE_ON, this, WRITE);
+ StorageAction *action = new StorageN11Action(getModel(), size, isOff(), this, WRITE);
action->p_file = fd;
/* Substract the part of the file that might disappear from the used sized on
* the storage element */
return resource->getName();
}
-e_surf_resource_state_t surf_resource_get_state(surf_cpp_resource_t resource){
- return resource->getState();
+int surf_resource_is_on(surf_cpp_resource_t resource){
+ return resource->isOn();
}
-
-void surf_resource_set_state(surf_cpp_resource_t resource, e_surf_resource_state_t state){
- resource->setState(state);
+int surf_resource_is_off(surf_cpp_resource_t resource){
+ return resource->isOff();
+}
+void surf_resource_turn_on(surf_cpp_resource_t resource){
+ resource->turnOn();
+}
+void surf_resource_turn_off(surf_cpp_resource_t resource){
+ resource->turnOff();
}
surf_action_t surf_host_sleep(sg_host_t host, double duration){
Resource::Resource()
: p_name(NULL), p_model(NULL)
-{}
+{} // FIXME: DEADCODE?
Resource::Resource(Model *model, const char *name)
- : Resource(model, name, SURF_RESOURCE_ON)
-{}
+ : Resource(model, name, 1/*SURF_RESOURCE_ON*/)
+{} // FIXME: DEADCODE?
Resource::Resource(Model *model, const char *name, lmm_constraint_t constraint)
- : Resource(model, name, constraint, SURF_RESOURCE_ON)
+ : Resource(model, name, constraint, 1/*SURF_RESOURCE_ON*/)
{}
-Resource::Resource(
- Model *model, const char *name,
- lmm_constraint_t constraint, e_surf_resource_state_t stateInit)
- : p_name(xbt_strdup(name)), p_model(model)
- , m_running(true), m_stateCurrent(stateInit), p_constraint(constraint)
+Resource::Resource(Model *model, const char *name, lmm_constraint_t constraint, int initiallyOn)
+ : p_name(xbt_strdup(name))
+ , p_model(model)
+ , m_isOn(initiallyOn)
+ , p_constraint(constraint)
{}
-Resource::Resource(Model *model, const char *name, e_surf_resource_state_t stateInit)
- : p_name(xbt_strdup(name)), p_model(model)
- , m_running(true), m_stateCurrent(stateInit)
-{}
+Resource::Resource(Model *model, const char *name, int initiallyOn)
+ : p_name(xbt_strdup(name))
+ , p_model(model)
+ , m_isOn(initiallyOn)
+{} // FIXME: DEADCODE?
Resource::~Resource() {
xbt_free((void*)p_name);
}
-e_surf_resource_state_t Resource::getState()
-{
- return m_stateCurrent;
+bool Resource::isOn() {
+ return m_isOn;
}
-
-void Resource::setState(e_surf_resource_state_t state)
-{
- m_stateCurrent = state;
-}
-
-bool Resource::isOn()
-{
- return m_running;
+bool Resource::isOff() {
+ return ! m_isOn;
}
void Resource::turnOn()
{
- if (!m_running) {
- m_running = true;
+ if (!m_isOn) {
+ m_isOn = true;
}
}
void Resource::turnOff()
{
- if (m_running) {
- m_running = false;
+ if (m_isOn) {
+ m_isOn = false;
}
}
*/
Resource(Model *model, const char *name, lmm_constraint_t constraint);
- Resource(Model *model, const char *name, lmm_constraint_t constraint, e_surf_resource_state_t stateInit);
+ Resource(Model *model, const char *name, lmm_constraint_t constraint, int initiallyOn);
/**
* @brief Resource constructor
*
* @param model Model associated to this Resource
* @param name The name of the Resource
- * @param stateInit the initial state of the Resource
+ * @param initiallyOn the initial state of the Resource
*/
- Resource(Model *model, const char *name, e_surf_resource_state_t stateInit);
+ Resource(Model *model, const char *name, int initiallyOn);
virtual ~Resource();
virtual bool isUsed()=0;
/** @brief Check if the current Resource is active */
- bool isOn();
+ virtual bool isOn();
+ /** @brief Check if the current Resource is shut down */
+ virtual bool isOff();
/** @brief Turn on the current Resource */
- void turnOn();
+ virtual void turnOn();
/** @brief Turn off the current Resource */
- void turnOff();
-
- /** @brief Get the [state](\ref e_surf_resource_state_t) of the current Resource */
- virtual e_surf_resource_state_t getState();
- /** @brief Set the [state](\ref e_surf_resource_state_t) of the current Resource */
- virtual void setState(e_surf_resource_state_t state);
+ virtual void turnOff();
private:
const char *p_name;
Model *p_model;
- bool m_running;
- e_surf_resource_state_t m_stateCurrent;
-
+ bool m_isOn;
public: /* LMM */
/** @brief Get the lmm constraint associated to this Resource if it is part of a LMM component */
}
s_sg_platf_host_cbarg_t host = SG_PLATF_HOST_INITIALIZER;
memset(&host, 0, sizeof(host));
- host.initial_state = SURF_RESOURCE_ON;
+ host.initiallyOn = 1;
host.pstate = 0;
host.speed_scale = 1.0;
host.core_amount = 1;
s_sg_platf_link_cbarg_t link = SG_PLATF_LINK_INITIALIZER;
memset(&link, 0, sizeof(link));
- link.state = SURF_RESOURCE_ON;
+ link.initiallyOn = 1;
link.policy = SURF_LINK_FULLDUPLEX;
link.latency = cabinet->lat;
link.bandwidth = cabinet->bw;
//host.power_peak = cluster->power;
host.speed_scale = 1.0;
host.core_amount = cluster->core_amount;
- host.initial_state = SURF_RESOURCE_ON;
+ host.initiallyOn = 1;
host.coord = "";
sg_platf_new_host(&host);
xbt_dynar_free(&host.speed_peak);
link.id = tmp_link;
link.bandwidth = cluster->loopback_bw;
link.latency = cluster->loopback_lat;
- link.state = SURF_RESOURCE_ON;
+ link.initiallyOn = 1;
link.policy = SURF_LINK_FATPIPE;
sg_platf_new_link(&link);
info_loop.link_up = Link::byName(tmp_link);
link.id = tmp_link;
link.bandwidth = cluster->limiter_link;
link.latency = 0;
- link.state = SURF_RESOURCE_ON;
+ link.initiallyOn = 1;
link.policy = SURF_LINK_SHARED;
sg_platf_new_link(&link);
info_lim.link_up = Link::byName(tmp_link);
link.id = link_backbone;
link.bandwidth = cluster->bb_bw;
link.latency = cluster->bb_lat;
- link.state = SURF_RESOURCE_ON;
+ link.initiallyOn = 1;
link.policy = cluster->bb_sharing_policy;
sg_platf_new_link(&link);
XBT_DEBUG("<host\tid=\"%s\"\tpower=\"%f\"/>", host_id, peer->speed);
s_sg_platf_host_cbarg_t host = SG_PLATF_HOST_INITIALIZER;
memset(&host, 0, sizeof(host));
- host.initial_state = SURF_RESOURCE_ON;
+ host.initiallyOn = 1;
host.id = host_id;
host.speed_peak = xbt_dynar_new(sizeof(double), NULL);
s_sg_platf_link_cbarg_t link = SG_PLATF_LINK_INITIALIZER;
memset(&link, 0, sizeof(link));
- link.state = SURF_RESOURCE_ON;
+ link.initiallyOn = 1;
link.policy = SURF_LINK_SHARED;
link.latency = peer->lat;
link.id = link_id;
link.bandwidth = cluster->bw;
link.latency = cluster->lat;
- link.state = SURF_RESOURCE_ON;
+ link.initiallyOn = 1;
link.policy = cluster->sharing_policy;
sg_platf_new_link(&link);
memset(&linkTemplate, 0, sizeof(linkTemplate));
linkTemplate.bandwidth = cluster->limiter_link;
linkTemplate.latency = 0;
- linkTemplate.state = SURF_RESOURCE_ON;
+ linkTemplate.initiallyOn = 1;
linkTemplate.policy = SURF_LINK_SHARED;
linkTemplate.id = bprintf("limiter_%d", id);
sg_platf_new_link(&linkTemplate);
memset(&linkTemplate, 0, sizeof(linkTemplate));
linkTemplate.bandwidth = cluster->loopback_bw;
linkTemplate.latency = cluster->loopback_lat;
- linkTemplate.state = SURF_RESOURCE_ON;
+ linkTemplate.initiallyOn = 1;
linkTemplate.policy = SURF_LINK_FATPIPE;
linkTemplate.id = bprintf("loopback_%d", id);
sg_platf_new_link(&linkTemplate);
memset(&linkTemplate, 0, sizeof(linkTemplate));
linkTemplate.bandwidth = cluster->bw;
linkTemplate.latency = cluster->lat;
- linkTemplate.state = SURF_RESOURCE_ON;
+ linkTemplate.initiallyOn = 1;
linkTemplate.policy = cluster->sharing_policy; // sthg to do with that ?
linkTemplate.id = bprintf("link_from_%d_to_%d_%d", downNode->id, upNode->id,
uniqueId);
memset(&link, 0, sizeof(link));
current_dimension = xbt_dynar_get_as(p_dimensions, j, int);
neighbour_rank_id = ( ((int) rank / dim_product) % current_dimension == current_dimension-1) ? rank - (current_dimension-1)*dim_product : rank + dim_product;
- //name of neighbour is not right for non contiguous cluster radicals (as id != rank in this case)
+ //name of neighbor is not right for non contiguous cluster radicals (as id != rank in this case)
link_id = bprintf("%s_link_from_%i_to_%i", cluster->id, id, neighbour_rank_id);
link.id = link_id;
link.bandwidth = cluster->bw;
link.latency = cluster->lat;
- link.state = SURF_RESOURCE_ON;
+ link.initiallyOn = 1;
link.policy = cluster->sharing_policy;
sg_platf_new_link(&link);
s_surf_parsing_link_up_down_t info;
xbt_assert((A_surfxml_host_state == A_surfxml_host_state_ON) ||
(A_surfxml_host_state == A_surfxml_host_state_OFF), "Invalid state");
if (A_surfxml_host_state == A_surfxml_host_state_ON)
- host.initial_state = SURF_RESOURCE_ON;
+ host.initiallyOn = 1;
if (A_surfxml_host_state == A_surfxml_host_state_OFF)
- host.initial_state = SURF_RESOURCE_OFF;
+ host.initiallyOn = 1;
host.coord = A_surfxml_host_coordinates;
sg_platf_new_host(&host);
switch (A_surfxml_link_state) {
case A_surfxml_link_state_ON:
- link.state = SURF_RESOURCE_ON;
+ link.initiallyOn = 1;
break;
case A_surfxml_link_state_OFF:
- link.state = SURF_RESOURCE_OFF;
+ link.initiallyOn = 0;
break;
default:
surf_parse_error("invalid state for link %s", link.id);
link.id = A_surfxml_backbone_id;
link.bandwidth = surf_parse_get_bandwidth(A_surfxml_backbone_bandwidth);
link.latency = surf_parse_get_time(A_surfxml_backbone_latency);
- link.state = SURF_RESOURCE_ON;
+ link.initiallyOn = 1;
link.policy = SURF_LINK_SHARED;
sg_platf_new_link(&link);
*/
tmgr_trace_t tmgr_trace_generator_state(const char *id,
probabilist_event_generator_t date_generator,
- e_surf_resource_state_t first_event_value)
+ int first_event_hostIsOn)
{
tmgr_trace_t trace = NULL;
trace->s_probabilist.event_generator[0] = date_generator;
trace->s_probabilist.event_generator[1] = date_generator;
trace->s_probabilist.is_state_trace = 1;
- trace->s_probabilist.next_event = (first_event_value==SURF_RESOURCE_ON ? 1 : 0);
+ trace->s_probabilist.next_event = first_event_hostIsOn;
return trace;
}
tmgr_trace_t tmgr_trace_generator_avail_unavail(const char *id,
probabilist_event_generator_t avail_duration_generator,
probabilist_event_generator_t unavail_duration_generator,
- e_surf_resource_state_t first_event_value)
+ int first_event_hostIsOn)
{
tmgr_trace_t trace = NULL;
trace->s_probabilist.event_generator[0] = unavail_duration_generator;
trace->s_probabilist.event_generator[1] = avail_duration_generator;
trace->s_probabilist.is_state_trace = 1;
- trace->s_probabilist.next_event = (first_event_value==SURF_RESOURCE_ON ? 1 : 0);
+ trace->s_probabilist.next_event = first_event_hostIsOn;
return trace;
}
* Resource *
************/
-VirtualMachine::VirtualMachine(Model *model, const char *name, xbt_dict_t props,simgrid::Host *hostPM)
+VirtualMachine::VirtualMachine(Model *model, const char *name, xbt_dict_t props, simgrid::Host *hostPM)
: Host(model, name, props, NULL, NULL, NULL)
, p_hostPM(hostPM)
{
{
VMDestructedCallbacks(this);
VMModel::ws_vms.erase(VMModel::vm_list_t::s_iterator_to(*this));
+ /* Free the cpu_action of the VM. */
+ XBT_ATTRIB_UNUSED int ret = p_action->unref();
+ xbt_assert(ret == 1, "Bug: some resource still remains");
}
-void VirtualMachine::setState(e_surf_resource_state_t state){
- Resource::setState(state);
- VMStateChangedCallbacks(this);
+e_surf_vm_state_t VirtualMachine::getState() {
+ return p_vm_state;
+}
+
+void VirtualMachine::setState(e_surf_vm_state_t state) {
+ p_vm_state = state;
+}
+void VirtualMachine::turnOn() {
+ if (isOff()) {
+ Resource::turnOn();
+ VMStateChangedCallbacks(this);
+ }
+}
+void VirtualMachine::turnOff() {
+ if (isOn()) {
+ Resource::turnOff();
+ VMStateChangedCallbacks(this);
+ }
}
/** @brief returns the physical machine on which the VM is running **/
/** @brief Destructor */
~VirtualMachine();
- void setState(e_surf_resource_state_t state) override;
-
/** @brief Suspend the VM */
virtual void suspend()=0;
/* The vm object of the lower layer */
CpuAction *p_action;
simgrid::Host *p_hostPM;
- e_surf_vm_state_t p_currentState;
+
+ void turnOn() override;
+ void turnOff() override;
+
+public:
+ e_surf_vm_state_t getState();
+ void setState(e_surf_vm_state_t state);
+protected:
+ e_surf_vm_state_t p_vm_state = SURF_VM_STATE_CREATED;
+
+
public:
boost::intrusive::list_member_hook<> vm_hook;
};
sg_host_t host_VM = sg_host_by_name_or_create(name);
host_VM->p_netcard = p_netElm;
- p_currentState = SURF_VM_STATE_CREATED;
+ p_vm_state = SURF_VM_STATE_CREATED;
// //// CPU RELATED STUFF ////
// Roughly, create a vcpu resource by using the values of the sub_cpu one.
1, // host->power_scale,
NULL, // host->power_trace,
1, // host->core_amount,
- SURF_RESOURCE_ON, // host->initial_state,
+ 1/*ON*/, // host->initiallyOn,
NULL); // host->state_trace,
/* We create cpu_action corresponding to a VM process on the host operating system. */
XBT_INFO("Create VM(%s)@PM(%s) with %ld mounted disks", name, p_hostPM->getName().c_str(), xbt_dynar_length(p_storage));
}
-/*
- * A physical host does not disappear in the current SimGrid code, but a VM may
- * disappear during a simulation.
- */
-VMHL13::~VMHL13()
-{
- /* Free the cpu_action of the VM. */
- XBT_ATTRIB_UNUSED int ret = p_action->unref();
- xbt_assert(ret == 1, "Bug: some resource still remains");
-}
-
-void VMHL13::updateState(tmgr_trace_event_t /*event_type*/, double /*value*/, double /*date*/) {
- THROW_IMPOSSIBLE; /* This model does not implement parallel tasks */
-}
-
-bool VMHL13::isUsed() {
- THROW_IMPOSSIBLE; /* This model does not implement parallel tasks */
- return -1;
-}
-
-e_surf_resource_state_t VMHL13::getState()
-{
- return (e_surf_resource_state_t) p_currentState;
-}
-
-void VMHL13::setState(e_surf_resource_state_t state)
-{
- p_currentState = (e_surf_vm_state_t) state;
-}
-
void VMHL13::suspend()
{
p_action->suspend();
- p_currentState = SURF_VM_STATE_SUSPENDED;
+ p_vm_state = SURF_VM_STATE_SUSPENDED;
}
void VMHL13::resume()
{
p_action->resume();
- p_currentState = SURF_VM_STATE_RUNNING;
+ p_vm_state = SURF_VM_STATE_RUNNING;
}
void VMHL13::save()
{
- p_currentState = SURF_VM_STATE_SAVING;
+ p_vm_state = SURF_VM_STATE_SAVING;
/* FIXME: do something here */
p_action->suspend();
- p_currentState = SURF_VM_STATE_SAVED;
+ p_vm_state = SURF_VM_STATE_SAVED;
}
void VMHL13::restore()
{
- p_currentState = SURF_VM_STATE_RESTORING;
+ p_vm_state = SURF_VM_STATE_RESTORING;
/* FIXME: do something here */
p_action->resume();
- p_currentState = SURF_VM_STATE_RUNNING;
+ p_vm_state = SURF_VM_STATE_RUNNING;
}
/*
class VMHL13 : public VirtualMachine {
public:
VMHL13(VMModel *model, const char* name, xbt_dict_t props, sg_host_t host_PM);
- ~VMHL13();
+ ~VMHL13() {}
void suspend() override;
void resume() override;
void migrate(sg_host_t ind_dst_pm) override;
- e_surf_resource_state_t getState() override;
- void setState(e_surf_resource_state_t state) override;
-
void setBound(double bound);
void setAffinity(Cpu *cpu, unsigned long mask);
-
- //FIXME: remove
- void updateState(tmgr_trace_event_t event_type, double value, double date);
- bool isUsed();
};
/**********