+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(cpu, surf,
+ "Logging specific to the SURF CPU module");
+
+surf_cpu_resource_t surf_cpu_resource = NULL;
+
+static xbt_dict_t cpu_set = NULL;
+
+static void cpu_free(void *CPU)
+{
+/* cpu_t cpu = CPU; */
+/* lmm_constraint_free(maxmin_system,cpu->constraint); */
+/* Clean somewhere else ! */
+
+ xbt_free(CPU);
+}
+
+/* power_scale is the basic power of the cpu when the cpu is
+ completely available. power_initial is therefore expected to be
+ comprised between 0.0 and 1.0, just as the values of power_trace.
+ state_trace values mean SURF_CPU_ON if >0 and SURF_CPU_OFF
+ otherwise.
+*/
+static cpu_t cpu_new(const char *name, xbt_maxmin_float_t power_scale,
+ xbt_maxmin_float_t power_initial,
+ tmgr_trace_t power_trace,
+ e_surf_cpu_state_t state_initial,
+ tmgr_trace_t state_trace)
+{
+ cpu_t cpu = xbt_new0(s_cpu_t, 1);
+
+ cpu->resource = (surf_resource_t) surf_cpu_resource;
+ cpu->name = name;
+ cpu->power_scale = power_scale;
+ cpu->power_current = power_initial;
+/* cpu->power_trace = power_trace; */
+ if (power_trace)
+ cpu->power_event =
+ tmgr_history_add_trace(history, power_trace, 0.0, 0, cpu);
+
+ cpu->state_current = state_initial;
+/* cpu->state_trace = state_trace; */
+ if (state_trace)
+ cpu->state_event =
+ tmgr_history_add_trace(history, state_trace, 0.0, 0, cpu);
+
+ cpu->constraint =
+ lmm_constraint_new(maxmin_system, cpu,
+ cpu->power_current * cpu->power_scale);
+
+ xbt_dict_set(cpu_set, name, cpu, cpu_free);
+
+ return cpu;
+}
+
+/*
+ Semantic: name scale initial power initial state
+ power trace state trace
+
+ Token: TOKEN_WORD TOKEN_WORD TOKEN_WORD TOKEN_WORD TOKEN_WORD TOKEN_WORD
+ Type: string float float string ON/OFF string
+*/
+
+static void parse_cpu(void)
+{
+ e_surf_token_t token;
+ char *name = NULL;
+ xbt_maxmin_float_t power_scale = 0.0;
+ xbt_maxmin_float_t power_initial = 0.0;
+ tmgr_trace_t power_trace = NULL;;
+ e_surf_cpu_state_t state_initial = SURF_CPU_OFF;
+ tmgr_trace_t state_trace = NULL;
+
+ name = xbt_strdup(surf_parse_text);
+
+ surf_parse_float(&power_scale);
+ surf_parse_float(&power_initial);
+ surf_parse_trace(&power_trace);
+
+ token = surf_parse(); /* state_initial */
+ xbt_assert1((token == TOKEN_WORD), "Parse error line %d", line_pos);
+ if (strcmp(surf_parse_text, "ON") == 0)
+ state_initial = SURF_CPU_ON;
+ else if (strcmp(surf_parse_text, "OFF") == 0)
+ state_initial = SURF_CPU_OFF;
+ else {
+ CRITICAL2("Invalid cpu state (line %d): %s neq ON or OFF\n", line_pos,
+ surf_parse_text);
+ xbt_abort();
+ }
+
+ surf_parse_trace(&state_trace);
+
+ cpu_new(name, power_scale, power_initial, power_trace, state_initial,
+ state_trace);
+}