- surf_action_cpu_Cas01_t action;
- while ((xbt_heap_size(cpu_action_heap) > 0)
- && (double_equals(xbt_heap_maxkey(cpu_action_heap), now))) {
- action = xbt_heap_pop(cpu_action_heap);
- XBT_DEBUG("Action %p: finish", action);
- GENERIC_ACTION(action).finish = surf_get_clock();
- /* set the remains to 0 due to precision problems when updating the remaining amount */
-#ifdef HAVE_TRACING
- if (TRACE_is_enabled()) {
- cpu_Cas01_t cpu = ((cpu_Cas01_t)(action->cpu));
- TRACE_surf_host_set_utilization(cpu->generic_resource.name,
- GENERIC_LMM_ACTION(action).generic_action.data,
- (surf_action_t) action,
- lmm_variable_getvalue (GENERIC_LMM_ACTION(action).variable),
- cpu->last_update,
- now - cpu->last_update);
- }
-#endif
- GENERIC_ACTION(action).remains = 0;
- cpu_cpu_action_state_set((surf_action_t) action, SURF_ACTION_DONE);
- cpu_update_remains(action->cpu, surf_get_clock());
- }
-#ifdef HAVE_TRACING
- if (TRACE_is_enabled()) {
- //defining the last timestamp that we can safely dump to trace file
- //without losing the event ascending order (considering all CPU's)
- void **data;
- cpu_Cas01_t cpu;
- xbt_lib_cursor_t cursor;
- char *key;
- double smaller = -1;
- xbt_lib_foreach(host_lib, cursor, key, data){
- if(data[SURF_CPU_LEVEL]){
- cpu = data[SURF_CPU_LEVEL];
- if (smaller < 0){
- smaller = cpu->last_update;
- continue;
- }
- if (cpu->last_update < smaller){
- smaller = cpu->last_update;
- }
- }
- }
- if (smaller > 0) {
- TRACE_last_timestamp_to_dump = smaller;
- }
- }
-#endif
- return;
+ xbt_dynar_t power_range_list = cpu_model->energy->power_range_watts_list;
+
+ if (power_range_list == NULL)
+ {
+ XBT_DEBUG("No power range properties specified for host %s", cpu_model->generic_resource.name);
+ return 0;
+ }
+ xbt_assert(xbt_dynar_length(power_range_list) == xbt_dynar_length(cpu_model->power_peak_list),
+ "The number of power ranges in the properties does not match the number of pstates for host %s",
+ cpu_model->generic_resource.name);
+
+ /* retrieve the power values associated with the current pstate */
+ xbt_dynar_t current_power_values = xbt_dynar_get_as(power_range_list, cpu_model->pstate, xbt_dynar_t);
+
+ /* min_power corresponds to the idle power (cpu load = 0) */
+ /* max_power is the power consumed at 100% cpu load */
+ double min_power = xbt_dynar_get_as(current_power_values, 0, double);
+ double max_power = xbt_dynar_get_as(current_power_values, 1, double);
+ double power_slope = max_power - min_power;
+
+ double current_power = min_power + cpu_load * power_slope;
+
+ XBT_DEBUG("[get_current_watts] min_power=%f, max_power=%f, slope=%f", min_power, max_power, power_slope);
+ XBT_DEBUG("[get_current_watts] Current power (watts) = %f, load = %f", current_power, cpu_load);
+
+ return current_power;
+