Logo AND Algorithmique Numérique Distribuée

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