3 /* Copyright (c) 2005 Arnaud Legrand. All rights reserved. */
5 /* This program is free software; you can redistribute it and/or modify it
6 * under the terms of the license (GNU LGPL) which comes with this package. */
10 #include "workstation_KCCFLN05_private.h"
12 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(workstation_KCCFLN05, surf,
13 "Logging specific to the SURF workstation module (KCCFLN05)");
15 static int nb_workstation = 0;
16 static s_route_KCCFLN05_t *routing_table = NULL;
17 #define ROUTE(i,j) routing_table[(i)+(j)*nb_workstation]
18 static network_link_KCCFLN05_t loopback = NULL;
20 static xbt_dict_t network_link_set = NULL;
22 /* convenient function */
23 static void __update_cpu_usage(cpu_KCCFLN05_t cpu)
26 surf_action_workstation_KCCFLN05_t action = NULL;
27 if ((!xbt_dynar_length(cpu->incomming_communications)) &&
28 (!xbt_dynar_length(cpu->outgoing_communications))) {
29 /* No communications */
30 lmm_update_constraint_bound(maxmin_system, cpu->constraint,
31 cpu->power_current * cpu->power_scale);
32 } else if ((!xbt_dynar_length(cpu->incomming_communications))
33 && (xbt_dynar_length(cpu->outgoing_communications))) {
35 lmm_update_constraint_bound(maxmin_system, cpu->constraint,
36 cpu->power_current * cpu->power_scale *
37 cpu->interference_send);
38 xbt_dynar_foreach(cpu->outgoing_communications, cpt, action)
39 lmm_elem_set_value(maxmin_system,cpu->constraint,action->variable,
40 cpu->power_current * cpu->power_scale *
41 ROUTE(action->src->id, action->dst->id).impact_on_src
43 } else if ((xbt_dynar_length(cpu->incomming_communications)) &&
44 (!xbt_dynar_length(cpu->outgoing_communications))) {
46 lmm_update_constraint_bound(maxmin_system, cpu->constraint,
47 cpu->power_current * cpu->power_scale *
48 cpu->interference_recv);
49 xbt_dynar_foreach(cpu->incomming_communications, cpt, action)
50 lmm_elem_set_value(maxmin_system,cpu->constraint,action->variable,
51 cpu->power_current * cpu->power_scale *
52 ROUTE(action->src->id, action->dst->id).impact_on_dst
55 /* Emission & Reception */
56 lmm_update_constraint_bound(maxmin_system, cpu->constraint,
57 cpu->power_current * cpu->power_scale *
58 cpu->interference_send_recv);
59 xbt_dynar_foreach(cpu->outgoing_communications, cpt, action)
60 lmm_elem_set_value(maxmin_system,cpu->constraint,action->variable,
61 cpu->power_current * cpu->power_scale *
62 ROUTE(action->src->id, action->dst->id).impact_on_src_with_other_recv
64 xbt_dynar_foreach(cpu->incomming_communications, cpt, action)
65 lmm_elem_set_value(maxmin_system,cpu->constraint,action->variable,
66 cpu->power_current * cpu->power_scale *
67 ROUTE(action->src->id, action->dst->id).impact_on_dst_with_other_send
72 /**************************************/
73 /******* Resource Public **********/
74 /**************************************/
76 static void *name_service(const char *name)
78 return xbt_dict_get_or_null(workstation_set, name);
81 static const char *get_resource_name(void *resource_id)
83 /* We can freely cast as a cpu_KCCFLN05_t because it has the same
84 prefix as network_link_KCCFLN05_t. However, only cpu_KCCFLN05_t
85 will theoretically be given as an argument here. */
86 return ((cpu_KCCFLN05_t) resource_id)->name;
89 /* action_get_state is inherited from the surf module */
91 static void action_use(surf_action_t action)
97 static int action_free(surf_action_t action)
100 surf_action_t act = NULL;
101 cpu_KCCFLN05_t src = ((surf_action_workstation_KCCFLN05_t) action)->src;
102 cpu_KCCFLN05_t dst = ((surf_action_workstation_KCCFLN05_t) action)->dst;
105 if (!action->using) {
106 xbt_swag_remove(action, action->state_set);
107 if (((surf_action_workstation_KCCFLN05_t) action)->variable)
108 lmm_variable_free(maxmin_system,
109 ((surf_action_workstation_KCCFLN05_t) action)->
113 xbt_dynar_foreach(src->outgoing_communications, cpt, act)
115 xbt_dynar_remove_at(src->outgoing_communications, cpt, &act);
119 if(!xbt_dynar_length(src->outgoing_communications))
120 __update_cpu_usage(src);
123 xbt_dynar_foreach(dst->incomming_communications, cpt, act)
125 xbt_dynar_remove_at(dst->incomming_communications, cpt, &act);
128 if(!xbt_dynar_length(dst->incomming_communications))
129 __update_cpu_usage(dst);
137 static void action_cancel(surf_action_t action)
139 surf_action_change_state(action, SURF_ACTION_FAILED);
143 static void action_recycle(surf_action_t action)
149 /* action_change_state is inherited from the surf module */
150 /* action_set_data is inherited from the surf module */
152 static void action_suspend(surf_action_t action)
154 XBT_IN1("(%p))",action);
155 lmm_update_variable_weight(maxmin_system,
156 ((surf_action_workstation_KCCFLN05_t)
157 action)->variable, 0.0);
161 static void action_resume(surf_action_t action)
163 XBT_IN1("(%p)",action);
164 lmm_update_variable_weight(maxmin_system,
165 ((surf_action_workstation_KCCFLN05_t)
166 action)->variable, 1.0);
170 static int action_is_suspended(surf_action_t action)
172 return (lmm_get_variable_weight
173 (((surf_action_workstation_KCCFLN05_t) action)->variable) ==
177 static void action_set_max_duration(surf_action_t action, double duration)
178 { /* FIXME: should inherit */
179 XBT_IN2("(%p,%g)",action,duration);
180 action->max_duration = duration;
185 static void action_set_priority(surf_action_t action, double priority)
186 { /* FIXME: should inherit */
187 XBT_IN2("(%p,%g)",action,priority);
188 action->priority = priority;
192 /**************************************/
193 /******* Resource Private **********/
194 /**************************************/
196 static int resource_used(void *resource_id)
198 /* We can freely cast as a network_link_KCCFLN05_t because it has
199 the same prefix as cpu_KCCFLN05_t */
200 if(((cpu_KCCFLN05_t) resource_id)->type == SURF_WORKSTATION_RESOURCE_CPU)
201 return (lmm_constraint_used(maxmin_system,
202 ((cpu_KCCFLN05_t) resource_id)->
204 lmm_constraint_used(maxmin_system,
205 ((cpu_KCCFLN05_t) resource_id)->
208 return lmm_constraint_used(maxmin_system,
209 ((network_link_KCCFLN05_t) resource_id)->
214 static double share_resources(double now)
216 s_surf_action_workstation_KCCFLN05_t s_action;
217 surf_action_workstation_KCCFLN05_t action = NULL;
219 xbt_swag_t running_actions = surf_workstation_resource->common_public->states.running_action_set;
220 double min = generic_maxmin_share_resources(running_actions,
221 xbt_swag_offset(s_action, variable));
223 xbt_swag_foreach(action, running_actions) {
224 if(action->latency>0) {
225 if(min<0) min = action->latency;
226 else if (action->latency<min) min = action->latency;
231 /* return generic_maxmin_share_resources(surf_workstation_resource->common_public-> */
232 /* states.running_action_set, */
233 /* xbt_swag_offset(action, variable)); */
236 static void update_actions_state(double now, double delta)
239 surf_action_workstation_KCCFLN05_t action = NULL;
240 surf_action_workstation_KCCFLN05_t next_action = NULL;
241 xbt_swag_t running_actions =
242 surf_workstation_resource->common_public->states.running_action_set;
244 xbt_swag_foreach_safe(action, next_action, running_actions) {
246 if (action->latency > 0) {
247 if (action->latency > deltap) {
248 surf_double_update(&(action->latency), deltap);
251 surf_double_update(&(deltap), action->latency);
252 action->latency = 0.0;
254 if ((action->latency == 0.0) && !(action->suspended))
255 lmm_update_variable_weight(maxmin_system, action->variable, 1.0);
257 surf_double_update(&(action->generic_action.remains),
258 lmm_variable_getvalue(action->variable) * deltap);
259 if (action->generic_action.max_duration != NO_MAX_DURATION)
260 surf_double_update(&(action->generic_action.max_duration), delta);
262 /* if(action->generic_action.remains<.00001) action->generic_action.remains=0; */
264 if ((action->generic_action.remains <= 0) &&
265 (lmm_get_variable_weight(action->variable)>0)) {
266 action->generic_action.finish = surf_get_clock();
267 surf_action_change_state((surf_action_t) action, SURF_ACTION_DONE);
268 } else if ((action->generic_action.max_duration != NO_MAX_DURATION) &&
269 (action->generic_action.max_duration <= 0)) {
270 action->generic_action.finish = surf_get_clock();
271 surf_action_change_state((surf_action_t) action, SURF_ACTION_DONE);
272 } else { /* Need to check that none of the resource has failed */
273 lmm_constraint_t cnst = NULL;
275 void *constraint_id = NULL;
278 lmm_get_cnst_from_var(maxmin_system, action->variable,
280 constraint_id = lmm_constraint_id(cnst);
281 if(((((network_link_KCCFLN05_t)constraint_id)->type==
282 SURF_WORKSTATION_RESOURCE_LINK) &&
283 (((network_link_KCCFLN05_t)constraint_id)->state_current==
284 SURF_NETWORK_LINK_OFF)) ||
285 ((((cpu_KCCFLN05_t)constraint_id)->type==
286 SURF_WORKSTATION_RESOURCE_CPU) &&
287 (((cpu_KCCFLN05_t)constraint_id)->state_current==
289 action->generic_action.finish = surf_get_clock();
290 surf_action_change_state((surf_action_t) action, SURF_ACTION_FAILED);
299 static void update_resource_state(void *id,
300 tmgr_trace_event_t event_type,
303 cpu_KCCFLN05_t cpu = id;
304 network_link_KCCFLN05_t nw_link = id ;
306 if(nw_link->type == SURF_WORKSTATION_RESOURCE_LINK) {
307 if (event_type == nw_link->bw_event) {
308 nw_link->bw_current = value;
309 lmm_update_constraint_bound(maxmin_system, nw_link->constraint,
310 nw_link->bw_current);
311 } else if (event_type == nw_link->lat_event) {
312 double delta = value - nw_link->lat_current;
313 lmm_variable_t var = NULL;
314 surf_action_workstation_KCCFLN05_t action = NULL;
316 nw_link->lat_current = value;
317 while (lmm_get_var_from_cnst(maxmin_system, nw_link->constraint, &var)) {
318 action = lmm_variable_id(var);
319 action->lat_current += delta;
321 lmm_update_variable_bound(maxmin_system, action->variable,
322 SG_TCP_CTE_GAMMA / (2.0 * action->lat_current));
324 lmm_update_variable_bound(maxmin_system, action->variable,
325 min(action->rate,SG_TCP_CTE_GAMMA / (2.0 * action->lat_current)));
327 } else if (event_type == nw_link->state_event) {
329 nw_link->state_current = SURF_NETWORK_LINK_ON;
331 nw_link->state_current = SURF_NETWORK_LINK_OFF;
333 CRITICAL0("Unknown event ! \n");
337 } else if(cpu->type == SURF_WORKSTATION_RESOURCE_CPU) {
338 if (event_type == cpu->power_event) {
339 cpu->power_current = value;
340 __update_cpu_usage(cpu);
341 } else if (event_type == cpu->state_event) {
343 cpu->state_current = SURF_CPU_ON;
345 cpu->state_current = SURF_CPU_OFF;
347 CRITICAL0("Unknown event ! \n");
357 static void finalize(void)
361 xbt_dict_free(&network_link_set);
362 xbt_dict_free(&workstation_set);
363 xbt_swag_free(surf_workstation_resource->common_public->states.
365 xbt_swag_free(surf_workstation_resource->common_public->states.
367 xbt_swag_free(surf_workstation_resource->common_public->states.
369 xbt_swag_free(surf_workstation_resource->common_public->states.
372 free(surf_workstation_resource->common_public);
373 free(surf_workstation_resource->common_private);
374 free(surf_workstation_resource->extension_public);
376 free(surf_workstation_resource);
377 surf_workstation_resource = NULL;
379 for (i = 0; i < nb_workstation; i++)
380 for (j = 0; j < nb_workstation; j++)
381 free(ROUTE(i, j).links);
383 routing_table = NULL;
387 lmm_system_free(maxmin_system);
388 maxmin_system = NULL;
392 /**************************************/
393 /******* Resource Private **********/
394 /**************************************/
396 static surf_action_t execute(void *cpu, double size)
398 surf_action_workstation_KCCFLN05_t action = NULL;
399 cpu_KCCFLN05_t CPU = cpu;
401 XBT_IN2("(%s,%g)",CPU->name,size);
402 action = xbt_new0(s_surf_action_workstation_KCCFLN05_t, 1);
404 action->generic_action.using = 1;
405 action->generic_action.cost = size;
406 action->generic_action.remains = size;
407 action->generic_action.priority = 1.0;
408 action->generic_action.max_duration = NO_MAX_DURATION;
409 action->generic_action.start = surf_get_clock();
410 action->generic_action.finish = -1.0;
411 action->generic_action.resource_type =
412 (surf_resource_t) surf_workstation_resource;
414 if (CPU->state_current == SURF_CPU_ON)
415 action->generic_action.state_set =
416 surf_workstation_resource->common_public->states.running_action_set;
418 action->generic_action.state_set =
419 surf_workstation_resource->common_public->states.failed_action_set;
420 xbt_swag_insert(action, action->generic_action.state_set);
422 action->variable = lmm_variable_new(maxmin_system, action,
423 action->generic_action.priority, -1.0, 1);
424 lmm_expand(maxmin_system, CPU->constraint, action->variable,
427 return (surf_action_t) action;
430 static surf_action_t action_sleep(void *cpu, double duration)
432 surf_action_workstation_KCCFLN05_t action = NULL;
434 XBT_IN2("(%s,%g)",((cpu_KCCFLN05_t)cpu)->name,duration);
436 action = (surf_action_workstation_KCCFLN05_t) execute(cpu, 1.0);
437 action->generic_action.max_duration = duration;
438 lmm_update_variable_weight(maxmin_system, action->variable, 0.0);
441 return (surf_action_t) action;
444 static e_surf_cpu_state_t resource_get_state(void *cpu)
446 return ((cpu_KCCFLN05_t) cpu)->state_current;
449 static double get_speed(void *cpu, double load)
451 return load*(((cpu_KCCFLN05_t) cpu)->power_scale);
454 static surf_action_t communicate(void *src, void *dst, double size, double rate)
456 surf_action_workstation_KCCFLN05_t action = NULL;
457 cpu_KCCFLN05_t card_src = src;
458 cpu_KCCFLN05_t card_dst = dst;
459 route_KCCFLN05_t route = &(ROUTE(card_src->id, card_dst->id));
460 int route_size = route->size;
463 XBT_IN4("(%s,%s,%g,%g)",card_src->name,card_dst->name,size,rate);
464 xbt_assert2(route_size,"You're trying to send data from %s to %s but there is no connexion between these two cards.", card_src->name, card_dst->name);
466 action = xbt_new0(s_surf_action_workstation_KCCFLN05_t, 1);
468 action->generic_action.using = 1;
469 action->generic_action.cost = size;
470 action->generic_action.remains = size;
471 action->generic_action.max_duration = NO_MAX_DURATION;
472 action->generic_action.start = -1.0;
473 action->generic_action.finish = -1.0;
476 action->generic_action.resource_type =
477 (surf_resource_t) surf_workstation_resource;
478 action->suspended = 0; /* Should be useless because of the
479 calloc but it seems to help valgrind... */
480 action->generic_action.state_set =
481 surf_workstation_resource->common_public->states.running_action_set;
483 xbt_dynar_push(card_src->outgoing_communications, &action);
484 xbt_dynar_push(card_dst->incomming_communications, &action);
486 xbt_swag_insert(action, action->generic_action.state_set);
489 action->latency = 0.0;
490 for (i = 0; i < route_size; i++)
491 action->latency += route->links[i]->lat_current;
492 action->lat_current = action->latency;
494 if(action->latency>0)
495 action->variable = lmm_variable_new(maxmin_system, action, 0.0, -1.0,
496 route_size+4); /* +1 for the src bus
499 +1 for the dst cpu */
501 action->variable = lmm_variable_new(maxmin_system, action, 1.0, -1.0,
505 if(action->lat_current>0)
506 lmm_update_variable_bound(maxmin_system, action->variable,
507 SG_TCP_CTE_GAMMA / (2.0 * action->lat_current));
509 lmm_update_variable_bound(maxmin_system, action->variable, -1.0);
511 if(action->lat_current>0)
512 lmm_update_variable_bound(maxmin_system, action->variable,
513 min(action->rate,SG_TCP_CTE_GAMMA / (2.0 * action->lat_current)));
515 lmm_update_variable_bound(maxmin_system, action->variable, action->rate);
518 for (i = 0; i < route_size; i++)
519 lmm_expand(maxmin_system, route->links[i]->constraint, action->variable, 1.0);
521 lmm_expand(maxmin_system, card_src->bus, action->variable, 1.0);
523 lmm_expand(maxmin_system, card_dst->bus, action->variable, 1.0);
524 lmm_expand(maxmin_system, card_src->constraint, action->variable, 0.0);
525 lmm_expand(maxmin_system, card_dst->constraint, action->variable, 0.0);
528 return (surf_action_t) action;
531 /* FIXME: execute_parallel_task */
532 static surf_action_t execute_parallel_task(int cpu_nb,
534 double *computation_amount,
535 double *communication_amount,
544 /**************************************/
545 /*** Resource Creation & Destruction **/
546 /**************************************/
548 static void cpu_free(void *cpu)
550 free(((cpu_KCCFLN05_t) cpu)->name);
551 xbt_dynar_free(&(((cpu_KCCFLN05_t) cpu)->incomming_communications));
552 xbt_dynar_free(&(((cpu_KCCFLN05_t) cpu)->outgoing_communications));
556 static cpu_KCCFLN05_t cpu_new(const char *name, double power_scale,
557 double power_initial,
558 tmgr_trace_t power_trace,
559 e_surf_cpu_state_t state_initial,
560 tmgr_trace_t state_trace,
561 double interference_send,
562 double interference_recv,
563 double interference_send_recv,
564 double max_outgoing_rate)
566 cpu_KCCFLN05_t cpu = xbt_new0(s_cpu_KCCFLN05_t, 1);
568 cpu->resource = (surf_resource_t) surf_workstation_resource;
569 cpu->type = SURF_WORKSTATION_RESOURCE_CPU;
570 cpu->name = xbt_strdup(name);
571 cpu->id = nb_workstation++;
573 cpu->power_scale = power_scale;
574 xbt_assert0(cpu->power_scale > 0, "Power has to be >0");
576 cpu->power_current = power_initial;
579 tmgr_history_add_trace(history, power_trace, 0.0, 0, cpu);
581 cpu->state_current = state_initial;
584 tmgr_history_add_trace(history, state_trace, 0.0, 0, cpu);
586 cpu->interference_send = interference_send;
587 cpu->interference_recv = interference_recv;
588 cpu->interference_send_recv = interference_send_recv;
591 lmm_constraint_new(maxmin_system, cpu,
592 cpu->power_current * cpu->power_scale);
593 if (max_outgoing_rate > 0)
594 cpu->bus = lmm_constraint_new(maxmin_system, cpu, max_outgoing_rate);
596 cpu->incomming_communications =
597 xbt_dynar_new(sizeof(surf_action_workstation_KCCFLN05_t), NULL);
598 cpu->outgoing_communications =
599 xbt_dynar_new(sizeof(surf_action_workstation_KCCFLN05_t), NULL);
601 xbt_dict_set(workstation_set, name, cpu, cpu_free);
606 static void parse_cpu(void)
608 double power_scale = 0.0;
609 double power_initial = 0.0;
610 tmgr_trace_t power_trace = NULL;
611 e_surf_cpu_state_t state_initial = SURF_CPU_OFF;
612 tmgr_trace_t state_trace = NULL;
613 double interference_send = 0.0;
614 double interference_recv = 0.0;
615 double interference_send_recv = 0.0;
616 double max_outgoing_rate = -1.0;
618 surf_parse_get_double(&power_scale, A_surfxml_cpu_power);
619 surf_parse_get_double(&power_initial, A_surfxml_cpu_availability);
620 surf_parse_get_trace(&power_trace, A_surfxml_cpu_availability_file);
622 xbt_assert0((A_surfxml_cpu_state == A_surfxml_cpu_state_ON) ||
623 (A_surfxml_cpu_state == A_surfxml_cpu_state_OFF),
625 if (A_surfxml_cpu_state == A_surfxml_cpu_state_ON)
626 state_initial = SURF_CPU_ON;
627 if (A_surfxml_cpu_state == A_surfxml_cpu_state_OFF)
628 state_initial = SURF_CPU_OFF;
629 surf_parse_get_trace(&state_trace, A_surfxml_cpu_state_file);
631 surf_parse_get_double(&interference_send,
632 A_surfxml_cpu_interference_send);
633 surf_parse_get_double(&interference_recv,
634 A_surfxml_cpu_interference_recv);
635 surf_parse_get_double(&interference_send_recv,
636 A_surfxml_cpu_interference_send_recv);
637 surf_parse_get_double(&max_outgoing_rate,
638 A_surfxml_cpu_max_outgoing_rate);
640 cpu_new(A_surfxml_cpu_name, power_scale, power_initial, power_trace,
641 state_initial, state_trace, interference_send, interference_recv,
642 interference_send_recv, max_outgoing_rate);
645 static void create_routing_table(void)
648 xbt_new0(s_route_KCCFLN05_t, nb_workstation * nb_workstation);
651 static void network_link_free(void *nw_link)
653 free(((network_link_KCCFLN05_t) nw_link)->name);
657 static network_link_KCCFLN05_t network_link_new(char *name,
659 tmgr_trace_t bw_trace,
661 tmgr_trace_t lat_trace,
662 e_surf_network_link_state_t
664 tmgr_trace_t state_trace,
665 e_surf_network_link_sharing_policy_t policy)
667 network_link_KCCFLN05_t nw_link = xbt_new0(s_network_link_KCCFLN05_t, 1);
670 nw_link->resource = (surf_resource_t) surf_workstation_resource;
671 nw_link->type = SURF_WORKSTATION_RESOURCE_LINK;
672 nw_link->name = name;
673 nw_link->bw_current = bw_initial;
676 tmgr_history_add_trace(history, bw_trace, 0.0, 0, nw_link);
677 nw_link->state_current = state_initial;
678 nw_link->lat_current = lat_initial;
681 tmgr_history_add_trace(history, lat_trace, 0.0, 0, nw_link);
683 nw_link->state_event =
684 tmgr_history_add_trace(history, state_trace, 0.0, 0, nw_link);
686 nw_link->constraint =
687 lmm_constraint_new(maxmin_system, nw_link, nw_link->bw_current);
689 if(policy == SURF_NETWORK_LINK_FATPIPE)
690 lmm_constraint_shared(nw_link->constraint);
692 xbt_dict_set(network_link_set, name, nw_link, network_link_free);
697 static void parse_network_link(void)
701 tmgr_trace_t bw_trace;
703 tmgr_trace_t lat_trace;
704 e_surf_network_link_state_t state_initial = SURF_NETWORK_LINK_ON;
705 e_surf_network_link_sharing_policy_t policy_initial = SURF_NETWORK_LINK_SHARED;
706 tmgr_trace_t state_trace;
708 name = xbt_strdup(A_surfxml_network_link_name);
709 surf_parse_get_double(&bw_initial,A_surfxml_network_link_bandwidth);
710 surf_parse_get_trace(&bw_trace, A_surfxml_network_link_bandwidth_file);
711 surf_parse_get_double(&lat_initial,A_surfxml_network_link_latency);
712 surf_parse_get_trace(&lat_trace, A_surfxml_network_link_latency_file);
714 xbt_assert0((A_surfxml_network_link_state==A_surfxml_network_link_state_ON)||
715 (A_surfxml_network_link_state==A_surfxml_network_link_state_OFF),
717 if (A_surfxml_network_link_state==A_surfxml_network_link_state_ON)
718 state_initial = SURF_NETWORK_LINK_ON;
719 else if (A_surfxml_network_link_state==A_surfxml_network_link_state_OFF)
720 state_initial = SURF_NETWORK_LINK_OFF;
722 if (A_surfxml_network_link_sharing_policy==A_surfxml_network_link_sharing_policy_SHARED)
723 policy_initial = SURF_NETWORK_LINK_SHARED;
724 else if (A_surfxml_network_link_sharing_policy==A_surfxml_network_link_sharing_policy_FATPIPE)
725 policy_initial = SURF_NETWORK_LINK_FATPIPE;
727 surf_parse_get_trace(&state_trace,A_surfxml_network_link_state_file);
729 network_link_new(name, bw_initial, bw_trace,
730 lat_initial, lat_trace, state_initial, state_trace,
734 static void route_new(int src_id, int dst_id, char **links, int nb_link,
735 double impact_on_src, double impact_on_dst,
736 double impact_on_src_with_other_recv,
737 double impact_on_dst_with_other_send)
739 network_link_KCCFLN05_t *link_list = NULL;
741 route_KCCFLN05_t route = &(ROUTE(src_id, dst_id));
743 route->size = nb_link;
744 link_list = route->links = xbt_new0(network_link_KCCFLN05_t, nb_link);
745 for (i = 0; i < nb_link; i++) {
746 link_list[i] = xbt_dict_get_or_null(network_link_set, links[i]);
750 route->impact_on_src = impact_on_src;
751 route->impact_on_dst = impact_on_src;
752 route->impact_on_src_with_other_recv = impact_on_src_with_other_recv;
753 route->impact_on_dst_with_other_send = impact_on_dst_with_other_send;
756 static int nb_link = 0;
757 static char **link_name = NULL;
758 static int src_id = -1;
759 static int dst_id = -1;
760 static double impact_on_src;
761 static double impact_on_dst;
762 static double impact_on_src_with_other_recv;
763 static double impact_on_dst_with_other_send;
765 static void parse_route_set_endpoints(void)
767 src_id = ((cpu_KCCFLN05_t) name_service(A_surfxml_route_src))->id;
768 dst_id = ((cpu_KCCFLN05_t) name_service(A_surfxml_route_dst))->id;
769 surf_parse_get_double(&impact_on_src, A_surfxml_route_impact_on_src);
770 surf_parse_get_double(&impact_on_dst, A_surfxml_route_impact_on_dst);
771 surf_parse_get_double(&impact_on_src_with_other_recv,
772 A_surfxml_route_impact_on_src_with_other_recv);
773 surf_parse_get_double(&impact_on_dst_with_other_send,
774 A_surfxml_route_impact_on_dst_with_other_send);
780 static void parse_route_elem(void)
783 link_name = xbt_realloc(link_name, (nb_link) * sizeof(char *));
784 link_name[(nb_link) - 1] = xbt_strdup(A_surfxml_route_element_name);
787 static void parse_route_set_route(void)
789 route_new(src_id, dst_id, link_name, nb_link, impact_on_src,
790 impact_on_dst, impact_on_src_with_other_recv,
791 impact_on_dst_with_other_send);
794 static void parse_file(const char *file)
798 /* Figuring out the cpus */
799 surf_parse_reset_parser();
800 ETag_surfxml_cpu_fun = parse_cpu;
801 surf_parse_open(file);
802 xbt_assert1((!surf_parse()), "Parse error in %s", file);
805 create_routing_table();
807 /* Figuring out the network links */
808 surf_parse_reset_parser();
809 ETag_surfxml_network_link_fun = parse_network_link;
810 surf_parse_open(file);
811 xbt_assert1((!surf_parse()), "Parse error in %s", file);
814 /* Building the routes */
815 surf_parse_reset_parser();
816 STag_surfxml_route_fun = parse_route_set_endpoints;
817 ETag_surfxml_route_element_fun = parse_route_elem;
818 ETag_surfxml_route_fun = parse_route_set_route;
819 surf_parse_open(file);
820 xbt_assert1((!surf_parse()), "Parse error in %s", file);
823 /* Adding loopback if needed */
824 for (i = 0; i < nb_workstation; i++)
825 if(!ROUTE(i,i).size) {
827 loopback = network_link_new(xbt_strdup("__MSG_loopback__"),
828 498.00, NULL, 0.000015, NULL,
829 SURF_NETWORK_LINK_ON, NULL,
830 SURF_NETWORK_LINK_FATPIPE);
832 ROUTE(i,i).links = xbt_new0(network_link_KCCFLN05_t, 1);
833 ROUTE(i,i).links[0] = loopback;
838 /**************************************/
839 /********* Module creation ***********/
840 /**************************************/
842 static void resource_init_internal(void)
844 s_surf_action_t action;
846 surf_workstation_resource = xbt_new0(s_surf_workstation_resource_t, 1);
848 surf_workstation_resource->common_private =
849 xbt_new0(s_surf_resource_private_t, 1);
850 surf_workstation_resource->common_public =
851 xbt_new0(s_surf_resource_public_t, 1);
852 surf_workstation_resource->extension_public =
853 xbt_new0(s_surf_workstation_resource_extension_public_t, 1);
855 surf_workstation_resource->common_public->states.ready_action_set =
856 xbt_swag_new(xbt_swag_offset(action, state_hookup));
857 surf_workstation_resource->common_public->states.running_action_set =
858 xbt_swag_new(xbt_swag_offset(action, state_hookup));
859 surf_workstation_resource->common_public->states.failed_action_set =
860 xbt_swag_new(xbt_swag_offset(action, state_hookup));
861 surf_workstation_resource->common_public->states.done_action_set =
862 xbt_swag_new(xbt_swag_offset(action, state_hookup));
864 surf_workstation_resource->common_public->name_service = name_service;
865 surf_workstation_resource->common_public->get_resource_name = get_resource_name;
866 surf_workstation_resource->common_public->action_get_state = surf_action_get_state;
867 surf_workstation_resource->common_public->action_use = action_use;
868 surf_workstation_resource->common_public->action_free = action_free;
869 surf_workstation_resource->common_public->action_cancel = action_cancel;
870 surf_workstation_resource->common_public->action_recycle = action_recycle;
871 surf_workstation_resource->common_public->action_change_state = surf_action_change_state;
872 surf_workstation_resource->common_public->action_set_data = surf_action_set_data;
873 surf_workstation_resource->common_public->suspend = action_suspend;
874 surf_workstation_resource->common_public->resume = action_resume;
875 surf_workstation_resource->common_public->is_suspended = action_is_suspended;
876 surf_workstation_resource->common_public->set_max_duration = action_set_max_duration;
877 surf_workstation_resource->common_public->set_priority = action_set_priority;
878 surf_workstation_resource->common_public->name = "Workstation KCCFLN05";
880 surf_workstation_resource->common_private->resource_used = resource_used;
881 surf_workstation_resource->common_private->share_resources = share_resources;
882 surf_workstation_resource->common_private->update_actions_state = update_actions_state;
883 surf_workstation_resource->common_private->update_resource_state = update_resource_state;
884 surf_workstation_resource->common_private->finalize = finalize;
886 surf_workstation_resource->extension_public->execute = execute;
887 surf_workstation_resource->extension_public->sleep = action_sleep;
888 surf_workstation_resource->extension_public->get_state = resource_get_state;
889 surf_workstation_resource->extension_public->communicate = communicate;
890 surf_workstation_resource->extension_public->execute_parallel_task = execute_parallel_task;
892 workstation_set = xbt_dict_new();
893 network_link_set = xbt_dict_new();
895 xbt_assert0(maxmin_system, "surf_init has to be called first!");
898 /**************************************/
899 /*************** Generic **************/
900 /**************************************/
901 void surf_workstation_resource_init_KCCFLN05(const char *filename)
903 xbt_assert0(!surf_cpu_resource, "CPU resource type already defined");
904 xbt_assert0(!surf_network_resource, "network resource type already defined");
905 resource_init_internal();
906 parse_file(filename);
908 xbt_dynar_push(resource_list, &surf_workstation_resource);