From 07890d9a4285a1d6e4151210ed7b6df8e6b32a67 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Thu, 21 Jan 2016 16:07:28 +0100 Subject: [PATCH] First round of refactoring in the event trace stuff - Rename various data types and function parameters to make their purpose clear - More to come: A class hierarchy is to be discovered in these messy bits --- src/include/surf/datatypes.h | 4 +- src/include/surf/trace_mgr.h | 14 +++--- src/surf/cpu_cas01.cpp | 6 +-- src/surf/cpu_cas01.hpp | 10 ++--- src/surf/cpu_ti.cpp | 2 +- src/surf/cpu_ti.hpp | 6 +-- src/surf/host_interface.hpp | 2 +- src/surf/host_ptask_L07.cpp | 4 +- src/surf/host_ptask_L07.hpp | 10 ++--- src/surf/network_cm02.cpp | 20 ++++----- src/surf/network_cm02.hpp | 4 +- src/surf/network_interface.cpp | 2 +- src/surf/network_interface.hpp | 6 +-- src/surf/network_ns3.cpp | 2 +- src/surf/network_ns3.hpp | 2 +- src/surf/storage_interface.cpp | 2 +- src/surf/storage_interface.hpp | 2 +- src/surf/surf_c_bindings.cpp | 4 +- src/surf/surf_interface.cpp | 2 +- src/surf/surf_interface.hpp | 6 +-- src/surf/surf_private.h | 2 +- src/surf/trace_mgr.c | 56 ++++++++++++------------ src/surf/trace_mgr_private.h | 10 +++-- teshsuite/surf/trace_usage/trace_usage.c | 2 +- 24 files changed, 90 insertions(+), 90 deletions(-) diff --git a/src/include/surf/datatypes.h b/src/include/surf/datatypes.h index 23b9a78661..8e704e710e 100644 --- a/src/include/surf/datatypes.h +++ b/src/include/surf/datatypes.h @@ -16,8 +16,8 @@ typedef struct lmm_constraint *lmm_constraint_t; typedef struct lmm_constraint_light *lmm_constraint_light_t; typedef struct lmm_system *lmm_system_t; -typedef struct tmgr_history *tmgr_history_t; -typedef struct tmgr_trace_event *tmgr_trace_event_t; +typedef struct tmgr_fes *tmgr_fes_t; +typedef struct tmgr_trace_iterator *tmgr_trace_iterator_t; #endif /* MAXMIN_DATATYPES_H */ diff --git a/src/include/surf/trace_mgr.h b/src/include/surf/trace_mgr.h index 62cf3acabc..2598b77677 100644 --- a/src/include/surf/trace_mgr.h +++ b/src/include/surf/trace_mgr.h @@ -16,8 +16,8 @@ SG_BEGIN_DECL() /* Creation functions */ -XBT_PUBLIC(tmgr_history_t) tmgr_history_new(void); -XBT_PUBLIC(void) tmgr_history_free(tmgr_history_t history); +XBT_PUBLIC(tmgr_fes_t) tmgr_history_new(void); +XBT_PUBLIC(void) tmgr_history_free(tmgr_fes_t history); XBT_PUBLIC(tmgr_trace_t) tmgr_empty_trace_new(void); XBT_PUBLIC(void) tmgr_trace_free(tmgr_trace_t trace); @@ -28,9 +28,9 @@ XBT_PUBLIC(void) tmgr_trace_free(tmgr_trace_t trace); * \param trace_event Trace event structure * \return 1 if the structure was freed, 0 otherwise */ -XBT_PUBLIC(int) tmgr_trace_event_free(tmgr_trace_event_t trace_event); +XBT_PUBLIC(int) tmgr_trace_event_free(tmgr_trace_iterator_t trace_event); -XBT_PUBLIC(tmgr_trace_event_t) tmgr_history_add_trace(tmgr_history_t +XBT_PUBLIC(tmgr_trace_iterator_t) tmgr_history_add_trace(tmgr_fes_t history, tmgr_trace_t trace, double start_time, @@ -38,9 +38,9 @@ XBT_PUBLIC(tmgr_trace_event_t) tmgr_history_add_trace(tmgr_history_t void *model); /* Access functions */ -XBT_PUBLIC(double) tmgr_history_next_date(tmgr_history_t history); -XBT_PUBLIC(tmgr_trace_event_t) - tmgr_history_get_next_event_leq(tmgr_history_t history, double date, +XBT_PUBLIC(double) tmgr_history_next_date(tmgr_fes_t history); +XBT_PUBLIC(tmgr_trace_iterator_t) + tmgr_history_get_next_event_leq(tmgr_fes_t history, double date, double *value, void **model); XBT_PUBLIC(void) tmgr_finalize(void); diff --git a/src/surf/cpu_cas01.cpp b/src/surf/cpu_cas01.cpp index 246b4f180f..5c7bc6e4be 100644 --- a/src/surf/cpu_cas01.cpp +++ b/src/surf/cpu_cas01.cpp @@ -166,12 +166,12 @@ CpuCas01::~CpuCas01() xbt_dynar_free(&p_speedPeakList); } -void CpuCas01::setStateEvent(tmgr_trace_event_t stateEvent) +void CpuCas01::setStateEvent(tmgr_trace_iterator_t stateEvent) { p_stateEvent = stateEvent; } -void CpuCas01::setPowerEvent(tmgr_trace_event_t powerEvent) +void CpuCas01::setPowerEvent(tmgr_trace_iterator_t powerEvent) { p_speedEvent = powerEvent; } @@ -204,7 +204,7 @@ void CpuCas01::onSpeedChange() { Cpu::onSpeedChange(); } -void CpuCas01::updateState(tmgr_trace_event_t event_type, double value, double date) +void CpuCas01::updateState(tmgr_trace_iterator_t event_type, double value, double date) { lmm_variable_t var = NULL; lmm_element_t elem = NULL; diff --git a/src/surf/cpu_cas01.hpp b/src/surf/cpu_cas01.hpp index b7564d7883..04d2896ccc 100644 --- a/src/surf/cpu_cas01.hpp +++ b/src/surf/cpu_cas01.hpp @@ -47,13 +47,13 @@ public: int pstate, double speedScale, tmgr_trace_t speedTrace, int core, int initiallyOn, tmgr_trace_t stateTrace) ; ~CpuCas01(); - void updateState(tmgr_trace_event_t event_type, double value, double date) override; + void updateState(tmgr_trace_iterator_t event_type, double value, double date) override; CpuAction *execute(double size) override; CpuAction *sleep(double duration) override; bool isUsed() override; - void setStateEvent(tmgr_trace_event_t stateEvent); - void setPowerEvent(tmgr_trace_event_t stateEvent); + void setStateEvent(tmgr_trace_iterator_t stateEvent); + void setPowerEvent(tmgr_trace_iterator_t stateEvent); xbt_dynar_t getSpeedPeakList(); // FIXME: killme to hide our internals @@ -62,8 +62,8 @@ protected: private: - tmgr_trace_event_t p_stateEvent; - tmgr_trace_event_t p_speedEvent; + tmgr_trace_iterator_t p_stateEvent; + tmgr_trace_iterator_t p_speedEvent; }; /********** diff --git a/src/surf/cpu_ti.cpp b/src/surf/cpu_ti.cpp index 4847691f26..2c5499c1b5 100644 --- a/src/surf/cpu_ti.cpp +++ b/src/surf/cpu_ti.cpp @@ -588,7 +588,7 @@ CpuTi::~CpuTi() delete p_actionSet; } -void CpuTi::updateState(tmgr_trace_event_t event_type, +void CpuTi::updateState(tmgr_trace_iterator_t event_type, double value, double date) { CpuTiAction *action; diff --git a/src/surf/cpu_ti.hpp b/src/surf/cpu_ti.hpp index 56156334ec..6bcbcdccb9 100644 --- a/src/surf/cpu_ti.hpp +++ b/src/surf/cpu_ti.hpp @@ -118,7 +118,7 @@ public: int initiallyOn, tmgr_trace_t stateTrace) ; ~CpuTi(); - void updateState(tmgr_trace_event_t event_type, double value, double date) override; + void updateState(tmgr_trace_iterator_t event_type, double value, double date) override; void updateActionsFinishTime(double now); bool isUsed() override; CpuAction *execute(double size) override; @@ -128,8 +128,8 @@ public: void modified(bool modified); CpuTiTgmr *p_availTrace; /*< Structure with data needed to integrate trace file */ - tmgr_trace_event_t p_stateEvent = NULL; /*< trace file with states events (ON or OFF) */ - tmgr_trace_event_t p_speedEvent = NULL; /*< trace file with availability events */ + tmgr_trace_iterator_t p_stateEvent = NULL; /*< trace file with states events (ON or OFF) */ + tmgr_trace_iterator_t p_speedEvent = NULL; /*< trace file with availability events */ ActionTiList *p_actionSet; /*< set with all actions running on cpu */ double m_sumPriority; /*< the sum of actions' priority that are running on cpu */ double m_lastUpdate = 0; /*< last update of actions' remaining amount done */ diff --git a/src/surf/host_interface.hpp b/src/surf/host_interface.hpp index d861c9bb1b..ce2c066a52 100644 --- a/src/surf/host_interface.hpp +++ b/src/surf/host_interface.hpp @@ -229,7 +229,7 @@ public: virtual int fileMove(surf_file_t fd, const char* fullpath); bool isUsed() override {DIE_IMPOSSIBLE;} // FIXME: Host should not be a Resource - void updateState(tmgr_trace_event_t event_type, double value, double date) override + void updateState(tmgr_trace_iterator_t event_type, double value, double date) override {THROW_IMPOSSIBLE;} // FIXME: Host should not be a Resource public: diff --git a/src/surf/host_ptask_L07.cpp b/src/surf/host_ptask_L07.cpp index 38b1709101..c202f98310 100644 --- a/src/surf/host_ptask_L07.cpp +++ b/src/surf/host_ptask_L07.cpp @@ -504,7 +504,7 @@ bool LinkL07::isUsed(){ return lmm_constraint_used(getModel()->getMaxminSystem(), getConstraint()); } -void CpuL07::updateState(tmgr_trace_event_t event_type, double value, double /*date*/){ +void CpuL07::updateState(tmgr_trace_iterator_t event_type, double value, double /*date*/){ XBT_DEBUG("Updating cpu %s (%p) with value %g", getName(), this, value); if (event_type == p_speedEvent) { m_speedScale = value; @@ -525,7 +525,7 @@ void CpuL07::updateState(tmgr_trace_event_t event_type, double value, double /*d return; } -void LinkL07::updateState(tmgr_trace_event_t event_type, double value, double date) { +void LinkL07::updateState(tmgr_trace_iterator_t event_type, double value, double date) { XBT_DEBUG("Updating link %s (%p) with value=%f for date=%g", getName(), this, value, date); if (event_type == p_bwEvent) { updateBandwidth(value, date); diff --git a/src/surf/host_ptask_L07.hpp b/src/surf/host_ptask_L07.hpp index 0e69ef8a63..89d109f414 100644 --- a/src/surf/host_ptask_L07.hpp +++ b/src/surf/host_ptask_L07.hpp @@ -94,15 +94,15 @@ public: class CpuL07 : public Cpu { friend void HostL07Model::addTraces(); - tmgr_trace_event_t p_stateEvent; - tmgr_trace_event_t p_speedEvent; + tmgr_trace_iterator_t p_stateEvent; + tmgr_trace_iterator_t p_speedEvent; public: CpuL07(CpuL07Model *model, simgrid::s4u::Host *host, xbt_dynar_t speedPeakList, int pstate, double power_scale, tmgr_trace_t power_trace, int core, int initiallyOn, tmgr_trace_t state_trace); ~CpuL07(); bool isUsed() override; - void updateState(tmgr_trace_event_t event_type, double value, double date) override; + void updateState(tmgr_trace_iterator_t event_type, double value, double date) override; Action *execute(double size) override; Action *sleep(double duration) override; protected: @@ -121,13 +121,13 @@ public: e_surf_link_sharing_policy_t policy); ~LinkL07(){ }; bool isUsed() override; - void updateState(tmgr_trace_event_t event_type, double value, double date) override; + void updateState(tmgr_trace_iterator_t event_type, double value, double date) override; double getBandwidth() override; void updateBandwidth(double value, double date=surf_get_clock()) override; void updateLatency(double value, double date=surf_get_clock()) override; double m_bwCurrent; - tmgr_trace_event_t p_bwEvent; + tmgr_trace_iterator_t p_bwEvent; }; /********** diff --git a/src/surf/network_cm02.cpp b/src/surf/network_cm02.cpp index 719dd52f39..1432ccd633 100644 --- a/src/surf/network_cm02.cpp +++ b/src/surf/network_cm02.cpp @@ -515,7 +515,7 @@ void NetworkCm02Model::addTraces(){ NetworkCm02Link::NetworkCm02Link(NetworkCm02Model *model, const char *name, xbt_dict_t props, lmm_system_t system, double constraint_value, - tmgr_history_t history, + tmgr_fes_t history, int initiallyOn, tmgr_trace_t state_trace, double metric_peak, @@ -547,22 +547,20 @@ NetworkCm02Link::NetworkCm02Link(NetworkCm02Model *model, const char *name, xbt_ -void NetworkCm02Link::updateState(tmgr_trace_event_t event_type, +void NetworkCm02Link::updateState(tmgr_trace_iterator_t triggered, double value, double date) { - /* printf("[" "%g" "] Asking to update network card \"%s\" with value " */ - /* "%g" " for event %p\n", surf_get_clock(), nw_link->name, */ - /* value, event_type); */ - if (event_type == p_speed.event) { + /* Find out which of my iterators was triggered, and react accordingly */ + if (triggered == p_speed.event) { updateBandwidth(value, date); - if (tmgr_trace_event_free(event_type)) + if (tmgr_trace_event_free(triggered)) p_speed.event = NULL; - } else if (event_type == p_latEvent) { + } else if (triggered == p_latEvent) { updateLatency(value, date); - if (tmgr_trace_event_free(event_type)) + if (tmgr_trace_event_free(triggered)) p_latEvent = NULL; - } else if (event_type == p_stateEvent) { + } else if (triggered == p_stateEvent) { if (value > 0) turnOn(); else { @@ -581,7 +579,7 @@ void NetworkCm02Link::updateState(tmgr_trace_event_t event_type, } } } - if (tmgr_trace_event_free(event_type)) + if (tmgr_trace_event_free(triggered)) p_stateEvent = NULL; } else { XBT_CRITICAL("Unknown event ! \n"); diff --git a/src/surf/network_cm02.hpp b/src/surf/network_cm02.hpp index 25b4de53ec..c9f3e1c2e4 100644 --- a/src/surf/network_cm02.hpp +++ b/src/surf/network_cm02.hpp @@ -75,7 +75,7 @@ public: NetworkCm02Link(NetworkCm02Model *model, const char *name, xbt_dict_t props, lmm_system_t system, double constraint_value, - tmgr_history_t history, + tmgr_fes_t history, int initiallyOn, tmgr_trace_t state_trace, double metric_peak, @@ -83,7 +83,7 @@ public: double lat_initial, tmgr_trace_t lat_trace, e_surf_link_sharing_policy_t policy); - void updateState(tmgr_trace_event_t event_type, double value, double date) override; + void updateState(tmgr_trace_iterator_t event_type, double value, double date) override; void updateBandwidth(double value, double date=surf_get_clock()) override; void updateLatency(double value, double date=surf_get_clock()) override; virtual void gapAppend(double /*size*/, const Link* /*link*/, NetworkAction * /*action*/) {}; diff --git a/src/surf/network_interface.cpp b/src/surf/network_interface.cpp index 4376384ba6..321c0d83e3 100644 --- a/src/surf/network_interface.cpp +++ b/src/surf/network_interface.cpp @@ -201,7 +201,7 @@ Link::Link(simgrid::surf::NetworkModel *model, const char *name, xbt_dict_t prop Link::Link(simgrid::surf::NetworkModel *model, const char *name, xbt_dict_t props, lmm_constraint_t constraint, - tmgr_history_t history, + tmgr_fes_t history, tmgr_trace_t state_trace) : Resource(model, name, constraint), PropertyHolder(props) diff --git a/src/surf/network_interface.hpp b/src/surf/network_interface.hpp index 6696895b1b..16f4ef773a 100644 --- a/src/surf/network_interface.hpp +++ b/src/surf/network_interface.hpp @@ -190,7 +190,7 @@ public: */ Link(simgrid::surf::NetworkModel *model, const char *name, xbt_dict_t props, lmm_constraint_t constraint, - tmgr_history_t history, + tmgr_fes_t history, tmgr_trace_t state_trace); /* Link destruction logic */ @@ -240,10 +240,10 @@ public: /* Using this object with the public part of model does not make sense */ double m_latCurrent = 0; - tmgr_trace_event_t p_latEvent = NULL; + tmgr_trace_iterator_t p_latEvent = NULL; /* LMM */ - tmgr_trace_event_t p_stateEvent = NULL; + tmgr_trace_iterator_t p_stateEvent = NULL; s_surf_metric_t p_speed; /* User data */ diff --git a/src/surf/network_ns3.cpp b/src/surf/network_ns3.cpp index 474c88bd94..7a62ae1ce9 100644 --- a/src/surf/network_ns3.cpp +++ b/src/surf/network_ns3.cpp @@ -428,7 +428,7 @@ NetworkNS3Link::~NetworkNS3Link() { } -void NetworkNS3Link::updateState(tmgr_trace_event_t event_type, double value, double date) +void NetworkNS3Link::updateState(tmgr_trace_iterator_t event_type, double value, double date) { } diff --git a/src/surf/network_ns3.hpp b/src/surf/network_ns3.hpp index 55c36b5f1a..1fea2d7bfa 100644 --- a/src/surf/network_ns3.hpp +++ b/src/surf/network_ns3.hpp @@ -70,7 +70,7 @@ public: double bw_initial, double lat_initial); ~NetworkNS3Link(); - void updateState(tmgr_trace_event_t event_type, double value, double date); + void updateState(tmgr_trace_iterator_t event_type, double value, double date); double getLatency(){THROW_UNIMPLEMENTED;} double getBandwidth(){THROW_UNIMPLEMENTED;} void updateBandwidth(double value, double date=surf_get_clock()){THROW_UNIMPLEMENTED;} diff --git a/src/surf/storage_interface.cpp b/src/surf/storage_interface.cpp index d0d1cb98ee..62fe89eae9 100644 --- a/src/surf/storage_interface.cpp +++ b/src/surf/storage_interface.cpp @@ -140,7 +140,7 @@ bool Storage::isUsed() return false; } -void Storage::updateState(tmgr_trace_event_t /*event_type*/, double /*value*/, double /*date*/) +void Storage::updateState(tmgr_trace_iterator_t /*event_type*/, double /*value*/, double /*date*/) { THROW_UNIMPLEMENTED; } diff --git a/src/surf/storage_interface.hpp b/src/surf/storage_interface.hpp index d81510bc2b..01bbf940ce 100644 --- a/src/surf/storage_interface.hpp +++ b/src/surf/storage_interface.hpp @@ -147,7 +147,7 @@ public: * @param value [description] * @param date [description] */ - void updateState(tmgr_trace_event_t event_type, double value, double date) override; + void updateState(tmgr_trace_iterator_t event_type, double value, double date) override; void turnOn() override; void turnOff() override; diff --git a/src/surf/surf_c_bindings.cpp b/src/surf/surf_c_bindings.cpp index 8b71301867..69dd67f74e 100644 --- a/src/surf/surf_c_bindings.cpp +++ b/src/surf/surf_c_bindings.cpp @@ -31,7 +31,7 @@ extern double NOW; void surf_presolve(void) { double next_event_date = -1.0; - tmgr_trace_event_t event = NULL; + tmgr_trace_iterator_t event = NULL; double value = -1.0; simgrid::surf::Resource *resource = NULL; simgrid::surf::Model *model = NULL; @@ -64,7 +64,7 @@ double surf_solve(double max_date) double value = -1.0; simgrid::surf::Resource *resource = NULL; simgrid::surf::Model *model = NULL; - tmgr_trace_event_t event = NULL; + tmgr_trace_iterator_t event = NULL; unsigned int iter; if(!host_that_restart) diff --git a/src/surf/surf_interface.cpp b/src/surf/surf_interface.cpp index 6497396107..bc4da64678 100644 --- a/src/surf/surf_interface.cpp +++ b/src/surf/surf_interface.cpp @@ -29,7 +29,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_kernel, surf, xbt_dynar_t all_existing_models = NULL; /* to destroy models correctly */ xbt_dynar_t model_list_invoke = NULL; /* for invoking callbacks */ -tmgr_history_t history = NULL; +tmgr_fes_t history = NULL; lmm_system_t maxmin_system = NULL; xbt_dynar_t surf_path = NULL; xbt_dynar_t host_that_restart = NULL; diff --git a/src/surf/surf_interface.hpp b/src/surf/surf_interface.hpp index f450f3bd2e..951e4f20ca 100644 --- a/src/surf/surf_interface.hpp +++ b/src/surf/surf_interface.hpp @@ -25,7 +25,7 @@ #include "src/surf/surf_private.h" #include "src/internal_config.h" -extern XBT_PRIVATE tmgr_history_t history; +extern XBT_PRIVATE tmgr_fes_t history; #define NO_MAX_DURATION -1.0 /********* @@ -366,7 +366,7 @@ private: typedef struct { double peak; /**< The peak of the metric, ie its max value */ double scale; /**< Current availability of the metric according to the traces, in [0,1] */ - tmgr_trace_event_t event; /**< The associated trace event associated to the metric */ + tmgr_trace_iterator_t event; /**< The associated trace event associated to the metric */ } s_surf_metric_t; namespace simgrid { @@ -422,7 +422,7 @@ public: * @param value [TODO] * @param date [TODO] */ - virtual void updateState(tmgr_trace_event_t event_type, double value, double date)=0; + virtual void updateState(tmgr_trace_iterator_t event_type, double value, double date)=0; /** @brief Check if the current Resource is used (if it currently serves an action) */ virtual bool isUsed()=0; diff --git a/src/surf/surf_private.h b/src/surf/surf_private.h index aa79814f73..730bcc7250 100644 --- a/src/surf/surf_private.h +++ b/src/surf/surf_private.h @@ -42,7 +42,7 @@ typedef enum { XBT_PRIVATE FILE *surf_fopen(const char *name, const char *mode); -extern XBT_PRIVATE tmgr_history_t history; +extern XBT_PRIVATE tmgr_fes_t history; /* The __surf_is_absolute_file_path() returns 1 if * file_path is a absolute file path, in the other diff --git a/src/surf/trace_mgr.c b/src/surf/trace_mgr.c index 47f1b29e97..03f5ef4e98 100644 --- a/src/surf/trace_mgr.c +++ b/src/surf/trace_mgr.c @@ -17,9 +17,9 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_trace, surf, "Surf trace management"); static xbt_dict_t trace_list = NULL; -XBT_INLINE tmgr_history_t tmgr_history_new(void) +XBT_INLINE tmgr_fes_t tmgr_history_new(void) { - tmgr_history_t h; + tmgr_fes_t h; h = xbt_new0(s_tmgr_history_t, 1); @@ -28,7 +28,7 @@ XBT_INLINE tmgr_history_t tmgr_history_new(void) return h; } -XBT_INLINE void tmgr_history_free(tmgr_history_t h) +XBT_INLINE void tmgr_history_free(tmgr_fes_t h) { xbt_heap_free(h->heap); free(h); @@ -383,29 +383,29 @@ XBT_INLINE void tmgr_trace_free(tmgr_trace_t trace) free(trace); } -tmgr_trace_event_t tmgr_history_add_trace(tmgr_history_t h, +tmgr_trace_iterator_t tmgr_history_add_trace(tmgr_fes_t h, tmgr_trace_t trace, double start_time, unsigned int offset, void *model) { - tmgr_trace_event_t trace_event = NULL; + tmgr_trace_iterator_t trace_iterator = NULL; - trace_event = xbt_new0(s_tmgr_trace_event_t, 1); - trace_event->trace = trace; - trace_event->idx = offset; - trace_event->model = model; + trace_iterator = xbt_new0(s_tmgr_trace_event_t, 1); + trace_iterator->trace = trace; + trace_iterator->idx = offset; + trace_iterator->model = model; if(trace->type == e_trace_list) { - xbt_assert((trace_event->idx < xbt_dynar_length(trace->s_list.event_list)), + xbt_assert((trace_iterator->idx < xbt_dynar_length(trace->s_list.event_list)), "You're referring to an event that does not exist!"); } - xbt_heap_push(h->heap, trace_event, start_time); + xbt_heap_push(h->heap, trace_iterator, start_time); - return trace_event; + return trace_iterator; } -XBT_INLINE double tmgr_history_next_date(tmgr_history_t h) +XBT_INLINE double tmgr_history_next_date(tmgr_fes_t h) { if (xbt_heap_size(h->heap)) return (xbt_heap_maxkey(h->heap)); @@ -413,13 +413,13 @@ XBT_INLINE double tmgr_history_next_date(tmgr_history_t h) return -1.0; } -tmgr_trace_event_t tmgr_history_get_next_event_leq(tmgr_history_t h, +tmgr_trace_iterator_t tmgr_history_get_next_event_leq(tmgr_fes_t h, double date, double *value, void **model) { double event_date = tmgr_history_next_date(h); - tmgr_trace_event_t trace_event = NULL; + tmgr_trace_iterator_t trace_iterator = NULL; tmgr_event_t event = NULL; tmgr_trace_t trace = NULL; double event_delta; @@ -427,27 +427,27 @@ tmgr_trace_event_t tmgr_history_get_next_event_leq(tmgr_history_t h, if (event_date > date) return NULL; - if (!(trace_event = xbt_heap_pop(h->heap))) + if (!(trace_iterator = xbt_heap_pop(h->heap))) return NULL; - trace = trace_event->trace; - *model = trace_event->model; + trace = trace_iterator->trace; + *model = trace_iterator->model; switch(trace->type) { case e_trace_list: - event = xbt_dynar_get_ptr(trace->s_list.event_list, trace_event->idx); + event = xbt_dynar_get_ptr(trace->s_list.event_list, trace_iterator->idx); *value = event->value; - if (trace_event->idx < xbt_dynar_length(trace->s_list.event_list) - 1) { - xbt_heap_push(h->heap, trace_event, event_date + event->delta); - trace_event->idx++; + if (trace_iterator->idx < xbt_dynar_length(trace->s_list.event_list) - 1) { + xbt_heap_push(h->heap, trace_iterator, event_date + event->delta); + trace_iterator->idx++; } else if (event->delta > 0) { /* Last element, checking for periodicity */ - xbt_heap_push(h->heap, trace_event, event_date + event->delta); - trace_event->idx = 1; /* not 0 as the first event is a placeholder to handle when events really start */ + xbt_heap_push(h->heap, trace_iterator, event_date + event->delta); + trace_iterator->idx = 1; /* not 0 as the first event is a placeholder to handle when events really start */ } else { /* We don't need this trace_event anymore */ - trace_event->free_me = 1; + trace_iterator->free_me = 1; } break; @@ -467,13 +467,13 @@ tmgr_trace_event_t tmgr_history_get_next_event_leq(tmgr_history_t h, event_delta = tmgr_event_generator_next_value(trace->s_probabilist.event_generator[0]); *value = tmgr_event_generator_next_value(trace->s_probabilist.event_generator[1]); } - xbt_heap_push(h->heap, trace_event, event_date + event_delta); + xbt_heap_push(h->heap, trace_iterator, event_date + event_delta); XBT_DEBUG("Generating a new event at date %f, with value %f", event_date + event_delta, *value); break; } - return trace_event; + return trace_iterator; } XBT_INLINE void tmgr_finalize(void) @@ -481,7 +481,7 @@ XBT_INLINE void tmgr_finalize(void) xbt_dict_free(&trace_list); } -int tmgr_trace_event_free(tmgr_trace_event_t trace_event) +int tmgr_trace_event_free(tmgr_trace_iterator_t trace_event) { if (trace_event->free_me) { xbt_free(trace_event); diff --git a/src/surf/trace_mgr_private.h b/src/surf/trace_mgr_private.h index a84a6385d8..184d9980c0 100644 --- a/src/surf/trace_mgr_private.h +++ b/src/surf/trace_mgr_private.h @@ -59,16 +59,18 @@ typedef struct tmgr_trace { }; } s_tmgr_trace_t; - -typedef struct tmgr_trace_event { +/* Iterator within a trace */ +typedef struct tmgr_trace_iterator { tmgr_trace_t trace; unsigned int idx; void *model; int free_me; } s_tmgr_trace_event_t; -typedef struct tmgr_history { - xbt_heap_t heap; +/* Future Event Set (collection of iterators over the traces) + * That's useful to quickly know which is the next occurring event in a set of traces. */ +typedef struct tmgr_fes { + xbt_heap_t heap; /* Content: only trace_events */ } s_tmgr_history_t; XBT_PRIVATE double tmgr_event_generator_next_value(probabilist_event_generator_t generator); diff --git a/teshsuite/surf/trace_usage/trace_usage.c b/teshsuite/surf/trace_usage/trace_usage.c index 2fd2157048..06450c7704 100644 --- a/teshsuite/surf/trace_usage/trace_usage.c +++ b/teshsuite/surf/trace_usage/trace_usage.c @@ -21,7 +21,7 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(surf_test, void test(void); void test(void) { - tmgr_history_t history = tmgr_history_new(); + tmgr_fes_t history = tmgr_history_new(); tmgr_trace_t trace_A = tmgr_trace_new_from_file("trace_A.txt"); tmgr_trace_t trace_B = tmgr_trace_new_from_file("trace_B.txt"); double next_event_date = -1.0; -- 2.20.1