From b4b40408881fd9dfc49a7802d4a83689c506b36b Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Fri, 25 Dec 2015 19:31:14 +0100 Subject: [PATCH] Make the energy plugin usable with ptask (but not DVFS) (fix #27) - Move the DVFS mechanism higher in the CPU hierarchy - Remove all static_casts to CpuCas01 in energy plugin - Make sure that ptaskL07 can execute sequential tasks DVFS is still not working: the speedPeak changes have no impact on ptask actions. I don't understand maxmin enough and need the help of @alegrand, sorry. --- .../energy/consumption/energy_consumption.c | 6 +- .../consumption/energy_consumption.tesh | 29 +++++++- src/simix/smx_host.cpp | 6 +- src/surf/cpu_cas01.cpp | 48 +----------- src/surf/cpu_cas01.hpp | 10 +-- src/surf/cpu_interface.cpp | 73 +++++++++++++++++-- src/surf/cpu_interface.hpp | 23 ++++-- src/surf/cpu_ti.cpp | 2 +- src/surf/host_ptask_L07.cpp | 55 ++++++++++---- src/surf/host_ptask_L07.hpp | 20 ++--- src/surf/plugins/energy.cpp | 13 ++-- src/surf/surf_c_bindings.cpp | 6 +- src/surf/surf_interface.hpp | 2 +- 13 files changed, 176 insertions(+), 117 deletions(-) diff --git a/examples/msg/energy/consumption/energy_consumption.c b/examples/msg/energy/consumption/energy_consumption.c index 8f928aeba3..e058370b19 100644 --- a/examples/msg/energy/consumption/energy_consumption.c +++ b/examples/msg/energy/consumption/energy_consumption.c @@ -41,8 +41,8 @@ int dvfs(int argc, char *argv[]) // Run a task start = MSG_get_clock(); - XBT_INFO("Run a task for 100E6 flops"); task1 = MSG_task_create ("t1", 100E6, 0, NULL); + XBT_INFO("Run a task of %.0E flops",MSG_task_get_flops_amount(task1)); MSG_task_execute (task1); MSG_task_destroy(task1); XBT_INFO("Task done (duration: %.2f s). Current peak speed=%.0E flop/s; Current consumption: from %.0fW to %.0fW depending on load; Energy dissipated=%.0f J", @@ -54,15 +54,15 @@ int dvfs(int argc, char *argv[]) // ========= Change power peak ========= int pstate=2; MSG_host_set_pstate(host, pstate); - XBT_INFO("========= Requesting pstate %d (speed should be of %.2f flop/s and is of %.2f flop/s)", + XBT_INFO("========= Requesting pstate %d (speed should be of %.0E flop/s and is of %.0E flop/s)", pstate, MSG_host_get_power_peak_at(host, pstate), MSG_host_get_current_power_peak(host)); // Run a second task start = MSG_get_clock(); - XBT_INFO("Run a task for 100E6 flops"); task1 = MSG_task_create ("t2", 100E6, 0, NULL); + XBT_INFO("Run a task of %.0E flops",MSG_task_get_flops_amount(task1)); MSG_task_execute (task1); MSG_task_destroy(task1); XBT_INFO("Task done (duration: %.2f s). Current peak speed=%.0E flop/s; Energy dissipated=%.0f J", diff --git a/examples/msg/energy/consumption/energy_consumption.tesh b/examples/msg/energy/consumption/energy_consumption.tesh index 017188af41..d7cc2eefdf 100644 --- a/examples/msg/energy/consumption/energy_consumption.tesh +++ b/examples/msg/energy/consumption/energy_consumption.tesh @@ -8,10 +8,33 @@ $ $SG_TEST_EXENV energy/consumption/energy_consumption$EXEEXT ${srcdir:=.}/../pl > [ 0.000000] (1:dvfs_test@MyHost1) Initial peak speed=1E+08 flop/s; Energy dissipated =0E+00 J > [ 0.000000] (1:dvfs_test@MyHost1) Sleep for 10 seconds > [ 10.000000] (1:dvfs_test@MyHost1) Done sleeping (duration: 10.00 s). Current peak speed=1E+08; Energy dissipated=1000.00 J -> [ 10.000000] (1:dvfs_test@MyHost1) Run a task for 100E6 flops +> [ 10.000000] (1:dvfs_test@MyHost1) Run a task of 1E+08 flops > [ 11.000000] (1:dvfs_test@MyHost1) Task done (duration: 1.00 s). Current peak speed=1E+08 flop/s; Current consumption: from 100W to 200W depending on load; Energy dissipated=1200 J -> [ 11.000000] (1:dvfs_test@MyHost1) ========= Requesting pstate 2 (speed should be of 20000000.00 flop/s and is of 20000000.00 flop/s) -> [ 11.000000] (1:dvfs_test@MyHost1) Run a task for 100E6 flops +> [ 11.000000] (1:dvfs_test@MyHost1) ========= Requesting pstate 2 (speed should be of 2E+07 flop/s and is of 2E+07 flop/s) +> [ 11.000000] (1:dvfs_test@MyHost1) Run a task of 1E+08 flops +> [ 16.000000] (1:dvfs_test@MyHost1) Task done (duration: 5.00 s). Current peak speed=2E+07 flop/s; Energy dissipated=1950 J +> [ 16.000000] (1:dvfs_test@MyHost1) Sleep for 4 seconds +> [ 20.000000] (1:dvfs_test@MyHost1) Done sleeping (duration: 4.00 s). Current peak speed=2E+07 flop/s; Energy dissipated=2310 J +> [ 20.000000] (1:dvfs_test@MyHost1) Turning MyHost2 off, and sleeping another 10 seconds. MyHost2 dissipated 2000 J so far. +> [ 30.000000] (0:@) Total simulation time: 30.00 +> [ 30.000000] (0:@) Total energy of host MyHost1: 3210.000000 Joules +> [ 30.000000] (0:@) Total energy of host MyHost2: 2100.000000 Joules +> [ 30.000000] (0:@) Total energy of host MyHost3: 3000.000000 Joules +> [ 30.000000] (1:dvfs_test@MyHost1) Done sleeping (duration: 10.00 s). Current peak speed=2E+07 flop/s; Energy dissipated=3210 J + +p Test the same with the ptask model + +$ $SG_TEST_EXENV energy/consumption/energy_consumption$EXEEXT ${srcdir:=.}/../platforms/energy_platform.xml ${srcdir:=.}/energy/consumption/deployment_consumption.xml --cfg=host/model:ptask_L07 "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" +> [ 0.000000] (0:@) Configuration change: Set 'host/model' to 'ptask_L07' +> [ 0.000000] (0:@) Switching to the L07 model to handle parallel tasks. +> [ 0.000000] (1:dvfs_test@MyHost1) Energetic profile: 100.0:200.0, 93.0:170.0, 90.0:150.0 +> [ 0.000000] (1:dvfs_test@MyHost1) Initial peak speed=1E+08 flop/s; Energy dissipated =0E+00 J +> [ 0.000000] (1:dvfs_test@MyHost1) Sleep for 10 seconds +> [ 10.000000] (1:dvfs_test@MyHost1) Done sleeping (duration: 10.00 s). Current peak speed=1E+08; Energy dissipated=1000.00 J +> [ 10.000000] (1:dvfs_test@MyHost1) Run a task of 1E+08 flops +> [ 11.000000] (1:dvfs_test@MyHost1) Task done (duration: 1.00 s). Current peak speed=1E+08 flop/s; Current consumption: from 100W to 200W depending on load; Energy dissipated=1200 J +> [ 11.000000] (1:dvfs_test@MyHost1) ========= Requesting pstate 2 (speed should be of 2E+07 flop/s and is of 2E+07 flop/s) +> [ 11.000000] (1:dvfs_test@MyHost1) Run a task of 1E+08 flops > [ 16.000000] (1:dvfs_test@MyHost1) Task done (duration: 5.00 s). Current peak speed=2E+07 flop/s; Energy dissipated=1950 J > [ 16.000000] (1:dvfs_test@MyHost1) Sleep for 4 seconds > [ 20.000000] (1:dvfs_test@MyHost1) Done sleeping (duration: 4.00 s). Current peak speed=2E+07 flop/s; Energy dissipated=2310 J diff --git a/src/simix/smx_host.cpp b/src/simix/smx_host.cpp index dce8607d21..92b2b5b17d 100644 --- a/src/simix/smx_host.cpp +++ b/src/simix/smx_host.cpp @@ -324,7 +324,11 @@ smx_synchro_t SIMIX_process_execute(smx_process_t issuer, const char *name, /* Note (hypervisor): for multicore, the bound value being passed to the * surf layer should not be zero (i.e., unlimited). It should be the - * capacity of a CPU core. */ + * capacity of a CPU core. + * + * FIXME: this should probably not be part of Simix but of Surf directly. + * That bound is part of the performance model, not of the synchronization + */ if (bound == 0) surf_cpu_action_set_bound(synchro->execution.surf_exec, sg_host_get_speed(issuer->host)); else diff --git a/src/surf/cpu_cas01.cpp b/src/surf/cpu_cas01.cpp index c767a73002..014f9dafe5 100644 --- a/src/surf/cpu_cas01.cpp +++ b/src/surf/cpu_cas01.cpp @@ -156,21 +156,12 @@ CpuCas01::CpuCas01(CpuCas01Model *model, simgrid::Host *host, xbt_dynar_t speedP int pstate, double speedScale, tmgr_trace_t speedTrace, int core, e_surf_resource_state_t stateInitial, tmgr_trace_t stateTrace) : Cpu(model, host, - lmm_constraint_new(model->getMaxminSystem(), this, core * speedScale * xbt_dynar_get_as(speedPeak, pstate, double)), - core, xbt_dynar_get_as(speedPeak, pstate, double), speedScale, + 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) { p_speedEvent = NULL; - // Copy the power peak array: - p_speedPeakList = xbt_dynar_new(sizeof(double), nullptr); - unsigned long n = xbt_dynar_length(speedPeak); - for (unsigned long i = 0; i != n; ++i) { - double value = xbt_dynar_get_as(speedPeak, i, double); - xbt_dynar_push(p_speedPeakList, &value); - } - - m_pstate = pstate; - XBT_DEBUG("CPU create: peak=%f, pstate=%d", m_speedPeak, m_pstate); m_core = core; @@ -201,11 +192,6 @@ xbt_dynar_t CpuCas01::getSpeedPeakList(){ return p_speedPeakList; } -int CpuCas01::getPState() -{ - return m_pstate; -} - bool CpuCas01::isUsed() { return lmm_constraint_used(getModel()->getMaxminSystem(), getConstraint()); @@ -322,34 +308,6 @@ double CpuCas01::getCurrentPowerPeak() return m_speedPeak; } -double CpuCas01::getPowerPeakAt(int pstate_index) -{ - xbt_dynar_t plist = p_speedPeakList; - 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); -} - -int CpuCas01::getNbPstates() -{ - return xbt_dynar_length(p_speedPeakList); -} - -void CpuCas01::setPstate(int pstate_index) -{ - xbt_dynar_t plist = p_speedPeakList; - xbt_assert((pstate_index <= (int)xbt_dynar_length(plist)), "Invalid parameters (pstate index out of bounds)"); - - double new_pstate = xbt_dynar_get_as(plist, pstate_index, double); - m_pstate = pstate_index; - m_speedPeak = new_pstate; -} - -int CpuCas01::getPstate() -{ - return m_pstate; -} - /********** * Action * **********/ diff --git a/src/surf/cpu_cas01.hpp b/src/surf/cpu_cas01.hpp index 66dd3f7072..294b8d7b60 100644 --- a/src/surf/cpu_cas01.hpp +++ b/src/surf/cpu_cas01.hpp @@ -56,22 +56,14 @@ public: CpuAction *sleep(double duration); double getCurrentPowerPeak(); - double getPowerPeakAt(int pstate_index); - int getNbPstates(); - void setPstate(int pstate_index); - int getPstate(); - bool isUsed(); + bool isUsed() override; void setStateEvent(tmgr_trace_event_t stateEvent); void setPowerEvent(tmgr_trace_event_t stateEvent); xbt_dynar_t getSpeedPeakList(); - int getPState(); - private: tmgr_trace_event_t p_stateEvent; tmgr_trace_event_t p_speedEvent; - xbt_dynar_t p_speedPeakList; /*< List of supported CPU capacities (pstate related) */ - int m_pstate; /*< Current pstate (index in the speedPeakList)*/ }; /********** diff --git a/src/surf/cpu_interface.cpp b/src/surf/cpu_interface.cpp index 0bb5ed6219..a935630d10 100644 --- a/src/surf/cpu_interface.cpp +++ b/src/surf/cpu_interface.cpp @@ -4,6 +4,7 @@ /* 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 #include "cpu_interface.hpp" #include "plugins/energy.hpp" @@ -144,7 +145,8 @@ Cpu::Cpu() Cpu::Cpu(Model *model, simgrid::Host *host, - int core, double speedPeak, double speedScale, + xbt_dynar_t speedPeakList, int pstate, + int core, double speedPeak, double speedScale, e_surf_resource_state_t stateInitial) : Resource(model, host->getName().c_str(), stateInitial) , m_core(core) @@ -153,10 +155,21 @@ Cpu::Cpu(Model *model, simgrid::Host *host, , m_host(host) { host->extension_set(Cpu::EXTENSION_ID, this); + + // Copy the power peak array: + p_speedPeakList = xbt_dynar_new(sizeof(double), nullptr); + unsigned long n = xbt_dynar_length(speedPeakList); + for (unsigned long i = 0; i != n; ++i) { + double value = xbt_dynar_get_as(speedPeakList, i, double); + xbt_dynar_push(p_speedPeakList, &value); + } + + m_pstate = pstate; } -Cpu::Cpu(Model *model, simgrid::Host *host, - lmm_constraint_t constraint, int core, double speedPeak, +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) , m_core(core) @@ -165,6 +178,17 @@ Cpu::Cpu(Model *model, simgrid::Host *host, , m_host(host) { host->extension_set(Cpu::EXTENSION_ID, this); + + // Copy the power peak array: + p_speedPeakList = xbt_dynar_new(sizeof(double), nullptr); + unsigned long n = xbt_dynar_length(speedPeakList); + for (unsigned long i = 0; i != n; ++i) { + double value = xbt_dynar_get_as(speedPeakList, i, double); + xbt_dynar_push(p_speedPeakList, &value); + } + + m_pstate = pstate; + /* Currently, we assume that a VM does not have a multicore CPU. */ if (core > 1) xbt_assert(model == surf_cpu_model_pm); @@ -182,14 +206,18 @@ Cpu::Cpu(Model *model, simgrid::Host *host, } } -Cpu::Cpu(Model *model, simgrid::Host *host, - lmm_constraint_t constraint, int core, double speedPeak, double speedScale) -: Cpu(model, host, constraint, core, speedPeak, speedScale, SURF_RESOURCE_ON) -{} +Cpu::Cpu(Model *model, simgrid::Host *host, lmm_constraint_t constraint, + xbt_dynar_t speedPeakList, int pstate, + int core, double speedPeak, double speedScale) +: Cpu(model, host, constraint, speedPeakList, pstate, core, speedPeak, speedScale, SURF_RESOURCE_ON) +{ + xbt_assert(0,"FIXME: this constructor could be removed"); +} Cpu::Cpu(Model *model, simgrid::Host *host, + xbt_dynar_t speedPeakList, int pstate, int core, double speedPeak, double speedScale) -: Cpu(model, host, core, speedPeak, speedScale, SURF_RESOURCE_ON) +: Cpu(model, host, speedPeakList, pstate, core, speedPeak, speedScale, SURF_RESOURCE_ON) {} Cpu::~Cpu() @@ -209,6 +237,35 @@ double Cpu::getCurrentPowerPeak() return m_speedPeak; } +int Cpu::getNbPStates() +{ + return xbt_dynar_length(p_speedPeakList); +} + +void Cpu::setPState(int pstate_index) +{ + xbt_dynar_t plist = p_speedPeakList; + xbt_assert(pstate_index <= (int)xbt_dynar_length(plist), + "Invalid parameters for CPU %s (pstate %d > length of pstates %d)", getName(), pstate_index, (int)xbt_dynar_length(plist)); + + double new_peak_speed = xbt_dynar_get_as(plist, pstate_index, double); + m_pstate = pstate_index; + m_speedPeak = new_peak_speed; +} + +int Cpu::getPState() +{ + return m_pstate; +} + +double Cpu::getPowerPeakAt(int pstate_index) +{ + xbt_dynar_t plist = p_speedPeakList; + 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); +} + double Cpu::getSpeed(double load) { return load * m_speedPeak; diff --git a/src/surf/cpu_interface.hpp b/src/surf/cpu_interface.hpp index 4f1b156247..a393754448 100644 --- a/src/surf/cpu_interface.hpp +++ b/src/surf/cpu_interface.hpp @@ -89,8 +89,9 @@ public: * @param speedScale The speed scale of this Cpu in [0;1] (available amount) * @param stateInitial whether it is created running or crashed */ - Cpu(simgrid::surf::Model *model, simgrid::Host *host, - lmm_constraint_t constraint, int core, double speedPeak, double speedScale, + 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); /** @@ -104,12 +105,15 @@ public: * @param stateInitial whether it is created running or crashed */ 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); + Cpu(simgrid::surf::Model *model, simgrid::Host *host, lmm_constraint_t constraint, + xbt_dynar_t speedPeakList, int pstate, + int core, double speedPeak, double speedScale); Cpu(simgrid::surf::Model *model, simgrid::Host *host, - lmm_constraint_t constraint, int core, double speedPeak, double speedScale); - Cpu(simgrid::surf::Model *model, simgrid::Host *host, + xbt_dynar_t speedPeakList, int pstate, int core, double speedPeak, double speedScale); ~Cpu(); @@ -142,11 +146,11 @@ public: /** @brief Get the current Cpu power peak */ virtual double getCurrentPowerPeak(); - virtual double getPowerPeakAt(int pstate_index)=0; + virtual double getPowerPeakAt(int pstate_index); - virtual int getNbPstates()=0; - virtual void setPstate(int pstate_index)=0; - virtual int getPstate()=0; + virtual int getNbPStates(); + virtual void setPState(int pstate_index); + virtual int getPState(); void addTraces(void); simgrid::Host* getHost() { return m_host; } @@ -157,6 +161,9 @@ public: double m_speedScale; /*< Percentage of CPU available according to the trace, in [O,1] */ simgrid::Host* m_host; + xbt_dynar_t p_speedPeakList = NULL; /*< List of supported CPU capacities (pstate related) */ + int m_pstate = 0; /*< Current pstate (index in the speedPeakList)*/ + /* Note (hypervisor): */ lmm_constraint_t *p_constraintCore=NULL; void **p_constraintCoreId=NULL; diff --git a/src/surf/cpu_ti.cpp b/src/surf/cpu_ti.cpp index a72268a2f6..6ea015287d 100644 --- a/src/surf/cpu_ti.cpp +++ b/src/surf/cpu_ti.cpp @@ -551,7 +551,7 @@ void CpuTiModel::addTraces() 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, core, 0, speedScale, stateInitial) + : Cpu(model, host, NULL, pstate, core, 0, speedScale, stateInitial) { p_speedEvent = NULL; m_speedScale = speedScale; diff --git a/src/surf/host_ptask_L07.cpp b/src/surf/host_ptask_L07.cpp index 700aa0c44f..dcf61d6122 100644 --- a/src/surf/host_ptask_L07.cpp +++ b/src/surf/host_ptask_L07.cpp @@ -53,9 +53,10 @@ namespace surf { HostL07Model::HostL07Model() : HostModel() { if (!ptask_maxmin_system) ptask_maxmin_system = lmm_system_new(1); + p_maxminSystem = ptask_maxmin_system; surf_host_model = NULL; - surf_network_model = new NetworkL07Model(this); - surf_cpu_model_pm = new CpuL07Model(this); + surf_network_model = new NetworkL07Model(this,ptask_maxmin_system); + surf_cpu_model_pm = new CpuL07Model(this,ptask_maxmin_system); routing_model_create(surf_network_model->createLink("__loopback__", 498000000, NULL, @@ -71,12 +72,32 @@ HostL07Model::~HostL07Model() { delete surf_network_model; ptask_host_count = 0; - if (ptask_maxmin_system) { - lmm_system_free(ptask_maxmin_system); - ptask_maxmin_system = NULL; - } + ptask_maxmin_system = NULL; // freed as part of ~Model (it's also stored as p_maxminSystem) +} + +CpuL07Model::CpuL07Model(HostL07Model *hmodel,lmm_system_t sys) + : CpuModel() + , p_hostModel(hmodel) + { + p_maxminSystem = sys; + } +CpuL07Model::~CpuL07Model() { + surf_cpu_model_pm = NULL; + p_maxminSystem = NULL; // Avoid multi-free +} +NetworkL07Model::NetworkL07Model(HostL07Model *hmodel, lmm_system_t sys) + : NetworkModel() + , p_hostModel(hmodel) + { + p_maxminSystem = sys; + } +NetworkL07Model::~NetworkL07Model() +{ + surf_network_model = NULL; + p_maxminSystem = NULL; // Avoid multi-free } + double HostL07Model::shareResources(double /*now*/) { L07Action *action; @@ -180,7 +201,7 @@ Action *HostL07Model::executeParallelTask(int host_nb, L07Action *action = new L07Action(this, 1, 0); unsigned int cpt; int nb_link = 0; - int nb_host = 0; + int nb_used_host = 0; /* Only the hosts with something to compute (>0 flops) are counted) */ double latency = 0.0; action->p_edgeList->reserve(host_nb); @@ -220,7 +241,7 @@ Action *HostL07Model::executeParallelTask(int host_nb, for (int i = 0; i < host_nb; i++) if (flops_amount[i] > 0) - nb_host++; + nb_used_host++; XBT_DEBUG("Creating a parallel task (%p) with %d cpus and %d links.", action, host_nb, nb_link); @@ -262,7 +283,7 @@ Action *HostL07Model::executeParallelTask(int host_nb, } } - if (nb_link + nb_host == 0) { + if (nb_link + nb_used_host == 0) { action->setCost(1.0); action->setRemains(0.0); } @@ -289,14 +310,13 @@ Action *NetworkL07Model::communicate(RoutingEdge *src, RoutingEdge *dst, return res; } -Cpu *CpuL07Model::createCpu(simgrid::Host *host, xbt_dynar_t powerPeak, +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, tmgr_trace_t state_trace) { - double power_initial = xbt_dynar_get_as(powerPeak, pstate, double); - CpuL07 *cpu = new CpuL07(this, host, power_initial, power_scale, power_trace, + CpuL07 *cpu = new CpuL07(this, host, powerPeakList, pstate, power_scale, power_trace, core, state_initial, state_trace); return cpu; } @@ -387,13 +407,16 @@ void HostL07Model::addTraces() /************ * Resource * ************/ + CpuL07::CpuL07(CpuL07Model *model, simgrid::Host *host, - double speedInitial, double speedScale, tmgr_trace_t speedTrace, - int core, e_surf_resource_state_t state_initial, tmgr_trace_t state_trace) - : Cpu(model, host, lmm_constraint_new(ptask_maxmin_system, this, speedInitial * speedScale), - core, speedInitial, speedScale, state_initial) + 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) + : Cpu(model, host, speedPeakList, pstate, + core, xbt_dynar_get_as(speedPeakList,pstate,double), speedScale, state_initial) { xbt_assert(m_speedScale > 0, "Power has to be >0"); + p_constraint = lmm_constraint_new(ptask_maxmin_system, this, xbt_dynar_get_as(speedPeakList,pstate,double) * speedScale); if (speedTrace) p_speedEvent = tmgr_history_add_trace(history, speedTrace, 0.0, 0, this); diff --git a/src/surf/host_ptask_L07.hpp b/src/surf/host_ptask_L07.hpp index 5b8c107209..370dd71328 100644 --- a/src/surf/host_ptask_L07.hpp +++ b/src/surf/host_ptask_L07.hpp @@ -55,10 +55,10 @@ public: class CpuL07Model : public CpuModel { public: - CpuL07Model(HostL07Model *hmodel) : CpuModel() {p_hostModel = hmodel;}; - ~CpuL07Model() {surf_cpu_model_pm = NULL;}; + CpuL07Model(HostL07Model *hmodel,lmm_system_t sys); + ~CpuL07Model(); - Cpu *createCpu(simgrid::Host *host, xbt_dynar_t speedPeak, + 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, @@ -70,8 +70,8 @@ public: class NetworkL07Model : public NetworkModel { public: - NetworkL07Model(HostL07Model *hmodel) : NetworkModel() {p_hostModel = hmodel;}; - ~NetworkL07Model() {surf_network_model = NULL;}; + NetworkL07Model(HostL07Model *hmodel, lmm_system_t sys); + ~NetworkL07Model(); Link* createLink(const char *name, double bw_initial, tmgr_trace_t bw_trace, @@ -98,20 +98,14 @@ class CpuL07 : public Cpu { tmgr_trace_event_t p_stateEvent; tmgr_trace_event_t p_speedEvent; public: - CpuL07(CpuL07Model *model, simgrid::Host *host, - double power_scale, double power_initial, tmgr_trace_t power_trace, + 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); ~CpuL07(); bool isUsed() override; void updateState(tmgr_trace_event_t event_type, double value, double date) override; Action *execute(double size) override; Action *sleep(double duration) override; - - double getCurrentPowerPeak() override {THROW_UNIMPLEMENTED;}; - double getPowerPeakAt(int /*pstate_index*/) override {THROW_UNIMPLEMENTED;}; - int getNbPstates() override {THROW_UNIMPLEMENTED;}; - void setPstate(int /*pstate_index*/) override {THROW_UNIMPLEMENTED;}; - int getPstate() override {THROW_UNIMPLEMENTED;}; }; class LinkL07 : public Link { diff --git a/src/surf/plugins/energy.cpp b/src/surf/plugins/energy.cpp index 1ee70cfced..f8d89101fb 100644 --- a/src/surf/plugins/energy.cpp +++ b/src/surf/plugins/energy.cpp @@ -5,7 +5,7 @@ * under the terms of the license (GNU LGPL) which comes with this package. */ #include -#include +#include #include /** @addtogroup SURF_plugin_energy @@ -185,14 +185,14 @@ HostEnergy::~HostEnergy(){ double HostEnergy::getWattMinAt(int pstate) { xbt_dynar_t power_range_list = power_range_watts_list; xbt_assert(power_range_watts_list, "No power range properties specified for host %s", host->getName()); - xbt_dynar_t current_power_values = xbt_dynar_get_as(power_range_list, static_cast(host->p_cpu)->getPState(), xbt_dynar_t); + xbt_dynar_t current_power_values = xbt_dynar_get_as(power_range_list, host->p_cpu->getPState(), xbt_dynar_t); double min_power = xbt_dynar_get_as(current_power_values, 0, double); return min_power; } double HostEnergy::getWattMaxAt(int pstate) { xbt_dynar_t power_range_list = power_range_watts_list; xbt_assert(power_range_watts_list, "No power range properties specified for host %s", host->getName()); - xbt_dynar_t current_power_values = xbt_dynar_get_as(power_range_list, static_cast(host->p_cpu)->getPState(), xbt_dynar_t); + xbt_dynar_t current_power_values = xbt_dynar_get_as(power_range_list, host->p_cpu->getPState(), xbt_dynar_t); double max_power = xbt_dynar_get_as(current_power_values, 1, double); return max_power; } @@ -203,10 +203,11 @@ double HostEnergy::getCurrentWattsValue(double cpu_load) xbt_dynar_t power_range_list = power_range_watts_list; xbt_assert(power_range_watts_list, "No power range properties specified for host %s", host->getName()); + 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, - static_cast(host->p_cpu)->getPState(), - xbt_dynar_t); + 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 */ diff --git a/src/surf/surf_c_bindings.cpp b/src/surf/surf_c_bindings.cpp index c709ccac8c..5dc27ce46e 100644 --- a/src/surf/surf_c_bindings.cpp +++ b/src/surf/surf_c_bindings.cpp @@ -283,14 +283,14 @@ double surf_host_get_power_peak_at(sg_host_t host, int pstate_index){ } int surf_host_get_nb_pstates(sg_host_t host){ - return sg_host_surfcpu(host)->getNbPstates(); + return sg_host_surfcpu(host)->getNbPStates(); } void surf_host_set_pstate(sg_host_t host, int pstate_index){ - sg_host_surfcpu(host)->setPstate(pstate_index); + sg_host_surfcpu(host)->setPState(pstate_index); } int surf_host_get_pstate(sg_host_t host){ - return sg_host_surfcpu(host)->getPstate(); + return sg_host_surfcpu(host)->getPState(); } using simgrid::energy::HostEnergy; diff --git a/src/surf/surf_interface.hpp b/src/surf/surf_interface.hpp index 8599ee8ae4..0c16aaffb3 100644 --- a/src/surf/surf_interface.hpp +++ b/src/surf/surf_interface.hpp @@ -488,7 +488,7 @@ private: public: /* LMM */ /** @brief Get the lmm constraint associated to this Resource if it is part of a LMM component */ lmm_constraint_t getConstraint(); -private: +protected: lmm_constraint_t p_constraint; }; -- 2.20.1