From 4871b54f42ce85370d6acdbcb7e42bf75a63b389 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Paul=20B=C3=A9daride?= Date: Thu, 5 Dec 2013 13:08:11 +0100 Subject: [PATCH] Restructure surf++ workstation vmworkstation --- buildtools/Cmake/DefinePackages.cmake | 16 +- src/surf/cpu_cas01.cpp | 1 - src/surf/cpu_interface.hpp | 8 +- src/surf/network_interface.hpp | 2 +- src/surf/storage_interface.hpp | 2 +- src/surf/surf_c_bindings.cpp | 16 +- src/surf/{surf.cpp => surf_interface.cpp} | 34 +- src/surf/{surf.hpp => surf_interface.hpp} | 2 +- src/surf/surf_routing.hpp | 2 +- src/surf/surf_routing_private.hpp | 2 +- src/surf/vm_workstation.hpp | 133 ----- ...orkstation.cpp => vm_workstation_hl13.cpp} | 99 ++-- src/surf/vm_workstation_hl13.hpp | 89 ++++ src/surf/vm_workstation_interface.cpp | 85 ++++ src/surf/vm_workstation_interface.hpp | 80 +++ src/surf/workstation.cpp | 455 ------------------ src/surf/workstation.hpp | 134 ------ src/surf/workstation_clm03.cpp | 187 +++++++ src/surf/workstation_clm03.hpp | 80 +++ src/surf/workstation_interface.cpp | 315 ++++++++++++ src/surf/workstation_interface.hpp | 124 +++++ src/surf/workstation_ptask_L07.cpp | 12 +- src/surf/workstation_ptask_L07.hpp | 14 +- 23 files changed, 1069 insertions(+), 823 deletions(-) rename src/surf/{surf.cpp => surf_interface.cpp} (98%) rename src/surf/{surf.hpp => surf_interface.hpp} (99%) delete mode 100644 src/surf/vm_workstation.hpp rename src/surf/{vm_workstation.cpp => vm_workstation_hl13.cpp} (82%) create mode 100644 src/surf/vm_workstation_hl13.hpp create mode 100644 src/surf/vm_workstation_interface.cpp create mode 100644 src/surf/vm_workstation_interface.hpp delete mode 100644 src/surf/workstation.cpp delete mode 100644 src/surf/workstation.hpp create mode 100644 src/surf/workstation_clm03.cpp create mode 100644 src/surf/workstation_clm03.hpp create mode 100644 src/surf/workstation_interface.cpp create mode 100644 src/surf/workstation_interface.hpp diff --git a/buildtools/Cmake/DefinePackages.cmake b/buildtools/Cmake/DefinePackages.cmake index 853db2294e..5239989043 100644 --- a/buildtools/Cmake/DefinePackages.cmake +++ b/buildtools/Cmake/DefinePackages.cmake @@ -62,7 +62,7 @@ set(EXTRA_DIST src/surf/simgrid_dtd.c src/surf/storage_interface.hpp src/surf/storage_n11.hpp - src/surf/surf.hpp + src/surf/surf_interface.hpp src/surf/surf_private.h src/surf/surf_routing_private.hpp src/surf/surf_routing.hpp @@ -75,8 +75,10 @@ set(EXTRA_DIST src/surf/surf_routing_vivaldi.hpp src/surf/surfxml_parse.c src/surf/trace_mgr_private.h - src/surf/vm_workstation.hpp - src/surf/workstation.hpp + src/surf/vm_workstation_interface.hpp + src/surf/vm_workstation_hl13.hpp + src/surf/workstation_interface.hpp + src/surf/workstation_clm03.hpp src/surf/workstation_ptask_L07.hpp src/win32/config.h src/xbt/automaton/automaton_lexer.yy.c @@ -314,7 +316,7 @@ set(SURF_SRC src/surf/sg_platf.c src/surf/storage_interface.cpp src/surf/storage_n11.cpp - src/surf/surf.cpp + src/surf/surf_interface.cpp src/surf/surf_c_bindings.cpp src/surf/surf_routing.cpp src/surf/surf_routing_cluster.cpp @@ -327,9 +329,11 @@ set(SURF_SRC src/surf/surfxml_parse.c src/surf/surfxml_parseplatf.c src/surf/trace_mgr.c - src/surf/workstation.cpp + src/surf/workstation_interface.cpp + src/surf/workstation_clm03.cpp src/surf/workstation_ptask_L07.cpp - src/surf/vm_workstation.cpp + src/surf/vm_workstation_interface.cpp + src/surf/vm_workstation_hl13.cpp src/xbt/xbt_sg_stubs.c ) diff --git a/src/surf/cpu_cas01.cpp b/src/surf/cpu_cas01.cpp index eaec1be859..2e71b1343e 100644 --- a/src/surf/cpu_cas01.cpp +++ b/src/surf/cpu_cas01.cpp @@ -6,7 +6,6 @@ #include "cpu_cas01.hpp" #include "cpu_ti.hpp" -#include "surf.hpp" #include "maxmin_private.h" #include "simgrid/sg_config.h" diff --git a/src/surf/cpu_interface.hpp b/src/surf/cpu_interface.hpp index b60bf13b14..7beb42557a 100644 --- a/src/surf/cpu_interface.hpp +++ b/src/surf/cpu_interface.hpp @@ -1,8 +1,8 @@ -#include "surf.hpp" +#include "surf_interface.hpp" #include "maxmin_private.h" -#ifndef SURF_MODEL_CPU_H_ -#define SURF_MODEL_CPU_H_ +#ifndef SURF_CPU_INTERFACE_HPP_ +#define SURF_CPU_INTERFACE_HPP_ /*********** * Classes * @@ -102,4 +102,4 @@ public: }; -#endif /* SURF_MODEL_CPU_H_ */ +#endif /* SURF_CPU_INTERFACE_HPP_ */ diff --git a/src/surf/network_interface.hpp b/src/surf/network_interface.hpp index f863cb3024..81ebd14860 100644 --- a/src/surf/network_interface.hpp +++ b/src/surf/network_interface.hpp @@ -4,7 +4,7 @@ * Created on: Nov 29, 2013 * Author: bedaride */ -#include "surf.hpp" +#include "surf_interface.hpp" #include "surf_routing.hpp" #ifndef SURF_NETWORK_INTERFACE_HPP_ diff --git a/src/surf/storage_interface.hpp b/src/surf/storage_interface.hpp index 054a9a73ac..9319dc5c15 100644 --- a/src/surf/storage_interface.hpp +++ b/src/surf/storage_interface.hpp @@ -1,4 +1,4 @@ -#include "surf.hpp" +#include "surf_interface.hpp" #ifndef STORAGE_INTERFACE_HPP_ #define STORAGE_INTERFACE_HPP_ diff --git a/src/surf/surf_c_bindings.cpp b/src/surf/surf_c_bindings.cpp index 4882897af0..bd1e7fa7fe 100644 --- a/src/surf/surf_c_bindings.cpp +++ b/src/surf/surf_c_bindings.cpp @@ -1,6 +1,6 @@ -#include "surf.hpp" -#include "workstation.hpp" -#include "vm_workstation.hpp" +#include "surf_interface.hpp" +#include "workstation_interface.hpp" +#include "vm_workstation_interface.hpp" #include "network_interface.hpp" #include "surf_routing_cluster.hpp" #include "instr/instr_private.h" @@ -15,12 +15,12 @@ static CpuPtr get_casted_cpu(surf_resource_t resource){ return dynamic_cast(static_cast(surf_cpu_resource_priv(resource))); } -static WorkstationCLM03Ptr get_casted_workstation(surf_resource_t resource){ - return dynamic_cast(static_cast(surf_workstation_resource_priv(resource))); +static WorkstationPtr get_casted_workstation(surf_resource_t resource){ + return dynamic_cast(static_cast(surf_workstation_resource_priv(resource))); } -static WorkstationVM2013Ptr get_casted_vm_workstation(surf_resource_t resource){ - return dynamic_cast(static_cast(surf_workstation_resource_priv(resource))); +static WorkstationVMPtr get_casted_vm_workstation(surf_resource_t resource){ + return dynamic_cast(static_cast(surf_workstation_resource_priv(resource))); } char *surf_routing_edge_name(sg_routing_edge_t edge){ @@ -28,7 +28,7 @@ char *surf_routing_edge_name(sg_routing_edge_t edge){ } #ifdef CONTEXT_THREADS -static xbt_parmap_t surf_parmap = NULL; /* parallel map on models */ +//FIXME:keeporremove static xbt_parmap_t surf_parmap = NULL; /* parallel map on models */ #endif extern double NOW; diff --git a/src/surf/surf.cpp b/src/surf/surf_interface.cpp similarity index 98% rename from src/surf/surf.cpp rename to src/surf/surf_interface.cpp index 4c1ff82683..b87f73c348 100644 --- a/src/surf/surf.cpp +++ b/src/surf/surf_interface.cpp @@ -1,9 +1,9 @@ #include "surf_private.h" -#include "surf.hpp" +#include "surf_interface.hpp" #include "network_interface.hpp" #include "cpu_interface.hpp" -#include "workstation.hpp" -#include "vm_workstation.hpp" +#include "workstation_interface.hpp" +#include "vm_workstation_interface.hpp" #include "simix/smx_host_private.h" #include "surf_routing.hpp" #include "simgrid/sg_config.h" @@ -319,7 +319,7 @@ static XBT_INLINE void surf_link_free(void *r) static XBT_INLINE void surf_workstation_free(void *r) { - delete dynamic_cast(static_cast(r)); + delete dynamic_cast(static_cast(r)); } @@ -750,18 +750,20 @@ const char *surf_action_state_names[6] = { "SURF_ACTION_NOT_IN_THE_SYSTEM" }; -Action::Action(){} - -Action::Action(ModelPtr model, double cost, bool failed): - m_priority(1.0), - m_failed(failed), - m_start(surf_get_clock()), m_finish(-1.0), - m_remains(cost), - m_maxDuration(NO_MAX_DURATION), - m_cost(cost), - p_model(model), - m_refcount(1), - p_data(NULL) +Action::Action() +: m_refcount(1) +{} + +Action::Action(ModelPtr model, double cost, bool failed) + : m_priority(1.0) + , m_failed(failed) + , m_start(surf_get_clock()), m_finish(-1.0) + , m_remains(cost) + , m_maxDuration(NO_MAX_DURATION) + , m_cost(cost) + , p_model(model) + , m_refcount(1) + , p_data(NULL) { #ifdef HAVE_TRACING p_category = NULL; diff --git a/src/surf/surf.hpp b/src/surf/surf_interface.hpp similarity index 99% rename from src/surf/surf.hpp rename to src/surf/surf_interface.hpp index 8f4d918410..0e001a9e15 100644 --- a/src/surf/surf.hpp +++ b/src/surf/surf_interface.hpp @@ -103,7 +103,7 @@ public: Model(string name); virtual ~Model(); - ResourcePtr createResource(string name); + //ResourcePtr createResource(string name); ActionPtr createAction(double _cost, bool _failed); virtual double shareResources(double now); virtual double shareResourcesLazy(double now); diff --git a/src/surf/surf_routing.hpp b/src/surf/surf_routing.hpp index d0ae19bf62..8c2c90f9a5 100644 --- a/src/surf/surf_routing.hpp +++ b/src/surf/surf_routing.hpp @@ -1,4 +1,4 @@ -#include "surf.hpp" +#include "surf_interface.hpp" #include #ifndef NETWORK_ROUTING_HPP_ diff --git a/src/surf/surf_routing_private.hpp b/src/surf/surf_routing_private.hpp index e3d718b1a8..16979416a4 100644 --- a/src/surf/surf_routing_private.hpp +++ b/src/surf/surf_routing_private.hpp @@ -10,7 +10,7 @@ #include #include "internal_config.h" -#include "surf.hpp" +#include "surf_interface.hpp" #include "xbt/dynar.h" #include "xbt/str.h" #include "xbt/config.h" diff --git a/src/surf/vm_workstation.hpp b/src/surf/vm_workstation.hpp deleted file mode 100644 index ce78cc7376..0000000000 --- a/src/surf/vm_workstation.hpp +++ /dev/null @@ -1,133 +0,0 @@ -/* - * vm_workstation.hpp - * - * Created on: Nov 12, 2013 - * Author: bedaride - */ -#include "workstation.hpp" - -#ifndef VM_WORKSTATION_HPP_ -#define VM_WORKSTATION_HPP_ - -#define GUESTOS_NOISE 100 // This value corresponds to the cost of the global action associated to the VM - // It corresponds to the cost of a VM running no tasks. - -void surf_vm_workstation_model_init(void); - -/* - void (*create) (const char *name, void *ind_phys_workstation); // First operation of the VM model - void (*destroy) (void *ind_vm_ws); // will be vm_ws_destroy(), which destroies the vm-workstation-specific data - - void (*suspend) (void *ind_vm_ws); - void (*resume) (void *ind_vm_ws); - - void (*save) (void *ind_vm_ws); - void (*restore) (void *ind_vm_ws); - - void (*migrate) (void *ind_vm_ws, void *ind_vm_ws_dest); // will be vm_ws_migrate() - - int (*get_state) (void *ind_vm_ws); - void (*set_state) (void *ind_vm_ws, int state); - - void * (*get_pm) (void *ind_vm_ws); // will be vm_ws_get_pm() - - void (*set_vm_bound) (void *ind_vm_ws, double bound); // will be vm_ws_set_vm_bound() - void (*set_vm_affinity) (void *ind_vm_ws, void *ind_pm_ws, unsigned long mask); // will be vm_ws_set_vm_affinity() -*/ - -/*********** - * Classes * - ***********/ - -class WorkstationVMModel; -typedef WorkstationVMModel *WorkstationVMModelPtr; - -class WorkstationVM2013; -typedef WorkstationVM2013 *WorkstationVM2013Ptr; - -class WorkstationVM2013Lmm; -typedef WorkstationVM2013Lmm *WorkstationVM2013LmmPtr; - -/********* - * Tools * - *********/ - -/********* - * Model * - *********/ -class WorkstationVMModel : public WorkstationModel { -public: - WorkstationVMModel(); - ~WorkstationVMModel(){}; - void createResource(const char *name, void *ind_phys_workstation); - double shareResources(double now); - void adjustWeightOfDummyCpuActions() {}; -}; - -/************ - * Resource * - ************/ -class WorkstationVM2013 : virtual public WorkstationCLM03 { -public: - WorkstationVM2013(WorkstationVMModelPtr model, const char* name, xbt_dict_t props, RoutingEdgePtr netElm, CpuPtr cpu) - : WorkstationCLM03(model, name, props, NULL, netElm, cpu) {}; - - virtual void suspend()=0; - virtual void resume()=0; - - virtual void save()=0; - virtual void restore()=0; - - virtual void migrate(surf_resource_t ind_vm_ws_dest)=0; // will be vm_ws_migrate() - - virtual surf_resource_t getPm()=0; // will be vm_ws_get_pm() - - virtual void setBound(double bound)=0; - virtual void setAffinity(CpuLmmPtr cpu, unsigned long mask)=0; - - /* The workstation object of the lower layer */ - WorkstationCLM03Ptr p_subWs; // Pointer to the ''host'' OS - e_surf_vm_state_t p_currentState; - CpuActionLmmPtr p_action; -}; - -class WorkstationVM2013Lmm : public WorkstationVM2013, public WorkstationCLM03Lmm { -public: - WorkstationVM2013Lmm(WorkstationVMModelPtr model, const char* name, xbt_dict_t props, surf_resource_t ind_phys_workstation); - ~WorkstationVM2013Lmm(); - - void suspend(); - void resume(); - - void save(); - void restore(); - - void migrate(surf_resource_t ind_dst_pm); - - e_surf_resource_state_t getState(); - void setState(e_surf_resource_state_t state); - - surf_resource_t getPm(); // will be vm_ws_get_pm() - - void setBound(double bound); - void setAffinity(CpuLmmPtr cpu, unsigned long mask); - - //FIXME: remove - void updateState(tmgr_trace_event_t event_type, double value, double date) { - WorkstationCLM03Lmm::updateState(event_type, value, date); - } - bool isUsed() { - return WorkstationCLM03Lmm::isUsed(); - } - xbt_dict_t getProperties() { - return WorkstationCLM03Lmm::getProperties(); - } - ActionPtr execute(double size); - -}; - -/********** - * Action * - **********/ - -#endif /* VM_WORKSTATION_HPP_ */ diff --git a/src/surf/vm_workstation.cpp b/src/surf/vm_workstation_hl13.cpp similarity index 82% rename from src/surf/vm_workstation.cpp rename to src/surf/vm_workstation_hl13.cpp index 6f868cc283..b8f6eccffe 100644 --- a/src/surf/vm_workstation.cpp +++ b/src/surf/vm_workstation_hl13.cpp @@ -4,19 +4,14 @@ * Created on: Nov 12, 2013 * Author: bedaride */ -#include "vm_workstation.hpp" +#include "vm_workstation_hl13.hpp" #include "cpu_cas01.hpp" -extern "C" { -XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_vm_workstation, surf, - "Logging specific to the SURF VM workstation module"); -} - -WorkstationVMModelPtr surf_vm_workstation_model = NULL; +XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_vm_workstation); void surf_vm_workstation_model_init_current_default(void){ if (surf_cpu_model_vm) { - surf_vm_workstation_model = new WorkstationVMModel(); + surf_vm_workstation_model = new WorkstationVMHL13Model(); ModelPtr model = static_cast(surf_vm_workstation_model); xbt_dynar_push(model_list, &model); @@ -28,16 +23,24 @@ void surf_vm_workstation_model_init_current_default(void){ * Model * *********/ -WorkstationVMModel::WorkstationVMModel() : WorkstationModel("Virtual Workstation") { +WorkstationVMHL13Model::WorkstationVMHL13Model() : WorkstationVMModel() { p_cpuModel = surf_cpu_model_vm; } +xbt_dynar_t WorkstationVMHL13Model::getRoute(WorkstationPtr src, WorkstationPtr dst){ + return WorkstationCLM03Model::getRoute(src, dst); +} + +ActionPtr WorkstationVMHL13Model::communicate(WorkstationPtr src, WorkstationPtr dst, double size, double rate){ + return WorkstationCLM03Model::communicate(src, dst, size, rate); +} + /* ind means ''indirect'' that this is a reference on the whole dict_elm * structure (i.e not on the surf_resource_private infos) */ -void WorkstationVMModel::createResource(const char *name, void *ind_phys_workstation) +void WorkstationVMHL13Model::createResource(const char *name, void *ind_phys_workstation) { - WorkstationVM2013LmmPtr ws = new WorkstationVM2013Lmm(this, name, NULL, static_cast(ind_phys_workstation)); + WorkstationVMHL13LmmPtr ws = new WorkstationVMHL13Lmm(this, name, NULL, static_cast(ind_phys_workstation)); xbt_lib_set(host_lib, name, SURF_WKS_LEVEL, static_cast(ws)); @@ -58,7 +61,7 @@ static inline double get_solved_value(CpuActionLmmPtr cpu_action) // const double virt_overhead = 0.95; const double virt_overhead = 1; -double WorkstationVMModel::shareResources(double now) +double WorkstationVMHL13Model::shareResources(double now) { /* TODO: udpate action's cost with the total cost of processes on the VM. */ @@ -107,35 +110,35 @@ double WorkstationVMModel::shareResources(double now) char *key; void **ind_host; xbt_lib_foreach(host_lib, cursor, key, ind_host) { - WorkstationCLM03Ptr ws_clm03 = dynamic_cast( + WorkstationPtr ws = dynamic_cast( static_cast(ind_host[SURF_WKS_LEVEL])); - CpuCas01LmmPtr cpu_cas01 = dynamic_cast( + CpuLmmPtr cpu = dynamic_cast( static_cast(ind_host[SURF_CPU_LEVEL])); - if (!ws_clm03) + if (!ws) continue; /* skip if it is not a virtual machine */ - if (ws_clm03->p_model != static_cast(surf_vm_workstation_model)) + if (ws->p_model != static_cast(surf_vm_workstation_model)) continue; - xbt_assert(cpu_cas01, "cpu-less workstation"); + xbt_assert(cpu, "cpu-less workstation"); /* It is a virtual machine, so we can cast it to workstation_VM2013_t */ - WorkstationVM2013Ptr ws_vm2013 = dynamic_cast(ws_clm03); + WorkstationVMPtr ws_vm = dynamic_cast(ws); - double solved_value = get_solved_value(ws_vm2013->p_action); + double solved_value = get_solved_value(reinterpret_cast(ws_vm->p_action)); XBT_DEBUG("assign %f to vm %s @ pm %s", solved_value, - ws_clm03->m_name, ws_vm2013->p_subWs->m_name); + ws->m_name, ws_vm->p_subWs->m_name); // TODO: check lmm_update_constraint_bound() works fine instead of the below manual substitution. // cpu_cas01->constraint->bound = solved_value; - xbt_assert(cpu_cas01->p_model == static_cast(surf_cpu_model_vm)); - lmm_system_t vcpu_system = cpu_cas01->p_model->p_maxminSystem; - lmm_update_constraint_bound(vcpu_system, cpu_cas01->p_constraint, virt_overhead * solved_value); + xbt_assert(cpu->p_model == static_cast(surf_cpu_model_vm)); + lmm_system_t vcpu_system = cpu->p_model->p_maxminSystem; + lmm_update_constraint_bound(vcpu_system, cpu->p_constraint, virt_overhead * solved_value); } /* 2. Calculate resource share at the virtual machine layer. */ - double ret = WorkstationModel::shareResources(now); + double ret = WorkstationCLM03Model::shareResources(now); /* FIXME: 3. do we have to re-initialize our cpu_action object? */ @@ -179,13 +182,13 @@ double WorkstationVMModel::shareResources(double now) /************ * Resource * ************/ -WorkstationVM2013Lmm::WorkstationVM2013Lmm(WorkstationVMModelPtr model, const char* name, xbt_dict_t props, +WorkstationVMHL13Lmm::WorkstationVMHL13Lmm(WorkstationVMModelPtr model, const char* name, xbt_dict_t props, surf_resource_t ind_phys_workstation) - : Resource(model, name, props), - WorkstationCLM03(model, name, props, NULL, NULL, NULL), - WorkstationVM2013(model, name, props, NULL, NULL), - WorkstationCLM03Lmm(model, name, props, NULL, NULL, NULL) { - WorkstationCLM03Ptr sub_ws = dynamic_cast( + : Resource(model, name, props) + , WorkstationVMLmm(NULL, NULL) + , WorkstationCLM03Lmm(model, name, props, NULL, NULL, NULL) +{ + WorkstationPtr sub_ws = dynamic_cast( static_cast( surf_workstation_resource_priv(ind_phys_workstation))); @@ -242,7 +245,7 @@ WorkstationVM2013Lmm::WorkstationVM2013Lmm(WorkstationVMModelPtr model, const ch * A physical host does not disapper in the current SimGrid code, but a VM may * disapper during a simulation. */ -WorkstationVM2013Lmm::~WorkstationVM2013Lmm() +WorkstationVMHL13Lmm::~WorkstationVMHL13Lmm() { /* ind_phys_workstation equals to smx_host_t */ surf_resource_t ind_vm_workstation = xbt_lib_get_elm_or_null(host_lib, m_name); @@ -282,29 +285,29 @@ WorkstationVM2013Lmm::~WorkstationVM2013Lmm() /* Free the workstation resource of the VM. */ } -e_surf_resource_state_t WorkstationVM2013Lmm::getState() +e_surf_resource_state_t WorkstationVMHL13Lmm::getState() { return (e_surf_resource_state_t) p_currentState; } -void WorkstationVM2013Lmm::setState(e_surf_resource_state_t state) +void WorkstationVMHL13Lmm::setState(e_surf_resource_state_t state) { p_currentState = (e_surf_vm_state_t) state; } -void WorkstationVM2013Lmm::suspend() +void WorkstationVMHL13Lmm::suspend() { p_action->suspend(); p_currentState = SURF_VM_STATE_SUSPENDED; } -void WorkstationVM2013Lmm::resume() +void WorkstationVMHL13Lmm::resume() { p_action->resume(); p_currentState = SURF_VM_STATE_RUNNING; } -void WorkstationVM2013Lmm::save() +void WorkstationVMHL13Lmm::save() { p_currentState = SURF_VM_STATE_SAVING; @@ -313,7 +316,7 @@ void WorkstationVM2013Lmm::save() p_currentState = SURF_VM_STATE_SAVED; } -void WorkstationVM2013Lmm::restore() +void WorkstationVMHL13Lmm::restore() { p_currentState = SURF_VM_STATE_RESTORING; @@ -325,17 +328,17 @@ void WorkstationVM2013Lmm::restore() /* * Update the physical host of the given VM */ -void WorkstationVM2013Lmm::migrate(surf_resource_t ind_dst_pm) +void WorkstationVMHL13Lmm::migrate(surf_resource_t ind_dst_pm) { /* ind_phys_workstation equals to smx_host_t */ - WorkstationCLM03Ptr ws_clm03_dst = dynamic_cast( + WorkstationPtr ws_dst = dynamic_cast( static_cast( surf_workstation_resource_priv(ind_dst_pm))); const char *vm_name = m_name; const char *pm_name_src = p_subWs->m_name; - const char *pm_name_dst = ws_clm03_dst->m_name; + const char *pm_name_dst = ws_dst->m_name; - xbt_assert(ws_clm03_dst); + xbt_assert(ws_dst); /* do something */ @@ -351,7 +354,7 @@ void WorkstationVM2013Lmm::migrate(surf_resource_t ind_dst_pm) p_netElm = new_net_elm; xbt_lib_set(host_lib, vm_name, ROUTING_HOST_LEVEL, p_netElm); - p_subWs = ws_clm03_dst; + p_subWs = ws_dst; /* Update vcpu's action for the new pm */ { @@ -371,7 +374,7 @@ void WorkstationVM2013Lmm::migrate(surf_resource_t ind_dst_pm) static_cast( surf_cpu_resource_priv(ind_dst_pm)))->execute(0)); - e_surf_action_state_t state = surf_action_get_state(p_action); + e_surf_action_state_t state = p_action->getState(); if (state != SURF_ACTION_DONE) XBT_CRITICAL("FIXME: may need a proper handling, %d", state); if (p_action->m_remains > 0) @@ -387,11 +390,11 @@ void WorkstationVM2013Lmm::migrate(surf_resource_t ind_dst_pm) XBT_DEBUG("migrate VM(%s): change PM (%s to %s)", vm_name, pm_name_src, pm_name_dst); } -void WorkstationVM2013Lmm::setBound(double bound){ +void WorkstationVMHL13Lmm::setBound(double bound){ p_action->setBound(bound); } -void WorkstationVM2013Lmm::setAffinity(CpuLmmPtr cpu, unsigned long mask){ +void WorkstationVMHL13Lmm::setAffinity(CpuLmmPtr cpu, unsigned long mask){ p_action->setAffinity(cpu, mask); } @@ -399,13 +402,13 @@ void WorkstationVM2013Lmm::setAffinity(CpuLmmPtr cpu, unsigned long mask){ * A surf level object will be useless in the upper layer. Returing the * dict_elm of the host. **/ -surf_resource_t WorkstationVM2013Lmm::getPm() +surf_resource_t WorkstationVMHL13Lmm::getPm() { return xbt_lib_get_elm_or_null(host_lib, p_subWs->m_name); } /* Adding a task to a VM updates the VCPU task on its physical machine. */ -ActionPtr WorkstationVM2013Lmm::execute(double size) +ActionPtr WorkstationVMHL13Lmm::execute(double size) { double old_cost = p_action->m_cost; double new_cost = old_cost + size; @@ -416,7 +419,7 @@ ActionPtr WorkstationVM2013Lmm::execute(double size) p_action->m_cost = new_cost; - return WorkstationCLM03::execute(size); + return WorkstationCLM03Lmm::execute(size); } /********** diff --git a/src/surf/vm_workstation_hl13.hpp b/src/surf/vm_workstation_hl13.hpp new file mode 100644 index 0000000000..4278426505 --- /dev/null +++ b/src/surf/vm_workstation_hl13.hpp @@ -0,0 +1,89 @@ +/* + * vm_workstation.hpp + * + * Created on: Nov 12, 2013 + * Author: bedaride + */ +#include "vm_workstation_interface.hpp" +#include "workstation_clm03.hpp" + +#ifndef VM_WORKSTATION_HPP_ +#define VM_WORKSTATION_HPP_ + +#define GUESTOS_NOISE 100 // This value corresponds to the cost of the global action associated to the VM + // It corresponds to the cost of a VM running no tasks. + +void surf_vm_workstation_model_init(void); + +/*********** + * Classes * + ***********/ + +class WorkstationVMHL13Model; +typedef WorkstationVMHL13Model *WorkstationVMHL13ModelPtr; + +class WorkstationVMHL13Lmm; +typedef WorkstationVMHL13Lmm *WorkstationVMHL13LmmPtr; + +/********* + * Tools * + *********/ + +/********* + * Model * + *********/ +class WorkstationVMHL13Model : public WorkstationVMModel, public WorkstationCLM03Model { +public: + WorkstationVMHL13Model(); + ~WorkstationVMHL13Model(){}; + void createResource(const char *name, void *ind_phys_workstation); + double shareResources(double now); + void adjustWeightOfDummyCpuActions() {}; + xbt_dynar_t getRoute(WorkstationPtr src, WorkstationPtr dst); + ActionPtr communicate(WorkstationPtr src, WorkstationPtr dst, double size, double rate); +}; + +/************ + * Resource * + ************/ + +class WorkstationVMHL13Lmm : public WorkstationVMLmm, public WorkstationCLM03Lmm { +public: + WorkstationVMHL13Lmm(WorkstationVMModelPtr model, const char* name, xbt_dict_t props, surf_resource_t ind_phys_workstation); + ~WorkstationVMHL13Lmm(); + + void suspend(); + void resume(); + + void save(); + void restore(); + + void migrate(surf_resource_t ind_dst_pm); + + e_surf_resource_state_t getState(); + void setState(e_surf_resource_state_t state); + + surf_resource_t getPm(); // will be vm_ws_get_pm() + + void setBound(double bound); + void setAffinity(CpuLmmPtr cpu, unsigned long mask); + + //FIXME: remove + void updateState(tmgr_trace_event_t event_type, double value, double date) { + WorkstationCLM03Lmm::updateState(event_type, value, date); + } + bool isUsed() { + return WorkstationCLM03Lmm::isUsed(); + } + xbt_dict_t getProperties() { + return WorkstationCLM03Lmm::getProperties(); + } + ActionPtr execute(double size); + +}; + +/********** + * Action * + **********/ + +#endif /* VM_WORKSTATION_HPP_ */ diff --git a/src/surf/vm_workstation_interface.cpp b/src/surf/vm_workstation_interface.cpp new file mode 100644 index 0000000000..4dff946e5b --- /dev/null +++ b/src/surf/vm_workstation_interface.cpp @@ -0,0 +1,85 @@ +/* + * vm_workstation.cpp + * + * Created on: Nov 12, 2013 + * Author: bedaride + */ +#include "vm_workstation_interface.hpp" +#include "cpu_cas01.hpp" + +extern "C" { +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_vm_workstation, surf, + "Logging specific to the SURF VM workstation module"); +} + +WorkstationVMModelPtr surf_vm_workstation_model = NULL; + +/********* + * Model * + *********/ + +WorkstationVMModel::WorkstationVMModel() : WorkstationModel("Virtual Workstation") { + p_cpuModel = surf_cpu_model_vm; +} + +/************ + * Resource * + ************/ + + +WorkstationVMLmm::WorkstationVMLmm(RoutingEdgePtr netElm, CpuPtr cpu) + : WorkstationVM(netElm, cpu) + , WorkstationLmm() +{} + +/* + * A physical host does not disapper in the current SimGrid code, but a VM may + * disapper during a simulation. + */ +WorkstationVM::~WorkstationVM() +{ + /* ind_phys_workstation equals to smx_host_t */ + surf_resource_t ind_vm_workstation = xbt_lib_get_elm_or_null(host_lib, m_name); + + /* Before clearing the entries in host_lib, we have to pick up resources. */ + CpuCas01LmmPtr cpu = dynamic_cast( + static_cast( + surf_cpu_resource_priv(ind_vm_workstation))); + + /* We deregister objects from host_lib, without invoking the freeing callback + * of each level. + * + * Do not call xbt_lib_remove() here. It deletes all levels of the key, + * including MSG_HOST_LEVEL and others. We should unregister only what we know. + */ + xbt_lib_unset(host_lib, m_name, SURF_CPU_LEVEL, 0); + xbt_lib_unset(host_lib, m_name, ROUTING_HOST_LEVEL, 0); + xbt_lib_unset(host_lib, m_name, SURF_WKS_LEVEL, 0); + + /* TODO: comment out when VM stroage is implemented. */ + // xbt_lib_unset(host_lib, name, SURF_STORAGE_LEVEL, 0); + + + /* Free the cpu_action of the VM. */ + int ret = p_action->unref(); + xbt_assert(ret == 1, "Bug: some resource still remains"); + + /* Free the cpu resource of the VM. If using power_trace, we will have to */ + delete cpu; +} + +/* + * A surf level object will be useless in the upper layer. Returing the + * dict_elm of the host. + **/ +surf_resource_t WorkstationVM::getPm() +{ + return xbt_lib_get_elm_or_null(host_lib, p_subWs->m_name); +} + +/********** + * Action * + **********/ + +//FIME:: handle action cancel + diff --git a/src/surf/vm_workstation_interface.hpp b/src/surf/vm_workstation_interface.hpp new file mode 100644 index 0000000000..9c067ed8ee --- /dev/null +++ b/src/surf/vm_workstation_interface.hpp @@ -0,0 +1,80 @@ +/* + * vm_workstation.hpp + * + * Created on: Nov 12, 2013 + * Author: bedaride + */ +#include "workstation_interface.hpp" + +#ifndef VM_WORKSTATION_INTERFACE_HPP_ +#define VM_WORKSTATION_INTERFACE_HPP_ + +#define GUESTOS_NOISE 100 // This value corresponds to the cost of the global action associated to the VM + // It corresponds to the cost of a VM running no tasks. + +void surf_vm_workstation_model_init(void); + +/*********** + * Classes * + ***********/ + +class WorkstationVMModel; +typedef WorkstationVMModel *WorkstationVMModelPtr; + +class WorkstationVM; +typedef WorkstationVM *WorkstationVMPtr; + +class WorkstationVMLmm; +typedef WorkstationVMLmm *WorkstationVMLmmPtr; + +/********* + * Model * + *********/ + +class WorkstationVMModel : virtual public WorkstationModel { +public: + WorkstationVMModel(); + ~WorkstationVMModel(){}; + virtual void createResource(const char *name, void *ind_phys_workstation)=0; + void adjustWeightOfDummyCpuActions() {}; +}; + +/************ + * Resource * + ************/ + +class WorkstationVM : virtual public Workstation { +public: + WorkstationVM(RoutingEdgePtr netElm, CpuPtr cpu) + : Workstation(NULL, netElm, cpu) {}; + ~WorkstationVM(); + + virtual void suspend()=0; + virtual void resume()=0; + + virtual void save()=0; + virtual void restore()=0; + + virtual void migrate(surf_resource_t ind_vm_ws_dest)=0; // will be vm_ws_migrate() + + virtual surf_resource_t getPm()=0; // will be vm_ws_get_pm() + + virtual void setBound(double bound)=0; + virtual void setAffinity(CpuLmmPtr cpu, unsigned long mask)=0; + + /* The workstation object of the lower layer */ + CpuActionPtr p_action; + WorkstationPtr p_subWs; // Pointer to the ''host'' OS + e_surf_vm_state_t p_currentState; +}; + +class WorkstationVMLmm : public WorkstationVM, public WorkstationLmm { +public: + WorkstationVMLmm(RoutingEdgePtr netElm, CpuPtr cpu); +}; + +/********** + * Action * + **********/ + +#endif /* VM_WORKSTATION_INTERFACE_HPP_ */ diff --git a/src/surf/workstation.cpp b/src/surf/workstation.cpp deleted file mode 100644 index 7274418b2d..0000000000 --- a/src/surf/workstation.cpp +++ /dev/null @@ -1,455 +0,0 @@ -#include "workstation.hpp" -#include "vm_workstation.hpp" -#include "cpu_cas01.hpp" -#include "simgrid/sg_config.h" - -extern "C" { -XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_workstation, surf, - "Logging specific to the SURF workstation module"); -} - -WorkstationModelPtr surf_workstation_model = NULL; - -/************* - * CallBacks * - *************/ - -static void workstation_new(sg_platf_host_cbarg_t host){ - surf_workstation_model->createResource(host->id); -} - -/********* - * Model * - *********/ - -void surf_workstation_model_init_current_default(void) -{ - surf_workstation_model = new WorkstationModel(); - xbt_cfg_setdefault_boolean(_sg_cfg_set, "network/crosstraffic", "yes"); - surf_cpu_model_init_Cas01(); - surf_network_model_init_LegrandVelho(); - surf_workstation_model->p_cpuModel = surf_cpu_model_pm; - - ModelPtr model = static_cast(surf_workstation_model); - xbt_dynar_push(model_list, &model); - xbt_dynar_push(model_list_invoke, &model); - sg_platf_host_add_cb(workstation_new); -} - -void surf_workstation_model_init_compound() -{ - - xbt_assert(surf_cpu_model_pm, "No CPU model defined yet!"); - xbt_assert(surf_network_model, "No network model defined yet!"); - surf_workstation_model = new WorkstationModel(); - - ModelPtr model = static_cast(surf_workstation_model); - xbt_dynar_push(model_list, &model); - xbt_dynar_push(model_list_invoke, &model); - sg_platf_host_add_cb(workstation_new); -} - -WorkstationModel::WorkstationModel() : Model("Workstation") { - p_cpuModel = surf_cpu_model_pm; -} - -WorkstationModel::~WorkstationModel() { -} - -void WorkstationModel::parseInit(sg_platf_host_cbarg_t host){ - createResource(host->id); -} - -WorkstationCLM03Ptr WorkstationModel::createResource(string name){ - - WorkstationCLM03Ptr workstation = new WorkstationCLM03(surf_workstation_model, name.c_str(), NULL, - (xbt_dynar_t)xbt_lib_get_or_null(storage_lib, name.c_str(), ROUTING_STORAGE_HOST_LEVEL), - (RoutingEdgePtr)xbt_lib_get_or_null(host_lib, name.c_str(), ROUTING_HOST_LEVEL), - dynamic_cast(static_cast(xbt_lib_get_or_null(host_lib, name.c_str(), SURF_CPU_LEVEL)))); - XBT_DEBUG("Create workstation %s with %ld mounted disks", name.c_str(), xbt_dynar_length(workstation->p_storage)); - xbt_lib_set(host_lib, name.c_str(), SURF_WKS_LEVEL, static_cast(workstation)); - return workstation; -} - -/* Each VM has a dummy CPU action on the PM layer. This CPU action works as the - * constraint (capacity) of the VM in the PM layer. If the VM does not have any - * active task, the dummy CPU action must be deactivated, so that the VM does - * not get any CPU share in the PM layer. */ -void WorkstationModel::adjustWeightOfDummyCpuActions() -{ - /* iterate for all hosts including virtual machines */ - xbt_lib_cursor_t cursor; - char *key; - void **ind_host; - - xbt_lib_foreach(host_lib, cursor, key, ind_host) { - WorkstationCLM03Ptr ws_clm03 = dynamic_cast( - static_cast(ind_host[SURF_WKS_LEVEL])); - CpuCas01LmmPtr cpu_cas01 = dynamic_cast( - static_cast(ind_host[SURF_CPU_LEVEL])); - - if (!ws_clm03) - continue; - /* skip if it is not a virtual machine */ - if (ws_clm03->p_model != static_cast(surf_vm_workstation_model)) - continue; - xbt_assert(cpu_cas01, "cpu-less workstation"); - - /* It is a virtual machine, so we can cast it to workstation_VM2013_t */ - WorkstationVM2013Ptr ws_vm2013 = dynamic_cast(ws_clm03); - - int is_active = lmm_constraint_used(cpu_cas01->p_model->p_maxminSystem, cpu_cas01->p_constraint); - // int is_active_old = constraint_is_active(cpu_cas01); - - // { - // xbt_assert(is_active == is_active_old, "%d %d", is_active, is_active_old); - // } - - if (is_active) { - /* some tasks exist on this VM */ - XBT_DEBUG("set the weight of the dummy CPU action on PM to 1"); - - /* FIXME: we shoud use lmm_update_variable_weight() ? */ - /* FIXME: If we assgign 1.05 and 0.05, the system makes apparently wrong values. */ - surf_action_set_priority(ws_vm2013->p_action, 1); - - } else { - /* no task exits on this VM */ - XBT_DEBUG("set the weight of the dummy CPU action on PM to 0"); - - surf_action_set_priority(ws_vm2013->p_action, 0); - } - } -} - -double WorkstationModel::shareResources(double now){ - adjustWeightOfDummyCpuActions(); - - double min_by_cpu = p_cpuModel->shareResources(now); - double min_by_net = surf_network_model->shareResources(now); - double min_by_sto = -1; - if (p_cpuModel == surf_cpu_model_pm) - min_by_sto = surf_storage_model->shareResources(now); - - XBT_DEBUG("model %p, %s min_by_cpu %f, %s min_by_net %f, %s min_by_sto %f", - this, surf_cpu_model_pm->m_name.c_str(), min_by_cpu, - surf_network_model->m_name.c_str(), min_by_net, - surf_storage_model->m_name.c_str(), min_by_sto); - - double res = max(max(min_by_cpu, min_by_net), min_by_sto); - if (min_by_cpu >= 0.0 && min_by_cpu < res) - res = min_by_cpu; - if (min_by_net >= 0.0 && min_by_net < res) - res = min_by_net; - if (min_by_sto >= 0.0 && min_by_sto < res) - res = min_by_sto; - return res; -} - -void WorkstationModel::updateActionsState(double /*now*/, double /*delta*/){ - return; -} - -ActionPtr WorkstationModel::executeParallelTask(int workstation_nb, - void **workstation_list, - double *computation_amount, - double *communication_amount, - double rate){ -#define cost_or_zero(array,pos) ((array)?(array)[pos]:0.0) - if ((workstation_nb == 1) - && (cost_or_zero(communication_amount, 0) == 0.0)) - return ((WorkstationCLM03Ptr)workstation_list[0])->execute(computation_amount[0]); - else if ((workstation_nb == 1) - && (cost_or_zero(computation_amount, 0) == 0.0)) - return communicate((WorkstationCLM03Ptr)workstation_list[0], (WorkstationCLM03Ptr)workstation_list[0],communication_amount[0], rate); - else if ((workstation_nb == 2) - && (cost_or_zero(computation_amount, 0) == 0.0) - && (cost_or_zero(computation_amount, 1) == 0.0)) { - int i,nb = 0; - double value = 0.0; - - for (i = 0; i < workstation_nb * workstation_nb; i++) { - if (cost_or_zero(communication_amount, i) > 0.0) { - nb++; - value = cost_or_zero(communication_amount, i); - } - } - if (nb == 1) - return communicate((WorkstationCLM03Ptr)workstation_list[0], (WorkstationCLM03Ptr)workstation_list[1],value, rate); - } -#undef cost_or_zero - - THROW_UNIMPLEMENTED; /* This model does not implement parallel tasks */ - return NULL; -} - -/* returns an array of network_link_CM02_t */ -xbt_dynar_t WorkstationModel::getRoute(WorkstationCLM03Ptr src, WorkstationCLM03Ptr dst) -{ - XBT_DEBUG("ws_get_route"); - return surf_network_model->getRoute(src->p_netElm, dst->p_netElm); -} - -ActionPtr WorkstationModel::communicate(WorkstationCLM03Ptr src, WorkstationCLM03Ptr dst, double size, double rate){ - return surf_network_model->communicate(src->p_netElm, dst->p_netElm, size, rate); -} - - - -/************ - * Resource * - ************/ -WorkstationCLM03::WorkstationCLM03(WorkstationModelPtr model, const char* name, xbt_dict_t properties, xbt_dynar_t storage, RoutingEdgePtr netElm, CpuPtr cpu) - : Resource(model, name, properties), p_storage(storage), p_netElm(netElm), p_cpu(cpu) {} - -bool WorkstationCLM03::isUsed(){ - THROW_IMPOSSIBLE; /* This model does not implement parallel tasks */ - return -1; -} - -void WorkstationCLM03::updateState(tmgr_trace_event_t /*event_type*/, double /*value*/, double /*date*/){ - THROW_IMPOSSIBLE; /* This model does not implement parallel tasks */ -} - -ActionPtr WorkstationCLM03::execute(double size) { - return p_cpu->execute(size); -} - -ActionPtr WorkstationCLM03::sleep(double duration) { - return p_cpu->sleep(duration); -} - -e_surf_resource_state_t WorkstationCLM03::getState() { - return p_cpu->getState(); -} - -int WorkstationCLM03::getCore(){ - return p_cpu->getCore(); -} - -double WorkstationCLM03::getSpeed(double load){ - return p_cpu->getSpeed(load); -} - -double WorkstationCLM03::getAvailableSpeed(){ - return p_cpu->getAvailableSpeed(); -} - -double WorkstationCLM03::getCurrentPowerPeak() -{ - return p_cpu->getCurrentPowerPeak(); -} - -double WorkstationCLM03::getPowerPeakAt(int pstate_index) -{ - return p_cpu->getPowerPeakAt(pstate_index); -} - -int WorkstationCLM03::getNbPstates() -{ - return p_cpu->getNbPstates(); -} - -void WorkstationCLM03::setPowerPeakAt(int pstate_index) -{ - p_cpu->setPowerPeakAt(pstate_index); -} - -double WorkstationCLM03::getConsumedEnergy() -{ - return p_cpu->getConsumedEnergy(); -} - - -xbt_dict_t WorkstationCLM03::getProperties() -{ - return p_cpu->m_properties; -} - - -StoragePtr WorkstationCLM03::findStorageOnMountList(const char* mount) -{ - StoragePtr st = NULL; - s_mount_t mnt; - unsigned int cursor; - - XBT_DEBUG("Search for storage name '%s' on '%s'", mount, m_name); - xbt_dynar_foreach(p_storage,cursor,mnt) - { - XBT_DEBUG("See '%s'",mnt.name); - if(!strcmp(mount,mnt.name)){ - st = dynamic_cast(static_cast(mnt.storage)); - break; - } - } - if(!st) xbt_die("Can't find mount '%s' for '%s'", mount, m_name); - return st; -} - -xbt_dict_t WorkstationCLM03::getStorageList() -{ - s_mount_t mnt; - unsigned int i; - xbt_dict_t storage_list = xbt_dict_new_homogeneous(NULL); - char *storage_name = NULL; - - xbt_dynar_foreach(p_storage,i,mnt){ - storage_name = (char *)dynamic_cast(static_cast(mnt.storage))->m_name; - xbt_dict_set(storage_list,mnt.name,storage_name,NULL); - } - return storage_list; -} - -ActionPtr WorkstationCLM03::open(const char* mount, const char* path) { - StoragePtr st = findStorageOnMountList(mount); - XBT_DEBUG("OPEN on disk '%s'", st->m_name); - return st->open(mount, path); -} - -ActionPtr WorkstationCLM03::close(surf_file_t fd) { - StoragePtr st = findStorageOnMountList(fd->mount); - XBT_DEBUG("CLOSE on disk '%s'",st->m_name); - return st->close(fd); -} - -ActionPtr WorkstationCLM03::read(surf_file_t fd, sg_size_t size) { - StoragePtr st = findStorageOnMountList(fd->mount); - XBT_DEBUG("READ on disk '%s'",st->m_name); - return st->read(fd, size); -} - -ActionPtr WorkstationCLM03::write(surf_file_t fd, sg_size_t size) { - StoragePtr st = findStorageOnMountList(fd->mount); - XBT_DEBUG("WRITE on disk '%s'",st->m_name); - return st->write(fd, size); -} - -int WorkstationCLM03::unlink(surf_file_t fd) { - if (!fd){ - XBT_WARN("No such file descriptor. Impossible to unlink"); - return 0; - } else { -// XBT_INFO("%s %zu", fd->storage, fd->size); - StoragePtr st = findStorageOnMountList(fd->mount); - /* Check if the file is on this storage */ - if (!xbt_dict_get_or_null(st->p_content, fd->name)){ - XBT_WARN("File %s is not on disk %s. Impossible to unlink", fd->name, - st->m_name); - return 0; - } else { - XBT_DEBUG("UNLINK on disk '%s'",st->m_name); - st->m_usedSize -= fd->size; - - // Remove the file from storage - xbt_dict_remove(st->p_content, fd->name); - - free(fd->name); - free(fd->mount); - xbt_free(fd); - return 1; - } - } -} - -ActionPtr WorkstationCLM03::ls(const char* mount, const char *path){ - XBT_DEBUG("LS on mount '%s' and file '%s'", mount, path); - StoragePtr st = findStorageOnMountList(mount); - return st->ls(path); -} - -sg_size_t WorkstationCLM03::getSize(surf_file_t fd){ - return fd->size; -} - -xbt_dynar_t WorkstationCLM03::getInfo( surf_file_t fd) -{ - StoragePtr st = findStorageOnMountList(fd->mount); - sg_size_t *psize = xbt_new(sg_size_t, 1); - *psize = fd->size; - xbt_dynar_t info = xbt_dynar_new(sizeof(void*), NULL); - xbt_dynar_push_as(info, sg_size_t *, psize); - xbt_dynar_push_as(info, void *, fd->mount); - xbt_dynar_push_as(info, void *, (void *)st->m_name); - xbt_dynar_push_as(info, void *, st->p_typeId); - xbt_dynar_push_as(info, void *, st->p_contentType); - - return info; -} - -sg_size_t WorkstationCLM03::fileTell(surf_file_t fd){ - return fd->current_position; -} - -int WorkstationCLM03::fileSeek(surf_file_t fd, sg_size_t offset, int origin){ - - switch (origin) { - case SEEK_SET: - fd->current_position = 0; - return MSG_OK; - case SEEK_CUR: - if(offset > fd->size) - offset = fd->size; - fd->current_position = offset; - return MSG_OK; - case SEEK_END: - fd->current_position = fd->size; - return MSG_OK; - default: - return MSG_TASK_CANCELED; - } -} - -sg_size_t WorkstationCLM03::getFreeSize(const char* name) -{ - StoragePtr st = findStorageOnMountList(name); - return st->m_size - st->m_usedSize; -} - -sg_size_t WorkstationCLM03::getUsedSize(const char* name) -{ - StoragePtr st = findStorageOnMountList(name); - return st->m_usedSize; -} - -e_surf_resource_state_t WorkstationCLM03Lmm::getState() { - return WorkstationCLM03::getState(); -} - -xbt_dynar_t WorkstationCLM03::getVms() -{ - xbt_dynar_t dyn = xbt_dynar_new(sizeof(smx_host_t), NULL); - - /* iterate for all hosts including virtual machines */ - xbt_lib_cursor_t cursor; - char *key; - void **ind_host; - xbt_lib_foreach(host_lib, cursor, key, ind_host) { - WorkstationCLM03Ptr ws_clm03 = dynamic_cast(static_cast(ind_host[SURF_WKS_LEVEL])); - if (!ws_clm03) - continue; - /* skip if it is not a virtual machine */ - if (ws_clm03->p_model != static_cast(surf_vm_workstation_model)) - continue; - - /* It is a virtual machine, so we can cast it to workstation_VM2013_t */ - WorkstationVM2013Ptr ws_vm2013 = dynamic_cast(ws_clm03); - if (this == ws_vm2013-> p_subWs) - xbt_dynar_push(dyn, &ws_vm2013->p_subWs); - } - - return dyn; -} - -void WorkstationCLM03::getParams(ws_params_t params) -{ - memcpy(params, &p_params, sizeof(s_ws_params_t)); -} - -void WorkstationCLM03::setParams(ws_params_t params) -{ - /* may check something here. */ - memcpy(&p_params, params, sizeof(s_ws_params_t)); -} -/********** - * Action * - **********/ diff --git a/src/surf/workstation.hpp b/src/surf/workstation.hpp deleted file mode 100644 index 76aaf9f00e..0000000000 --- a/src/surf/workstation.hpp +++ /dev/null @@ -1,134 +0,0 @@ -#include "surf.hpp" -#include "storage_interface.hpp" -#include "cpu_interface.hpp" -#include "network_interface.hpp" - -#ifndef WORKSTATION_HPP_ -#define WORKSTATION_HPP_ - -/*********** - * Classes * - ***********/ - -class WorkstationModel; -typedef WorkstationModel *WorkstationModelPtr; - -class WorkstationCLM03; -typedef WorkstationCLM03 *WorkstationCLM03Ptr; - -class WorkstationCLM03Lmm; -typedef WorkstationCLM03Lmm *WorkstationCLM03LmmPtr; - -class WorkstationAction; -typedef WorkstationAction *WorkstationActionPtr; - -class WorkstationActionLmm; -typedef WorkstationActionLmm *WorkstationActionLmmPtr; - -/********* - * Tools * - *********/ -extern WorkstationModelPtr surf_workstation_model; - -/********* - * Model * - *********/ -class WorkstationModel : public Model { -public: - WorkstationModel(string name): Model(name) {}; - WorkstationModel(); - ~WorkstationModel(); - virtual void parseInit(sg_platf_host_cbarg_t host); - WorkstationCLM03Ptr createResource(string name); - double shareResources(double now); - virtual void adjustWeightOfDummyCpuActions(); - - void updateActionsState(double now, double delta); - - virtual ActionPtr executeParallelTask(int workstation_nb, - void **workstation_list, - double *computation_amount, - double *communication_amount, - double rate); - virtual xbt_dynar_t getRoute(WorkstationCLM03Ptr src, WorkstationCLM03Ptr dst); - virtual ActionPtr communicate(WorkstationCLM03Ptr src, WorkstationCLM03Ptr dst, double size, double rate); - CpuModelPtr p_cpuModel; -}; - -/************ - * Resource * - ************/ - -class WorkstationCLM03 : virtual public Resource { -public: - WorkstationCLM03(WorkstationModelPtr model, const char* name, xbt_dict_t properties, xbt_dynar_t storage, RoutingEdgePtr netElm, CpuPtr cpu); - - void updateState(tmgr_trace_event_t event_type, double value, double date); - - virtual ActionPtr execute(double size); - virtual ActionPtr sleep(double duration); - e_surf_resource_state_t getState(); - - virtual int getCore(); - virtual double getSpeed(double load); - virtual double getAvailableSpeed(); - virtual double getCurrentPowerPeak(); - virtual double getPowerPeakAt(int pstate_index); - virtual int getNbPstates(); - virtual void setPowerPeakAt(int pstate_index); - virtual double getConsumedEnergy(); - - xbt_dict_t getProperties(); - - StoragePtr findStorageOnMountList(const char* storage); - xbt_dict_t getStorageList(); - ActionPtr open(const char* mount, const char* path); - ActionPtr close(surf_file_t fd); - int unlink(surf_file_t fd); - ActionPtr ls(const char* mount, const char *path); - sg_size_t getSize(surf_file_t fd); - ActionPtr read(surf_file_t fd, sg_size_t size); - ActionPtr write(surf_file_t fd, sg_size_t size); - xbt_dynar_t getInfo( surf_file_t fd); - sg_size_t fileTell(surf_file_t fd); - sg_size_t getFreeSize(const char* name); - sg_size_t getUsedSize(const char* name); - int fileSeek(surf_file_t fd, sg_size_t offset, int origin); - - bool isUsed(); - //bool isShared(); - xbt_dynar_t p_storage; - RoutingEdgePtr p_netElm; - CpuPtr p_cpu; - NetworkLinkPtr p_network; - - xbt_dynar_t getVms(); - - /* common with vm */ - void getParams(ws_params_t params); - void setParams(ws_params_t params); - s_ws_params_t p_params; -}; - -class WorkstationCLM03Lmm : virtual public WorkstationCLM03, public ResourceLmm { -public: - WorkstationCLM03Lmm(WorkstationModelPtr model, const char* name, xbt_dict_t props, xbt_dynar_t storage, RoutingEdgePtr netElm, CpuPtr cpu): - WorkstationCLM03(model, name, props, storage, netElm, cpu){}; - e_surf_resource_state_t getState(); -}; - -/********** - * Action * - **********/ -class WorkstationAction : virtual public Action { -public: - WorkstationAction(ModelPtr model, double cost, bool failed): Action(model, cost, failed) {}; -}; - -class WorkstationActionLmm : public ActionLmm, public WorkstationAction { -public: - WorkstationActionLmm(ModelPtr model, double cost, bool failed): ActionLmm(model, cost, failed), WorkstationAction(model, cost, failed) {}; -}; - - -#endif /* WORKSTATION_HPP_ */ diff --git a/src/surf/workstation_clm03.cpp b/src/surf/workstation_clm03.cpp new file mode 100644 index 0000000000..dd7a23d1a6 --- /dev/null +++ b/src/surf/workstation_clm03.cpp @@ -0,0 +1,187 @@ +#include "workstation_clm03.hpp" +#include "vm_workstation_interface.hpp" +#include "cpu_cas01.hpp" +#include "simgrid/sg_config.h" + +XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_workstation); + +/************* + * CallBacks * + *************/ + +static void workstation_new(sg_platf_host_cbarg_t host){ + reinterpret_cast(surf_workstation_model)->createResource(host->id); +} + +/********* + * Model * + *********/ + +void surf_workstation_model_init_current_default(void) +{ + surf_workstation_model = new WorkstationCLM03Model(); + xbt_cfg_setdefault_boolean(_sg_cfg_set, "network/crosstraffic", "yes"); + surf_cpu_model_init_Cas01(); + surf_network_model_init_LegrandVelho(); + surf_workstation_model->p_cpuModel = surf_cpu_model_pm; + + ModelPtr model = static_cast(surf_workstation_model); + xbt_dynar_push(model_list, &model); + xbt_dynar_push(model_list_invoke, &model); + sg_platf_host_add_cb(workstation_new); +} + +void surf_workstation_model_init_compound() +{ + + xbt_assert(surf_cpu_model_pm, "No CPU model defined yet!"); + xbt_assert(surf_network_model, "No network model defined yet!"); + surf_workstation_model = new WorkstationCLM03Model(); + + ModelPtr model = static_cast(surf_workstation_model); + xbt_dynar_push(model_list, &model); + xbt_dynar_push(model_list_invoke, &model); + sg_platf_host_add_cb(workstation_new); +} + +WorkstationCLM03Model::WorkstationCLM03Model(string name) + : WorkstationModel(name) +{} + + +WorkstationCLM03Model::WorkstationCLM03Model() + : WorkstationModel("Workstation") +{ +} + +WorkstationCLM03Model::~WorkstationCLM03Model() +{} + +void WorkstationCLM03Model::parseInit(sg_platf_host_cbarg_t host){ + createResource(host->id); +} + +WorkstationPtr WorkstationCLM03Model::createResource(string name){ + + WorkstationPtr workstation = new WorkstationCLM03Lmm(surf_workstation_model, name.c_str(), NULL, + (xbt_dynar_t)xbt_lib_get_or_null(storage_lib, name.c_str(), ROUTING_STORAGE_HOST_LEVEL), + (RoutingEdgePtr)xbt_lib_get_or_null(host_lib, name.c_str(), ROUTING_HOST_LEVEL), + dynamic_cast(static_cast(xbt_lib_get_or_null(host_lib, name.c_str(), SURF_CPU_LEVEL)))); + XBT_DEBUG("Create workstation %s with %ld mounted disks", name.c_str(), xbt_dynar_length(workstation->p_storage)); + xbt_lib_set(host_lib, name.c_str(), SURF_WKS_LEVEL, static_cast(workstation)); + return workstation; +} + +double WorkstationCLM03Model::shareResources(double now){ + adjustWeightOfDummyCpuActions(); + + double min_by_cpu = p_cpuModel->shareResources(now); + double min_by_net = surf_network_model->shareResources(now); + double min_by_sto = -1; + if (p_cpuModel == surf_cpu_model_pm) + min_by_sto = surf_storage_model->shareResources(now); + + XBT_DEBUG("model %p, %s min_by_cpu %f, %s min_by_net %f, %s min_by_sto %f", + this, surf_cpu_model_pm->m_name.c_str(), min_by_cpu, + surf_network_model->m_name.c_str(), min_by_net, + surf_storage_model->m_name.c_str(), min_by_sto); + + double res = max(max(min_by_cpu, min_by_net), min_by_sto); + if (min_by_cpu >= 0.0 && min_by_cpu < res) + res = min_by_cpu; + if (min_by_net >= 0.0 && min_by_net < res) + res = min_by_net; + if (min_by_sto >= 0.0 && min_by_sto < res) + res = min_by_sto; + return res; +} + +void WorkstationCLM03Model::updateActionsState(double /*now*/, double /*delta*/){ + return; +} + +ActionPtr WorkstationCLM03Model::executeParallelTask(int workstation_nb, + void **workstation_list, + double *computation_amount, + double *communication_amount, + double rate){ +#define cost_or_zero(array,pos) ((array)?(array)[pos]:0.0) + if ((workstation_nb == 1) + && (cost_or_zero(communication_amount, 0) == 0.0)) + return ((WorkstationCLM03LmmPtr)workstation_list[0])->execute(computation_amount[0]); + else if ((workstation_nb == 1) + && (cost_or_zero(computation_amount, 0) == 0.0)) + return communicate((WorkstationCLM03LmmPtr)workstation_list[0], (WorkstationCLM03LmmPtr)workstation_list[0],communication_amount[0], rate); + else if ((workstation_nb == 2) + && (cost_or_zero(computation_amount, 0) == 0.0) + && (cost_or_zero(computation_amount, 1) == 0.0)) { + int i,nb = 0; + double value = 0.0; + + for (i = 0; i < workstation_nb * workstation_nb; i++) { + if (cost_or_zero(communication_amount, i) > 0.0) { + nb++; + value = cost_or_zero(communication_amount, i); + } + } + if (nb == 1) + return communicate((WorkstationCLM03LmmPtr)workstation_list[0], (WorkstationCLM03LmmPtr)workstation_list[1],value, rate); + } +#undef cost_or_zero + + THROW_UNIMPLEMENTED; /* This model does not implement parallel tasks */ + return NULL; +} + +/* returns an array of network_link_CM02_t */ +xbt_dynar_t WorkstationCLM03Model::getRoute(WorkstationPtr src, WorkstationPtr dst) +{ + XBT_DEBUG("ws_get_route"); + return surf_network_model->getRoute(src->p_netElm, dst->p_netElm); +} + +ActionPtr WorkstationCLM03Model::communicate(WorkstationPtr src, WorkstationPtr dst, double size, double rate){ + return surf_network_model->communicate(src->p_netElm, dst->p_netElm, size, rate); +} + + + +/************ + * Resource * + ************/ +WorkstationCLM03Lmm::WorkstationCLM03Lmm(WorkstationModelPtr model, const char* name, xbt_dict_t properties, xbt_dynar_t storage, RoutingEdgePtr netElm, CpuPtr cpu) + : Resource(model, name, properties), Workstation(storage, netElm, cpu) {} + +bool WorkstationCLM03Lmm::isUsed(){ + THROW_IMPOSSIBLE; /* This model does not implement parallel tasks */ + return -1; +} + +void WorkstationCLM03Lmm::updateState(tmgr_trace_event_t /*event_type*/, double /*value*/, double /*date*/){ + THROW_IMPOSSIBLE; /* This model does not implement parallel tasks */ +} + +ActionPtr WorkstationCLM03Lmm::execute(double size) { + return p_cpu->execute(size); +} + +ActionPtr WorkstationCLM03Lmm::sleep(double duration) { + return p_cpu->sleep(duration); +} + +e_surf_resource_state_t WorkstationCLM03Lmm::getState() { + return p_cpu->getState(); +} + + + + + + + + + + +/********** + * Action * + **********/ diff --git a/src/surf/workstation_clm03.hpp b/src/surf/workstation_clm03.hpp new file mode 100644 index 0000000000..08eb43e464 --- /dev/null +++ b/src/surf/workstation_clm03.hpp @@ -0,0 +1,80 @@ +#include "workstation_interface.hpp" +#include "storage_interface.hpp" +#include "cpu_interface.hpp" +#include "network_interface.hpp" + +#ifndef SURF_WORKSTATION_CLM03_HPP_ +#define SURF_WORKSTATION_CLM03_HPP_ + +/*********** + * Classes * + ***********/ + +class WorkstationCLM03Model; +typedef WorkstationCLM03Model *WorkstationCLM03ModelPtr; + +class WorkstationCLM03Lmm; +typedef WorkstationCLM03Lmm *WorkstationCLM03LmmPtr; + +class WorkstationCLM03ActionLmm; +typedef WorkstationCLM03ActionLmm *WorkstationCLM03ActionLmmPtr; + +/********* + * Model * + *********/ + +class WorkstationCLM03Model : virtual public WorkstationModel { +public: + WorkstationCLM03Model(string name); + WorkstationCLM03Model(); + ~WorkstationCLM03Model(); + void parseInit(sg_platf_host_cbarg_t host); + WorkstationPtr createResource(string name); + double shareResources(double now); + + void updateActionsState(double now, double delta); + + ActionPtr executeParallelTask(int workstation_nb, + void **workstation_list, + double *computation_amount, + double *communication_amount, + double rate); + xbt_dynar_t getRoute(WorkstationPtr src, WorkstationPtr dst); + ActionPtr communicate(WorkstationPtr src, WorkstationPtr dst, double size, double rate); +}; + +/************ + * Resource * + ************/ + +class WorkstationCLM03Lmm : public WorkstationLmm { +public: + WorkstationCLM03Lmm(WorkstationModelPtr model, const char* name, xbt_dict_t properties, xbt_dynar_t storage, RoutingEdgePtr netElm, CpuPtr cpu); + + void updateState(tmgr_trace_event_t event_type, double value, double date); + + virtual ActionPtr execute(double size); + virtual ActionPtr sleep(double duration); + e_surf_resource_state_t getState(); + + bool isUsed(); + + xbt_dynar_t getVms(); + + /* common with vm */ + void getParams(ws_params_t params); + void setParams(ws_params_t params); +}; + + +/********** + * Action * + **********/ + +class WorkstationCLM03ActionLmm : public WorkstationActionLmm { +public: + WorkstationCLM03ActionLmm(ModelPtr model, double cost, bool failed): Action(model, cost, failed), WorkstationActionLmm() {}; +}; + + +#endif /* SURF_WORKSTATION_CLM03_HPP_ */ diff --git a/src/surf/workstation_interface.cpp b/src/surf/workstation_interface.cpp new file mode 100644 index 0000000000..a834d3a7f9 --- /dev/null +++ b/src/surf/workstation_interface.cpp @@ -0,0 +1,315 @@ +#include "workstation_interface.hpp" +#include "vm_workstation_interface.hpp" +#include "cpu_cas01.hpp" +#include "simgrid/sg_config.h" + +extern "C" { +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_workstation, surf, + "Logging specific to the SURF workstation module"); +} + +WorkstationModelPtr surf_workstation_model = NULL; + +/********* + * Model * + *********/ +WorkstationModel::WorkstationModel(string name) + : Model(name) +{ + p_cpuModel = surf_cpu_model_pm; +} + +WorkstationModel::WorkstationModel() +: Model("Workstation") { + p_cpuModel = surf_cpu_model_pm; +} + +WorkstationModel::~WorkstationModel() { +} + + + +/* Each VM has a dummy CPU action on the PM layer. This CPU action works as the + * constraint (capacity) of the VM in the PM layer. If the VM does not have any + * active task, the dummy CPU action must be deactivated, so that the VM does + * not get any CPU share in the PM layer. */ +void WorkstationModel::adjustWeightOfDummyCpuActions() +{ + /* iterate for all hosts including virtual machines */ + xbt_lib_cursor_t cursor; + char *key; + void **ind_host; + + xbt_lib_foreach(host_lib, cursor, key, ind_host) { + WorkstationPtr ws = dynamic_cast( + static_cast(ind_host[SURF_WKS_LEVEL])); + CpuCas01LmmPtr cpu_cas01 = dynamic_cast( + static_cast(ind_host[SURF_CPU_LEVEL])); + + if (!ws) + continue; + /* skip if it is not a virtual machine */ + if (ws->p_model != static_cast(surf_vm_workstation_model)) + continue; + xbt_assert(cpu_cas01, "cpu-less workstation"); + + /* It is a virtual machine, so we can cast it to workstation_VM2013_t */ + WorkstationVMLmmPtr ws_vm = dynamic_cast(ws); + + int is_active = lmm_constraint_used(cpu_cas01->p_model->p_maxminSystem, cpu_cas01->p_constraint); + // int is_active_old = constraint_is_active(cpu_cas01); + + // { + // xbt_assert(is_active == is_active_old, "%d %d", is_active, is_active_old); + // } + + if (is_active) { + /* some tasks exist on this VM */ + XBT_DEBUG("set the weight of the dummy CPU action on PM to 1"); + + /* FIXME: we shoud use lmm_update_variable_weight() ? */ + /* FIXME: If we assgign 1.05 and 0.05, the system makes apparently wrong values. */ + ws_vm->p_action->setPriority(1); + + } else { + /* no task exits on this VM */ + XBT_DEBUG("set the weight of the dummy CPU action on PM to 0"); + + ws_vm->p_action->setPriority(0); + } + } +} + +/************ + * Resource * + ************/ +Workstation::Workstation(xbt_dynar_t storage, RoutingEdgePtr netElm, CpuPtr cpu) + : p_storage(storage), p_netElm(netElm), p_cpu(cpu) +{} + +int Workstation::getCore(){ + return p_cpu->getCore(); +} + +double Workstation::getSpeed(double load){ + return p_cpu->getSpeed(load); +} + +double Workstation::getAvailableSpeed(){ + return p_cpu->getAvailableSpeed(); +} + +double Workstation::getCurrentPowerPeak() +{ + return p_cpu->getCurrentPowerPeak(); +} + +double Workstation::getPowerPeakAt(int pstate_index) +{ + return p_cpu->getPowerPeakAt(pstate_index); +} + +int Workstation::getNbPstates() +{ + return p_cpu->getNbPstates(); +} + +void Workstation::setPowerPeakAt(int pstate_index) +{ + p_cpu->setPowerPeakAt(pstate_index); +} + +double Workstation::getConsumedEnergy() +{ + return p_cpu->getConsumedEnergy(); +} + +xbt_dict_t Workstation::getProperties() +{ + return p_cpu->m_properties; +} + + +StoragePtr Workstation::findStorageOnMountList(const char* mount) +{ + StoragePtr st = NULL; + s_mount_t mnt; + unsigned int cursor; + + XBT_DEBUG("Search for storage name '%s' on '%s'", mount, m_name); + xbt_dynar_foreach(p_storage,cursor,mnt) + { + XBT_DEBUG("See '%s'",mnt.name); + if(!strcmp(mount,mnt.name)){ + st = dynamic_cast(static_cast(mnt.storage)); + break; + } + } + if(!st) xbt_die("Can't find mount '%s' for '%s'", mount, m_name); + return st; +} + +xbt_dict_t Workstation::getStorageList() +{ + s_mount_t mnt; + unsigned int i; + xbt_dict_t storage_list = xbt_dict_new_homogeneous(NULL); + char *storage_name = NULL; + + xbt_dynar_foreach(p_storage,i,mnt){ + storage_name = (char *)dynamic_cast(static_cast(mnt.storage))->m_name; + xbt_dict_set(storage_list,mnt.name,storage_name,NULL); + } + return storage_list; +} + +ActionPtr Workstation::open(const char* mount, const char* path) { + StoragePtr st = findStorageOnMountList(mount); + XBT_DEBUG("OPEN on disk '%s'", st->m_name); + return st->open(mount, path); +} + +ActionPtr Workstation::close(surf_file_t fd) { + StoragePtr st = findStorageOnMountList(fd->mount); + XBT_DEBUG("CLOSE on disk '%s'",st->m_name); + return st->close(fd); +} + +ActionPtr Workstation::read(surf_file_t fd, sg_size_t size) { + StoragePtr st = findStorageOnMountList(fd->mount); + XBT_DEBUG("READ on disk '%s'",st->m_name); + return st->read(fd, size); +} + +ActionPtr Workstation::write(surf_file_t fd, sg_size_t size) { + StoragePtr st = findStorageOnMountList(fd->mount); + XBT_DEBUG("WRITE on disk '%s'",st->m_name); + return st->write(fd, size); +} + +int Workstation::unlink(surf_file_t fd) { + if (!fd){ + XBT_WARN("No such file descriptor. Impossible to unlink"); + return 0; + } else { +// XBT_INFO("%s %zu", fd->storage, fd->size); + StoragePtr st = findStorageOnMountList(fd->mount); + /* Check if the file is on this storage */ + if (!xbt_dict_get_or_null(st->p_content, fd->name)){ + XBT_WARN("File %s is not on disk %s. Impossible to unlink", fd->name, + st->m_name); + return 0; + } else { + XBT_DEBUG("UNLINK on disk '%s'",st->m_name); + st->m_usedSize -= fd->size; + + // Remove the file from storage + xbt_dict_remove(st->p_content, fd->name); + + free(fd->name); + free(fd->mount); + xbt_free(fd); + return 1; + } + } +} + +ActionPtr Workstation::ls(const char* mount, const char *path){ + XBT_DEBUG("LS on mount '%s' and file '%s'", mount, path); + StoragePtr st = findStorageOnMountList(mount); + return st->ls(path); +} + +sg_size_t Workstation::getSize(surf_file_t fd){ + return fd->size; +} + +xbt_dynar_t Workstation::getInfo( surf_file_t fd) +{ + StoragePtr st = findStorageOnMountList(fd->mount); + sg_size_t *psize = xbt_new(sg_size_t, 1); + *psize = fd->size; + xbt_dynar_t info = xbt_dynar_new(sizeof(void*), NULL); + xbt_dynar_push_as(info, sg_size_t *, psize); + xbt_dynar_push_as(info, void *, fd->mount); + xbt_dynar_push_as(info, void *, (void *)st->m_name); + xbt_dynar_push_as(info, void *, st->p_typeId); + xbt_dynar_push_as(info, void *, st->p_contentType); + + return info; +} + +sg_size_t Workstation::fileTell(surf_file_t fd){ + return fd->current_position; +} + +int Workstation::fileSeek(surf_file_t fd, sg_size_t offset, int origin){ + + switch (origin) { + case SEEK_SET: + fd->current_position = 0; + return MSG_OK; + case SEEK_CUR: + if(offset > fd->size) + offset = fd->size; + fd->current_position = offset; + return MSG_OK; + case SEEK_END: + fd->current_position = fd->size; + return MSG_OK; + default: + return MSG_TASK_CANCELED; + } +} + +sg_size_t Workstation::getFreeSize(const char* name) +{ + StoragePtr st = findStorageOnMountList(name); + return st->m_size - st->m_usedSize; +} + +sg_size_t Workstation::getUsedSize(const char* name) +{ + StoragePtr st = findStorageOnMountList(name); + return st->m_usedSize; +} + +xbt_dynar_t Workstation::getVms() +{ + xbt_dynar_t dyn = xbt_dynar_new(sizeof(smx_host_t), NULL); + + /* iterate for all hosts including virtual machines */ + xbt_lib_cursor_t cursor; + char *key; + void **ind_host; + xbt_lib_foreach(host_lib, cursor, key, ind_host) { + WorkstationPtr ws = dynamic_cast(static_cast(ind_host[SURF_WKS_LEVEL])); + if (!ws) + continue; + /* skip if it is not a virtual machine */ + if (ws->p_model != static_cast(surf_vm_workstation_model)) + continue; + + /* It is a virtual machine, so we can cast it to workstation_VM2013_t */ + WorkstationVMPtr ws_vm = dynamic_cast(ws); + if (this == ws_vm-> p_subWs) + xbt_dynar_push(dyn, &ws_vm->p_subWs); + } + + return dyn; +} + +void Workstation::getParams(ws_params_t params) +{ + memcpy(params, &p_params, sizeof(s_ws_params_t)); +} + +void Workstation::setParams(ws_params_t params) +{ + /* may check something here. */ + memcpy(&p_params, params, sizeof(s_ws_params_t)); +} + +/********** + * Action * + **********/ diff --git a/src/surf/workstation_interface.hpp b/src/surf/workstation_interface.hpp new file mode 100644 index 0000000000..307d2d6c1e --- /dev/null +++ b/src/surf/workstation_interface.hpp @@ -0,0 +1,124 @@ +#include "surf_interface.hpp" +#include "storage_interface.hpp" +#include "cpu_interface.hpp" +#include "network_interface.hpp" + +#ifndef SURF_WORKSTATION_INTERFACE_HPP_ +#define SURF_WORKSTATION_INTERFACE_HPP_ + +/*********** + * Classes * + ***********/ + +class WorkstationModel; +typedef WorkstationModel *WorkstationModelPtr; + +class Workstation; +typedef Workstation *WorkstationPtr; + +class WorkstationLmm; +typedef WorkstationLmm *WorkstationLmmPtr; + +class WorkstationAction; +typedef WorkstationAction *WorkstationActionPtr; + +class WorkstationActionLmm; +typedef WorkstationActionLmm *WorkstationActionLmmPtr; + +/********* + * Tools * + *********/ +extern WorkstationModelPtr surf_workstation_model; + +/********* + * Model * + *********/ +class WorkstationModel : public Model { +public: + WorkstationModel(string name); + WorkstationModel(); + ~WorkstationModel(); + virtual void adjustWeightOfDummyCpuActions(); + + virtual ActionPtr executeParallelTask(int workstation_nb, + void **workstation_list, + double *computation_amount, + double *communication_amount, + double rate)=0; + virtual xbt_dynar_t getRoute(WorkstationPtr src, WorkstationPtr dst)=0; + virtual ActionPtr communicate(WorkstationPtr src, WorkstationPtr dst, double size, double rate)=0; + + CpuModelPtr p_cpuModel; +}; + +/************ + * Resource * + ************/ + +class Workstation : virtual public Resource { +public: + Workstation(){}; + Workstation(xbt_dynar_t storage, RoutingEdgePtr netElm, CpuPtr cpu); + + xbt_dict_t getProperties(); + + virtual ActionPtr execute(double size)=0; + virtual ActionPtr sleep(double duration)=0; + + virtual int getCore(); + virtual double getSpeed(double load); + virtual double getAvailableSpeed(); + virtual double getCurrentPowerPeak(); + virtual double getPowerPeakAt(int pstate_index); + virtual int getNbPstates(); + virtual void setPowerPeakAt(int pstate_index); + virtual double getConsumedEnergy(); + + virtual StoragePtr findStorageOnMountList(const char* storage); + virtual xbt_dict_t getStorageList(); + virtual ActionPtr open(const char* mount, const char* path); + virtual ActionPtr close(surf_file_t fd); + virtual int unlink(surf_file_t fd); + virtual ActionPtr ls(const char* mount, const char *path); + virtual sg_size_t getSize(surf_file_t fd); + virtual ActionPtr read(surf_file_t fd, sg_size_t size); + virtual ActionPtr write(surf_file_t fd, sg_size_t size); + virtual xbt_dynar_t getInfo( surf_file_t fd); + virtual sg_size_t fileTell(surf_file_t fd); + virtual sg_size_t getFreeSize(const char* name); + virtual sg_size_t getUsedSize(const char* name); + virtual int fileSeek(surf_file_t fd, sg_size_t offset, int origin); + + xbt_dynar_t p_storage; + RoutingEdgePtr p_netElm; + CpuPtr p_cpu; + NetworkLinkPtr p_network; + + xbt_dynar_t getVms(); + + /* common with vm */ + void getParams(ws_params_t params); + void setParams(ws_params_t params); + s_ws_params_t p_params; +}; + +class WorkstationLmm : virtual public Workstation, public ResourceLmm { +public: + WorkstationLmm() {}; +}; + +/********** + * Action * + **********/ +class WorkstationAction : virtual public Action { +public: + WorkstationAction() {}; +}; + +class WorkstationActionLmm : public ActionLmm, public WorkstationAction { +public: + WorkstationActionLmm(): ActionLmm(), WorkstationAction() {}; +}; + + +#endif /* SURF_WORKSTATION_INTERFACE_HPP_ */ diff --git a/src/surf/workstation_ptask_L07.cpp b/src/surf/workstation_ptask_L07.cpp index 926990f758..cb864ab474 100644 --- a/src/surf/workstation_ptask_L07.cpp +++ b/src/surf/workstation_ptask_L07.cpp @@ -121,7 +121,7 @@ void WorkstationL07Model::updateActionsState(double /*now*/, double delta) i++))) { constraint_id = lmm_constraint_id(cnst); - if (static_cast(constraint_id)->p_stateCurrent == SURF_RESOURCE_OFF) { + if (static_cast(constraint_id)->p_stateCurrent == SURF_RESOURCE_OFF) { XBT_DEBUG("Action (%p) Failed!!", action); action->m_finish = surf_get_clock(); action->setState(SURF_ACTION_FAILED); @@ -194,7 +194,7 @@ ActionPtr WorkstationL07Model::executeParallelTask(int workstation_nb, action->m_suspended = 0; /* Should be useless because of the calloc but it seems to help valgrind... */ action->m_workstationNb = workstation_nb; - action->p_workstationList = (WorkstationCLM03Ptr *) workstation_list; + action->p_workstationList = (WorkstationPtr *) workstation_list; action->p_computationAmount = computation_amount; action->p_communicationAmount = communication_amount; action->m_latency = latency; @@ -266,7 +266,7 @@ ResourcePtr WorkstationL07Model::createResource(const char *name, double /*power return wk;//FIXME:xbt_lib_get_elm_or_null(host_lib, name); } -ActionPtr WorkstationL07Model::communicate(WorkstationCLM03Ptr src, WorkstationCLM03Ptr dst, +ActionPtr WorkstationL07Model::communicate(WorkstationPtr src, WorkstationPtr dst, double size, double rate) { void **workstation_list = xbt_new0(void *, 2); @@ -285,7 +285,7 @@ ActionPtr WorkstationL07Model::communicate(WorkstationCLM03Ptr src, WorkstationC return res; } -xbt_dynar_t WorkstationL07Model::getRoute(WorkstationCLM03Ptr src, WorkstationCLM03Ptr dst) +xbt_dynar_t WorkstationL07Model::getRoute(WorkstationPtr src, WorkstationPtr dst) { xbt_dynar_t route=NULL; routing_platf->getRouteAndLatency(src->p_netElm, dst->p_netElm, &route, NULL); @@ -441,8 +441,8 @@ void WorkstationL07Model::addTraces() WorkstationL07::WorkstationL07(WorkstationModelPtr model, const char* name, xbt_dict_t props, RoutingEdgePtr netElm, CpuPtr cpu) : Resource(model, name, props), - WorkstationCLM03(model, name, props, NULL, netElm, cpu), - WorkstationCLM03Lmm(model, name, props, NULL, netElm, cpu) + Workstation(NULL, netElm, cpu), + WorkstationLmm() { } diff --git a/src/surf/workstation_ptask_L07.hpp b/src/surf/workstation_ptask_L07.hpp index eef274c826..d999f1df02 100644 --- a/src/surf/workstation_ptask_L07.hpp +++ b/src/surf/workstation_ptask_L07.hpp @@ -1,4 +1,4 @@ -#include "workstation.hpp" +#include "workstation_interface.hpp" #ifndef WORKSTATION_L07_HPP_ #define WORKSTATION_L07_HPP_ @@ -53,8 +53,8 @@ public: double *computation_amount, double *communication_amount, double rate); - xbt_dynar_t getRoute(WorkstationCLM03Ptr src, WorkstationCLM03Ptr dst); - ActionPtr communicate(WorkstationCLM03Ptr src, WorkstationCLM03Ptr dst, double size, double rate); + xbt_dynar_t getRoute(WorkstationPtr src, WorkstationPtr dst); + ActionPtr communicate(WorkstationPtr src, WorkstationPtr dst, double size, double rate); void addTraces(); NetworkModelPtr p_networkModel; }; @@ -89,7 +89,7 @@ public: e_surf_link_sharing_policy_t policy, xbt_dict_t properties); - xbt_dynar_t getRoute(WorkstationCLM03Ptr /*src*/, WorkstationCLM03Ptr /*dst*/) {DIE_IMPOSSIBLE;}; + xbt_dynar_t getRoute(WorkstationPtr /*src*/, WorkstationPtr /*dst*/) {DIE_IMPOSSIBLE;}; ActionPtr communicate(RoutingEdgePtr /*src*/, RoutingEdgePtr /*dst*/, double /*size*/, double /*rate*/) {DIE_IMPOSSIBLE;}; void addTraces() {DIE_IMPOSSIBLE;}; WorkstationL07ModelPtr p_workstationModel; @@ -99,7 +99,7 @@ public: * Resource * ************/ -class WorkstationL07 : public WorkstationCLM03Lmm { +class WorkstationL07 : public WorkstationLmm { public: WorkstationL07(WorkstationModelPtr model, const char* name, xbt_dict_t props, RoutingEdgePtr netElm, CpuPtr cpu); //bool isUsed(); @@ -158,7 +158,7 @@ public: class WorkstationL07ActionLmm : public WorkstationActionLmm { public: WorkstationL07ActionLmm(ModelPtr model, double cost, bool failed) - : Action(model, cost, failed), WorkstationActionLmm(model, cost, failed) {}; + : Action(model, cost, failed), WorkstationActionLmm() {}; ~WorkstationL07ActionLmm(); void updateBound(); @@ -173,7 +173,7 @@ public: double getRemains(); int m_workstationNb; - WorkstationCLM03Ptr *p_workstationList; + WorkstationPtr *p_workstationList; double *p_computationAmount; double *p_communicationAmount; double m_latency; -- 2.20.1