- workstation_KCCFLN05_t workstation = xbt_new0(s_workstation_KCCFLN05_t, 1);
-
- workstation->resource = (surf_resource_t) surf_workstation_resource;
- workstation->name = xbt_strdup(name);
- workstation->id = nb_workstation++;
-
- workstation->power_scale = power_scale;
- xbt_assert0(workstation->power_scale>0,"Power has to be >0");
-
- workstation->power_current = power_initial;
- if (power_trace)
- workstation->power_event =
- tmgr_history_add_trace(history, power_trace, 0.0, 0, workstation);
-
- workstation->state_current = state_initial;
- if (state_trace)
- workstation->state_event =
- tmgr_history_add_trace(history, state_trace, 0.0, 0, workstation);
-
- workstation->interference_send=interference_send;
- workstation->interference_recv=interference_recv;
- workstation->interference_send_recv=interference_send_recv;
-
- workstation->constraint =
- lmm_constraint_new(maxmin_system_cpu_KCCFLN05, workstation,
- workstation->power_current * workstation->power_scale);
- if(max_outgoing_rate>0)
- workstation->bus=
- lmm_constraint_new(maxmin_system_cpu_KCCFLN05, workstation,
- max_outgoing_rate);
-
- workstation->incomming_communications =
- xbt_dynar_new(sizeof(surf_action_network_KCCFLN05_t),NULL);
- workstation->outgoing_communications =
- xbt_dynar_new(sizeof(surf_action_network_KCCFLN05_t),NULL);
-
- xbt_dict_set(workstation_set, name, workstation, workstation_free);
-
- return workstation;
-}
-
-static void parse_workstation(void)
-{
- double power_scale = 0.0;
- double 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;
- double interference_send = 0.0;
- double interference_recv = 0.0;
- double interference_send_recv = 0.0;
- double max_outgoing_rate = -1.0;
-
- surf_parse_get_double(&power_scale,A_cpu_power);
- surf_parse_get_double(&power_initial,A_cpu_availability);
- surf_parse_get_trace(&power_trace,A_cpu_availability_file);
-
- xbt_assert0((A_cpu_state==A_cpu_state_ON)||
- (A_cpu_state==A_cpu_state_OFF),
- "Invalid state")
- if (A_cpu_state==A_cpu_state_ON) state_initial = SURF_CPU_ON;
- if (A_cpu_state==A_cpu_state_OFF) state_initial = SURF_CPU_OFF;
- surf_parse_get_trace(&state_trace,A_cpu_state_file);
-
- surf_parse_get_double(&interference_send,A_cpu_interference_send);
- surf_parse_get_double(&interference_recv,A_cpu_interference_recv);
- surf_parse_get_double(&interference_send_recv,A_cpu_interference_send_recv);
- surf_parse_get_double(&max_outgoing_rate,A_cpu_max_outgoing_rate);
-
- workstation_new(A_cpu_name, power_scale, power_initial, power_trace, state_initial,
- state_trace, interference_send, interference_recv,
- interference_send_recv, max_outgoing_rate);
-}
-
-/*********** resource management ***********/
-
-static void *name_service(const char *name)
-{
- void *workstation = NULL;
-
- xbt_dict_get(workstation_set, name, &workstation);
-
- return workstation;
-}
-
-static const char *get_resource_name(void *resource_id)
-{
- return ((workstation_KCCFLN05_t) resource_id)->name;
-}
-
-static int cpu_used(void *resource_id)
-{
- return lmm_constraint_used(maxmin_system_cpu_KCCFLN05,
- ((workstation_KCCFLN05_t) resource_id)->constraint);
-}
-
-static int link_used(void *resource_id)
-{
- return lmm_constraint_used(maxmin_system_network_KCCFLN05,
- ((network_link_KCCFLN05_t) resource_id)->constraint);
-}
-
-static e_surf_cpu_state_t get_state(void *cpu)
-{
- return ((workstation_KCCFLN05_t) cpu)->state_current;
-}
-
-static void update_cpu_KCCFLN05_state(void *id,
- tmgr_trace_event_t event_type,
- double value)
-{
- workstation_KCCFLN05_t cpu = id;
-
- if (event_type == cpu->power_event) {
- cpu->power_current = value;
- /*** The bound is updated in share_cpu_KCCFLN05_resources ***/
- /* lmm_update_constraint_bound(maxmin_system_cpu_KCCFLN05, cpu->constraint, */
- /* cpu->power_current * cpu->power_scale); */
- } else if (event_type == cpu->state_event) {
- if (value > 0)
- cpu->state_current = SURF_CPU_ON;
- else
- cpu->state_current = SURF_CPU_OFF;
+ int cpt;
+ surf_action_workstation_KCCFLN05_t action = NULL;
+ if ((!xbt_dynar_length(cpu->incomming_communications)) &&
+ (!xbt_dynar_length(cpu->outgoing_communications))) {
+ /* No communications */
+ lmm_update_constraint_bound(maxmin_system, cpu->constraint,
+ cpu->power_current * cpu->power_scale);
+ } else if ((!xbt_dynar_length(cpu->incomming_communications))
+ && (xbt_dynar_length(cpu->outgoing_communications))) {
+ /* Emission */
+ lmm_update_constraint_bound(maxmin_system, cpu->constraint,
+ cpu->power_current * cpu->power_scale *
+ cpu->interference_send);
+ xbt_dynar_foreach(cpu->outgoing_communications, cpt, action)
+ lmm_elem_set_value(maxmin_system,cpu->constraint,action->variable,
+ cpu->power_current * cpu->power_scale *
+ ROUTE(action->src->id, action->dst->id).impact_on_src
+ );
+ } else if ((xbt_dynar_length(cpu->incomming_communications)) &&
+ (!xbt_dynar_length(cpu->outgoing_communications))) {
+ /* Reception */
+ lmm_update_constraint_bound(maxmin_system, cpu->constraint,
+ cpu->power_current * cpu->power_scale *
+ cpu->interference_recv);
+ xbt_dynar_foreach(cpu->incomming_communications, cpt, action)
+ lmm_elem_set_value(maxmin_system,cpu->constraint,action->variable,
+ cpu->power_current * cpu->power_scale *
+ ROUTE(action->src->id, action->dst->id).impact_on_dst
+ );