Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
CpuCas01 in C++
[simgrid.git] / src / surf / network.cpp
1 #include "network.hpp"
2
3 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surfpp_network, surfpp,
4                                 "Logging specific to the SURF network module");
5
6 //TODO: resolve dependencies
7 static int TRACE_is_enabled(void) {return 0;}
8 static void TRACE_surf_host_set_utilization(const char *resource,
9                                      const char *category,
10                                      double value,
11                                      double now,
12                                      double delta){}
13 static void TRACE_surf_link_set_utilization(const char *resource,
14                                      const char *category,
15                                      double value,
16                                      double now,
17                                      double delta){}
18 static double TRACE_last_timestamp_to_dump = 0;
19
20 /*********
21  * Utils *
22  *********/
23
24 static xbt_dict_t gap_lookup = NULL;//TODO: remove static
25
26 /*********
27  * Model *
28  *********/
29
30 void NetworkModel::updateActionsStateLazy(double now, double delta)
31 {
32   NetworkCm02ActionLmmPtr action;
33   while ((xbt_heap_size(p_actionHeap) > 0)
34          && (double_equals(xbt_heap_maxkey(p_actionHeap), now))) {
35     action = (NetworkCm02ActionLmmPtr) xbt_heap_pop(p_actionHeap);
36     XBT_DEBUG("Something happened to action %p", action);
37 #ifdef HAVE_TRACING
38     if (TRACE_is_enabled()) {
39       int n = lmm_get_number_of_cnst_from_var(p_maxminSystem, action->p_variable);
40       unsigned int i;
41       for (i = 0; i < n; i++){
42         lmm_constraint_t constraint = lmm_get_cnst_from_var(p_maxminSystem,
43                                                             action->p_variable,
44                                                             i);
45         NetworkCm02LinkPtr link = (NetworkCm02LinkPtr) lmm_constraint_id(constraint);
46         TRACE_surf_link_set_utilization(link->m_name,
47                                         action->p_category,
48                                         (lmm_variable_getvalue(action->p_variable)*
49                                             lmm_get_cnst_weight_from_var(p_maxminSystem,
50                                                 action->p_variable,
51                                                 i)),
52                                         action->m_lastUpdate,
53                                         now - action->m_lastUpdate);
54       }
55     }
56 #endif
57
58     // if I am wearing a latency hat
59     if (action->m_hat == LATENCY) {
60       XBT_DEBUG("Latency paid for action %p. Activating", action);
61       lmm_update_variable_weight(p_maxminSystem, action->p_variable, action->m_weight);
62       action->heapRemove(p_actionHeap);
63       action->m_lastUpdate = surf_get_clock();
64
65         // if I am wearing a max_duration or normal hat
66     } else if (action->m_hat == MAX_DURATION ||
67         action->m_hat == NORMAL) {
68         // no need to communicate anymore
69         // assume that flows that reached max_duration have remaining of 0
70       action->m_finish = surf_get_clock();
71       XBT_DEBUG("Action %p finished", action);
72       action->m_remains = 0;
73       action->m_finish = surf_get_clock();
74       action->setState(SURF_ACTION_DONE);
75       action->heapRemove(p_actionHeap);
76
77       gapRemove(action);
78     }
79   }
80   return;
81 }
82
83 void NetworkModel::gapRemove(ActionLmmPtr lmm_action)
84 {
85   xbt_fifo_t fifo;
86   size_t size;
87   NetworkCm02ActionLmmPtr action = (NetworkCm02ActionLmmPtr)lmm_action;
88
89   if (sg_sender_gap > 0.0 && action->p_senderLinkName
90       && action->p_senderFifoItem) {
91     fifo =
92         (xbt_fifo_t) xbt_dict_get_or_null(gap_lookup,
93                                           action->p_senderLinkName);
94     xbt_fifo_remove_item(fifo, action->p_senderFifoItem);
95     size = xbt_fifo_size(fifo);
96     if (size == 0) {
97       xbt_fifo_free(fifo);
98       xbt_dict_remove(gap_lookup, action->p_senderLinkName);
99       size = xbt_dict_length(gap_lookup);
100       if (size == 0) {
101         xbt_dict_free(&gap_lookup);
102       }
103     }
104   }
105 }
106
107 /************
108  * Resource *
109  ************/
110
111 /**********
112  * Action *
113  **********/
114 void NetworkCm02ActionLmm::updateRemainingLazy(double now)
115 {
116   double delta = 0.0;
117
118   if (m_suspended != 0)
119     return;
120
121   delta = now - m_lastUpdate;
122
123   if (m_remains > 0) {
124     XBT_DEBUG("Updating action(%p): remains was %lf, last_update was: %lf", this, m_remains, m_lastUpdate);
125     double_update(&(m_remains), m_lastValue * delta);
126
127     XBT_DEBUG("Updating action(%p): remains is now %lf", this, m_remains);
128   }
129
130   if (m_maxDuration != NO_MAX_DURATION)
131     double_update(&m_maxDuration, delta);
132
133   if (m_remains <= 0 &&
134       (lmm_get_variable_weight(p_variable) > 0)) {
135     m_finish = surf_get_clock();
136     setState(SURF_ACTION_DONE);
137
138     heapRemove(p_model->p_actionHeap);
139   } else if (((m_maxDuration != NO_MAX_DURATION)
140       && (m_maxDuration <= 0))) {
141     m_finish = surf_get_clock();
142     setState(SURF_ACTION_DONE);
143     heapRemove(p_model->p_actionHeap);
144   }
145
146   m_lastUpdate = now;
147   m_lastValue = lmm_variable_getvalue(p_variable);
148 }
149