X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/efb4f45908f62882ef6ebd34742f29d079d99736..ad0262690dd5803f9dd716e4278bbb485083138f:/src/surf/surf_interface.hpp diff --git a/src/surf/surf_interface.hpp b/src/surf/surf_interface.hpp index b28e1c0aa3..f243cac497 100644 --- a/src/surf/surf_interface.hpp +++ b/src/surf/surf_interface.hpp @@ -1,4 +1,8 @@ -//using namespace generic; +/* Copyright (c) 2004-2014. The SimGrid Team. + * All rights reserved. */ + +/* This program is free software; you can redistribute it and/or modify it + * under the terms of the license (GNU LGPL) which comes with this package. */ #ifndef SURF_MODEL_H_ #define SURF_MODEL_H_ @@ -6,27 +10,34 @@ #include #include #include -#include #include #include +#include #include "surf/trace_mgr.h" #include "xbt/lib.h" #include "surf/surf_routing.h" #include "simgrid/platf_interface.h" #include "surf/surf.h" #include "surf/surf_private.h" +#include "internal_config.h" + +#ifdef LIBSIGC +#include +#define surf_callback(arg1, ...) sigc::signal +#define surf_callback_connect(callback, fun_ptr) callback.connect(sigc::ptr_fun(fun_ptr)) +#define surf_callback_emit(callback, ...) callback.emit(__VA_ARGS__) +#else +#include +#define surf_callback(arg1, ...) boost::signals2::signal +#define surf_callback_connect(callback, fun_ptr) callback.connect(fun_ptr) +#define surf_callback_emit(callback, ...) callback(__VA_ARGS__) +#endif extern tmgr_history_t history; #define NO_MAX_DURATION -1.0 using namespace std; -/** \ingroup SURF_simulation - * \brief Return the current time - * - * Return the current time in millisecond. - */ - /********* * Utils * *********/ @@ -49,26 +60,23 @@ XBT_PUBLIC(double) surf_get_clock(void); } extern double sg_sender_gap; -XBT_PUBLIC(int) SURF_CPU_LEVEL; //Surf cpu level + +extern surf_callback(void, void) surfExitCallbacks; int __surf_is_absolute_file_path(const char *file_path); /*********** * Classes * ***********/ -//class Model; -typedef Model* ModelPtr; +typedef boost::intrusive::list ActionList; +typedef ActionList* ActionListPtr; +typedef boost::intrusive::list_base_hook<> actionHook; -//class Resource; -typedef Resource* ResourcePtr; -typedef boost::function ResourceCallback; - -//class Action; -typedef Action* ActionPtr; -typedef boost::function ActionCallback; +struct lmmTag; +typedef boost::intrusive::list > > > ActionLmmList; +typedef ActionLmmList* ActionLmmListPtr; +typedef boost::intrusive::list_base_hook > actionLmmHook; -//class ActionLmm; -typedef ActionLmm* ActionLmmPtr; enum heap_action_type{ LATENCY = 100, @@ -84,252 +92,460 @@ enum heap_action_type{ XBT_PUBLIC_DATA(xbt_dict_t) traces_set_list; XBT_PUBLIC_DATA(xbt_dict_t) trace_connect_list_host_avail; XBT_PUBLIC_DATA(xbt_dict_t) trace_connect_list_power; -XBT_PUBLIC_DATA(xbt_dict_t) trace_connect_list_link_avail; -XBT_PUBLIC_DATA(xbt_dict_t) trace_connect_list_bandwidth; +XBT_PUBLIC_DATA(xbt_dict_t) trace_connect_list_link_avail; +XBT_PUBLIC_DATA(xbt_dict_t) trace_connect_list_bandwidth; XBT_PUBLIC_DATA(xbt_dict_t) trace_connect_list_latency; - /********* * Model * *********/ XBT_PUBLIC_DATA(xbt_dynar_t) model_list; -class Model { +/** @ingroup SURF_interface + * @brief SURF model interface class + * @details A model is an object which handle the interactions between its Resources and its Actions + */ +XBT_PUBLIC_CLASS Model { public: - Model(string name); + /** + * @brief Model constructor + * + * @param name the name of the model + */ + Model(const char *name); + + /** + * @brief Model destructor + */ virtual ~Model(); - //ResourcePtr createResource(string name); - ActionPtr createAction(double _cost, bool _failed); + virtual void addTraces() =0; + + /** + * @brief Get the name of the current Model + * + * @return The name of the current Model + */ + const char *getName() {return p_name;} + + /** + * @brief Get the set of [actions](@ref Action) in *ready* state + * + * @return The set of [actions](@ref Action) in *ready* state + */ + virtual ActionListPtr getReadyActionSet() {return p_readyActionSet;} + + /** + * @brief Get the set of [actions](@ref Action) in *running* state + * + * @return The set of [actions](@ref Action) in *running* state + */ + virtual ActionListPtr getRunningActionSet() {return p_runningActionSet;} + + /** + * @brief Get the set of [actions](@ref Action) in *failed* state + * + * @return The set of [actions](@ref Action) in *failed* state + */ + virtual ActionListPtr getFailedActionSet() {return p_failedActionSet;} + + /** + * @brief Get the set of [actions](@ref Action) in *done* state + * + * @return The set of [actions](@ref Action) in *done* state + */ + virtual ActionListPtr getDoneActionSet() {return p_doneActionSet;} + + /** + * @brief Get the set of modified [actions](@ref Action) + * + * @return The set of modified [actions](@ref Action) + */ + virtual ActionLmmListPtr getModifiedSet() {return p_modifiedSet;} + + /** + * @brief Get the maxmin system of the current Model + * + * @return The maxmin system of the current Model + */ + lmm_system_t getMaxminSystem() {return p_maxminSystem;} + + /** + * @brief Get the update mechanism of the current Model + * @see e_UM_t + * + * @return [description] + */ + e_UM_t getUpdateMechanism() {return p_updateMechanism;} + + /** + * @brief Get Action heap + * @details [TODO] + * + * @return The Action heap + */ + xbt_heap_t getActionHeap() {return p_actionHeap;} + + /** + * @brief share the resources + * @details Share the resources between the actions + * + * @param now The current time of the simulation + * @return The delta of time till the next action will finish + */ virtual double shareResources(double now); virtual double shareResourcesLazy(double now); virtual double shareResourcesFull(double now); - double shareResourcesMaxMin(xbt_swag_t running_actions, + double shareResourcesMaxMin(ActionListPtr running_actions, lmm_system_t sys, void (*solve) (lmm_system_t)); + + /** + * @brief Update state of actions + * @details Update action to the current time + * + * @param now The current time of the simulation + * @param delta The delta of time since the last update + */ virtual void updateActionsState(double now, double delta); virtual void updateActionsStateLazy(double now, double delta); virtual void updateActionsStateFull(double now, double delta); - string getName() {return m_name;}; - - void addTurnedOnCallback(ResourceCallback rc); - void notifyResourceTurnedOn(ResourcePtr r); - - void addTurnedOffCallback(ResourceCallback rc); - void notifyResourceTurnedOff(ResourcePtr r); - - void addActionCancelCallback(ActionCallback ac); - void notifyActionCancel(ActionPtr a); - void addActionResumeCallback(ActionCallback ac); - void notifyActionResume(ActionPtr a); - void addActionSuspendCallback(ActionCallback ac); - void notifyActionSuspend(ActionPtr a); - +protected: + ActionLmmListPtr p_modifiedSet; lmm_system_t p_maxminSystem; e_UM_t p_updateMechanism; - xbt_swag_t p_modifiedSet; - xbt_heap_t p_actionHeap; int m_selectiveUpdate; - - xbt_swag_t p_readyActionSet; /**< Actions in state SURF_ACTION_READY */ - xbt_swag_t p_runningActionSet; /**< Actions in state SURF_ACTION_RUNNING */ - xbt_swag_t p_failedActionSet; /**< Actions in state SURF_ACTION_FAILED */ - xbt_swag_t p_doneActionSet; /**< Actions in state SURF_ACTION_DONE */ - string m_name; - -protected: - std::vector m_failedActions, m_runningActions; + xbt_heap_t p_actionHeap; private: - ResourceCallback m_resOnCB, m_resOffCB; - ActionCallback m_actCancelCB, m_actSuspendCB, m_actResumeCB; + const char *p_name; + + ActionListPtr p_readyActionSet; /**< Actions in state SURF_ACTION_READY */ + ActionListPtr p_runningActionSet; /**< Actions in state SURF_ACTION_RUNNING */ + ActionListPtr p_failedActionSet; /**< Actions in state SURF_ACTION_FAILED */ + ActionListPtr p_doneActionSet; /**< Actions in state SURF_ACTION_DONE */ }; /************ * Resource * ************/ -/** - * Resource which have a metric handled by a maxmin system +/** @ingroup SURF_interface + * @brief Resource which have a metric handled by a maxmin system */ typedef struct { - double scale; - double peak; - tmgr_trace_event_t event; + double scale; /**< The scale of the metric */ + double peak; /**< The peak of the metric */ + tmgr_trace_event_t event; /**< The associated trace event associated to the metric */ } s_surf_metric_t; -class Resource { +/** @ingroup SURF_interface + * @brief SURF resource interface class + * @details A resource represent an element of a component (e.g.: a link for the network) + */ +XBT_PUBLIC_CLASS Resource { public: + /** + * @brief Resource constructor + */ Resource(); - Resource(ModelPtr model, const char *name, xbt_dict_t properties); - virtual ~Resource() { - xbt_free((void*)m_name); - xbt_dict_free(&m_properties); - }; + /** + * @brief Resource constructor + * + * @param model Model associated to this Resource + * @param name The name of the Resource + * @param props Dictionary of properties associated to this Resource + */ + Resource(Model *model, const char *name, xbt_dict_t props); + + /** + * @brief Resource constructor + * + * @param model Model associated to this Resource + * @param name The name of the Resource + * @param props Dictionary of properties associated to this Resource + * @param constraint The lmm constraint associated to this Resource if it is part of a LMM component + */ + Resource(Model *model, const char *name, xbt_dict_t props, lmm_constraint_t constraint); + /** + * @brief Resource constructor + * + * @param model Model associated to this Resource + * @param name The name of the Resource + * @param props Dictionary of properties associated to this Resource + * @param stateInit the initial state of the Resource + */ + Resource(Model *model, const char *name, xbt_dict_t props, e_surf_resource_state_t stateInit); + + /** + * @brief Resource destructor + */ + virtual ~Resource(); + + /** + * @brief Get the Model of the current Resource + * + * @return The Model of the current Resource + */ + Model *getModel(); + + /** + * @brief Get the name of the current Resource + * + * @return The name of the current Resource + */ + const char *getName(); + + /** + * @brief Get the properties of the current Resource + * + * @return The properties of the current Resource + */ + virtual xbt_dict_t getProperties(); + + /** + * @brief Update the state of the current Resource + * @details [TODO] + * + * @param event_type [TODO] + * @param value [TODO] + * @param date [TODO] + */ virtual void updateState(tmgr_trace_event_t event_type, double value, double date)=0; - //private + /** + * @brief Check if the current Resource is used + * @return true if the current Resource is used, false otherwise + */ virtual bool isUsed()=0; - //FIXME:updateActionState(); - //FIXME:updateResourceState(); - //FIXME:finilize(); + /** + * @brief Check if the current Resource is active + * + * @return true if the current Resource is active, false otherwise + */ bool isOn(); + + /** + * @brief Turn on the current Resource + */ void turnOn(); + + /** + * @brief Turn off the current Resource + */ void turnOff(); - void setName(string name); - const char *getName(); - virtual xbt_dict_t getProperties(); - ModelPtr getModel() {return p_model;}; + /** + * @brief Get the [state](\ref e_surf_resource_state_t) of the current Resource + * + * @return The state of the currenrt Resource + */ virtual e_surf_resource_state_t getState(); - virtual void setState(e_surf_resource_state_t state); - void printModel() { std::cout << p_model->getName() << "<