Logo AND Algorithmique Numérique Distribuée

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