Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
CpuCas01 in C++
[simgrid.git] / src / surf / cpu.cpp
1 #include "cpu.hpp"
2
3 //TODO: resolve dependencies
4 static int TRACE_is_enabled(void) {return 0;}
5 static void TRACE_surf_host_set_utilization(const char *resource,
6                                      const char *category,
7                                      double value,
8                                      double now,
9                                      double delta){}
10 static double TRACE_last_timestamp_to_dump = 0;
11
12 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surfpp_cpu, surfpp,
13                                 "Logging specific to the SURF cpu module");
14
15
16 /*********
17  * Model *
18  *********/
19
20 void CpuModel::updateActionsStateLazy(double now, double delta)
21 {
22   void *_action;
23   ActionLmmPtr action;
24   while ((xbt_heap_size(p_actionHeap) > 0)
25          && (double_equals(xbt_heap_maxkey(p_actionHeap), now))) {
26     action = (ActionLmmPtr) xbt_heap_pop(p_actionHeap);
27     XBT_DEBUG("Something happened to action %p", action);
28 #ifdef HAVE_TRACING
29     if (TRACE_is_enabled()) {
30       CpuPtr cpu = (CpuPtr) lmm_constraint_id(lmm_get_cnst_from_var(p_maxminSystem, action->p_variable, 0));
31       TRACE_surf_host_set_utilization(cpu->m_name, action->p_category,
32                                       lmm_variable_getvalue(action->p_variable),
33                                       action->m_lastUpdate,
34                                       now - action->m_lastUpdate);
35     }
36 #endif
37
38     action->m_finish = surf_get_clock();
39     XBT_DEBUG("Action %p finished", action);
40
41     /* set the remains to 0 due to precision problems when updating the remaining amount */
42     action->m_remains = 0;
43     action->setState(SURF_ACTION_DONE);
44     action->heapRemove(p_actionHeap); //FIXME: strange call since action was already popped
45   }
46 #ifdef HAVE_TRACING
47   if (TRACE_is_enabled()) {
48     //defining the last timestamp that we can safely dump to trace file
49     //without losing the event ascending order (considering all CPU's)
50     double smaller = -1;
51     xbt_swag_foreach(_action, p_runningActionSet) {
52       action = (ActionLmmPtr) _action;
53         if (smaller < 0) {
54           smaller = action->m_lastUpdate;
55           continue;
56         }
57         if (action->m_lastUpdate < smaller) {
58           smaller = action->m_lastUpdate;
59         }
60     }
61     if (smaller > 0) {
62       TRACE_last_timestamp_to_dump = smaller;
63     }
64   }
65 #endif
66   return;
67 }
68
69 void CpuModel::updateActionsStateFull(double now, double delta)
70 {
71   void *_action, *_next_action;
72   ActionLmmPtr action = NULL;
73   ActionLmmPtr next_action = NULL;
74   xbt_swag_t running_actions = p_runningActionSet;
75
76   xbt_swag_foreach_safe(_action, _next_action, running_actions) {
77     action = (ActionLmmPtr) _action;
78 #ifdef HAVE_TRACING
79     if (TRACE_is_enabled()) {
80       CpuPtr x = (CpuPtr) lmm_constraint_id(lmm_get_cnst_from_var
81                               (p_maxminSystem, action->p_variable, 0));
82
83       TRACE_surf_host_set_utilization(x->m_name,
84                                       action->p_category,
85                                       lmm_variable_getvalue(action->p_variable),
86                                       now - delta,
87                                       delta);
88       TRACE_last_timestamp_to_dump = now - delta;
89     }
90 #endif
91
92     double_update(&(action->m_remains),
93                   lmm_variable_getvalue(action->p_variable) * delta);
94
95
96     if (action->m_maxDuration != NO_MAX_DURATION)
97       double_update(&(action->m_maxDuration), delta);
98
99
100     if ((action->m_remains <= 0) &&
101         (lmm_get_variable_weight(action->p_variable) > 0)) {
102       action->m_finish = surf_get_clock();
103       action->setState(SURF_ACTION_DONE);
104
105     } else if ((action->m_maxDuration != NO_MAX_DURATION) &&
106                (action->m_maxDuration <= 0)) {
107       action->m_finish = surf_get_clock();
108       action->setState(SURF_ACTION_DONE);
109     }
110   }
111
112   return;
113 }
114
115 /************
116  * Resource *
117  ************/
118
119 double Cpu::getSpeed(double load)
120 {
121   return load * m_powerPeak;
122 }
123
124 double Cpu::getAvailableSpeed()
125 {
126 /* number between 0 and 1 */
127   return m_powerScale;
128 }
129
130 int Cpu::getCore()
131 {
132   return m_core;
133 }
134
135 /**********
136  * Action *
137  **********/
138
139 void CpuActionLmm::updateRemainingLazy(double now)
140 {
141   double delta = 0.0;
142
143   xbt_assert(p_stateSet == p_model->p_runningActionSet,
144       "You're updating an action that is not running.");
145
146   /* bogus priority, skip it */
147   xbt_assert(m_priority > 0,
148       "You're updating an action that seems suspended.");
149
150   delta = now - m_lastUpdate;
151
152   if (m_remains > 0) {
153     XBT_DEBUG("Updating action(%p): remains was %lf, last_update was: %lf", this, m_remains, m_lastUpdate);
154     double_update(&(m_remains), m_lastValue * delta);
155
156 #ifdef HAVE_TRACING
157     if (TRACE_is_enabled()) {
158       CpuPtr cpu = (CpuPtr) lmm_constraint_id(lmm_get_cnst_from_var(p_model->p_maxminSystem, p_variable, 0));
159       TRACE_surf_host_set_utilization(cpu->m_name, p_category, m_lastValue, m_lastUpdate, now - m_lastUpdate);
160     }
161 #endif
162     XBT_DEBUG("Updating action(%p): remains is now %lf", this, m_remains);
163   }
164
165   m_lastUpdate = now;
166   m_lastValue = lmm_variable_getvalue(p_variable);
167 }