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(surf_workstation, 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 /*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)->
112 xbt_dynar_foreach(src->outgoing_communications, cpt, act)
114 xbt_dynar_remove_at(src->outgoing_communications, cpt, &act);
119 xbt_dynar_foreach(dst->incomming_communications, cpt, act)
121 xbt_dynar_remove_at(dst->incomming_communications, cpt, &act);
125 if(src && (!xbt_dynar_length(src->outgoing_communications)))
126 __update_cpu_usage(src);
127 if(dst && (!xbt_dynar_length(dst->incomming_communications)))
128 __update_cpu_usage(dst);
136 static void action_cancel(surf_action_t action)
138 surf_action_change_state(action, SURF_ACTION_FAILED);
142 static void action_recycle(surf_action_t action)
148 /* action_change_state is inherited from the surf module */
149 /* action_set_data is inherited from the surf module */
151 static void action_suspend(surf_action_t action)
153 XBT_IN1("(%p))",action);
154 ((surf_action_workstation_KCCFLN05_t) action)->suspended = 1;
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 if(((surf_action_workstation_KCCFLN05_t)action)->lat_current==0.0)
165 lmm_update_variable_weight(maxmin_system,
166 ((surf_action_workstation_KCCFLN05_t)
167 action)->variable, 1.0);
169 lmm_update_variable_weight(maxmin_system,
170 ((surf_action_workstation_KCCFLN05_t) action)->variable,
171 ((surf_action_workstation_KCCFLN05_t) action)->lat_current);
173 ((surf_action_workstation_KCCFLN05_t) action)->suspended = 0;
177 static int action_is_suspended(surf_action_t action)
179 return (((surf_action_workstation_KCCFLN05_t) action)->suspended);
182 static void action_set_max_duration(surf_action_t action, double duration)
183 { /* FIXME: should inherit */
184 XBT_IN2("(%p,%g)",action,duration);
185 action->max_duration = duration;
190 static void action_set_priority(surf_action_t action, double priority)
191 { /* FIXME: should inherit */
192 XBT_IN2("(%p,%g)",action,priority);
193 action->priority = priority;
197 /**************************************/
198 /******* Resource Private **********/
199 /**************************************/
201 static int resource_used(void *resource_id)
203 /* We can freely cast as a network_link_KCCFLN05_t because it has
204 the same prefix as cpu_KCCFLN05_t */
205 if(((cpu_KCCFLN05_t) resource_id)->type == SURF_WORKSTATION_RESOURCE_CPU)
206 return (lmm_constraint_used(maxmin_system,
207 ((cpu_KCCFLN05_t) resource_id)->
209 ((((cpu_KCCFLN05_t) resource_id)->bus)?
210 lmm_constraint_used(maxmin_system,
211 ((cpu_KCCFLN05_t) resource_id)->
214 return lmm_constraint_used(maxmin_system,
215 ((network_link_KCCFLN05_t) resource_id)->
220 static double share_resources(double now)
222 s_surf_action_workstation_KCCFLN05_t s_action;
223 surf_action_workstation_KCCFLN05_t action = NULL;
225 xbt_swag_t running_actions = surf_workstation_resource->common_public->states.running_action_set;
226 double min = generic_maxmin_share_resources(running_actions,
227 xbt_swag_offset(s_action, variable));
229 xbt_swag_foreach(action, running_actions) {
230 if(action->latency>0) {
231 if(min<0) min = action->latency;
232 else if (action->latency<min) min = action->latency;
237 /* return generic_maxmin_share_resources(surf_workstation_resource->common_public-> */
238 /* states.running_action_set, */
239 /* xbt_swag_offset(action, variable)); */
242 static void update_actions_state(double now, double delta)
245 surf_action_workstation_KCCFLN05_t action = NULL;
246 surf_action_workstation_KCCFLN05_t next_action = NULL;
247 xbt_swag_t running_actions =
248 surf_workstation_resource->common_public->states.running_action_set;
250 xbt_swag_foreach_safe(action, next_action, running_actions) {
252 if (action->latency > 0) {
253 if (action->latency > deltap) {
254 surf_double_update(&(action->latency), deltap);
257 surf_double_update(&(deltap), action->latency);
258 action->latency = 0.0;
260 if ((action->latency == 0.0) && !(action->suspended)) {
261 if((action)->lat_current==0.0)
262 lmm_update_variable_weight(maxmin_system,action->variable, 1.0);
264 lmm_update_variable_weight(maxmin_system, action->variable,
265 action->lat_current);
268 surf_double_update(&(action->generic_action.remains),
269 lmm_variable_getvalue(action->variable) * deltap);
270 if (action->generic_action.max_duration != NO_MAX_DURATION)
271 surf_double_update(&(action->generic_action.max_duration), delta);
273 /* if(action->generic_action.remains<.00001) action->generic_action.remains=0; */
275 if ((action->generic_action.remains <= 0) &&
276 (lmm_get_variable_weight(action->variable)>0)) {
277 action->generic_action.finish = surf_get_clock();
278 surf_action_change_state((surf_action_t) action, SURF_ACTION_DONE);
279 } else if ((action->generic_action.max_duration != NO_MAX_DURATION) &&
280 (action->generic_action.max_duration <= 0)) {
281 action->generic_action.finish = surf_get_clock();
282 surf_action_change_state((surf_action_t) action, SURF_ACTION_DONE);
283 } else { /* Need to check that none of the resource has failed */
284 lmm_constraint_t cnst = NULL;
286 void *constraint_id = NULL;
289 lmm_get_cnst_from_var(maxmin_system, action->variable,
291 constraint_id = lmm_constraint_id(cnst);
292 if(((((network_link_KCCFLN05_t)constraint_id)->type==
293 SURF_WORKSTATION_RESOURCE_LINK) &&
294 (((network_link_KCCFLN05_t)constraint_id)->state_current==
295 SURF_NETWORK_LINK_OFF)) ||
296 ((((cpu_KCCFLN05_t)constraint_id)->type==
297 SURF_WORKSTATION_RESOURCE_CPU) &&
298 (((cpu_KCCFLN05_t)constraint_id)->state_current==
300 action->generic_action.finish = surf_get_clock();
301 surf_action_change_state((surf_action_t) action, SURF_ACTION_FAILED);
310 static void update_resource_state(void *id,
311 tmgr_trace_event_t event_type,
314 cpu_KCCFLN05_t cpu = id;
315 network_link_KCCFLN05_t nw_link = id ;
317 if(nw_link->type == SURF_WORKSTATION_RESOURCE_LINK) {
318 if (event_type == nw_link->bw_event) {
319 nw_link->bw_current = value;
320 lmm_update_constraint_bound(maxmin_system, nw_link->constraint,
321 nw_link->bw_current);
322 } else if (event_type == nw_link->lat_event) {
323 double delta = value - nw_link->lat_current;
324 lmm_variable_t var = NULL;
325 surf_action_workstation_KCCFLN05_t action = NULL;
327 nw_link->lat_current = value;
328 while (lmm_get_var_from_cnst(maxmin_system, nw_link->constraint, &var)) {
329 action = lmm_variable_id(var);
330 action->lat_current += delta;
332 lmm_update_variable_bound(maxmin_system, action->variable,
333 SG_TCP_CTE_GAMMA / (2.0 * action->lat_current));
335 lmm_update_variable_bound(maxmin_system, action->variable,
336 min(action->rate,SG_TCP_CTE_GAMMA / (2.0 * action->lat_current)));
337 if(!(action->suspended))
338 lmm_update_variable_weight(maxmin_system, action->variable,
339 action->lat_current);
341 } else if (event_type == nw_link->state_event) {
343 nw_link->state_current = SURF_NETWORK_LINK_ON;
345 nw_link->state_current = SURF_NETWORK_LINK_OFF;
347 CRITICAL0("Unknown event ! \n");
351 } else if(cpu->type == SURF_WORKSTATION_RESOURCE_CPU) {
352 if (event_type == cpu->power_event) {
353 cpu->power_current = value;
354 __update_cpu_usage(cpu);
355 } else if (event_type == cpu->state_event) {
357 cpu->state_current = SURF_CPU_ON;
359 cpu->state_current = SURF_CPU_OFF;
361 CRITICAL0("Unknown event ! \n");
371 static void finalize(void)
375 xbt_dict_free(&network_link_set);
376 xbt_dict_free(&workstation_set);
377 xbt_swag_free(surf_workstation_resource->common_public->states.
379 xbt_swag_free(surf_workstation_resource->common_public->states.
381 xbt_swag_free(surf_workstation_resource->common_public->states.
383 xbt_swag_free(surf_workstation_resource->common_public->states.
386 free(surf_workstation_resource->common_public);
387 free(surf_workstation_resource->common_private);
388 free(surf_workstation_resource->extension_public);
390 free(surf_workstation_resource);
391 surf_workstation_resource = NULL;
393 for (i = 0; i < nb_workstation; i++)
394 for (j = 0; j < nb_workstation; j++)
395 free(ROUTE(i, j).links);
397 routing_table = NULL;
401 lmm_system_free(maxmin_system);
402 maxmin_system = NULL;
406 /**************************************/
407 /******* Resource Private **********/
408 /**************************************/
410 static surf_action_t execute(void *cpu, double size)
412 surf_action_workstation_KCCFLN05_t action = NULL;
413 cpu_KCCFLN05_t CPU = cpu;
415 XBT_IN2("(%s,%g)",CPU->name,size);
416 action = xbt_new0(s_surf_action_workstation_KCCFLN05_t, 1);
418 action->generic_action.using = 1;
419 action->generic_action.cost = size;
420 action->generic_action.remains = size;
421 action->generic_action.priority = 1.0;
422 action->generic_action.max_duration = NO_MAX_DURATION;
423 action->generic_action.start = surf_get_clock();
424 action->generic_action.finish = -1.0;
425 action->generic_action.resource_type =
426 (surf_resource_t) surf_workstation_resource;
427 action->suspended = 0;
429 if (CPU->state_current == SURF_CPU_ON)
430 action->generic_action.state_set =
431 surf_workstation_resource->common_public->states.running_action_set;
433 action->generic_action.state_set =
434 surf_workstation_resource->common_public->states.failed_action_set;
435 xbt_swag_insert(action, action->generic_action.state_set);
437 action->variable = lmm_variable_new(maxmin_system, action,
438 action->generic_action.priority, -1.0, 1);
439 lmm_expand(maxmin_system, CPU->constraint, action->variable,
442 return (surf_action_t) action;
445 static surf_action_t action_sleep(void *cpu, double duration)
447 surf_action_workstation_KCCFLN05_t action = NULL;
449 XBT_IN2("(%s,%g)",((cpu_KCCFLN05_t)cpu)->name,duration);
451 action = (surf_action_workstation_KCCFLN05_t) execute(cpu, 1.0);
452 action->generic_action.max_duration = duration;
453 lmm_update_variable_weight(maxmin_system, action->variable, 0.0);
456 return (surf_action_t) action;
459 static e_surf_cpu_state_t resource_get_state(void *cpu)
461 return ((cpu_KCCFLN05_t) cpu)->state_current;
464 static double get_speed(void *cpu, double load)
466 return load*(((cpu_KCCFLN05_t) cpu)->power_scale);
469 static double get_available_speed(void *cpu)
471 return ((cpu_KCCFLN05_t) cpu)->power_current;
474 static surf_action_t communicate(void *src, void *dst, double size, double rate)
476 surf_action_workstation_KCCFLN05_t action = NULL;
477 cpu_KCCFLN05_t card_src = src;
478 cpu_KCCFLN05_t card_dst = dst;
479 route_KCCFLN05_t route = &(ROUTE(card_src->id, card_dst->id));
480 int route_size = route->size;
483 XBT_IN4("(%s,%s,%g,%g)",card_src->name,card_dst->name,size,rate);
484 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);
486 action = xbt_new0(s_surf_action_workstation_KCCFLN05_t, 1);
488 action->generic_action.using = 1;
489 action->generic_action.cost = size;
490 action->generic_action.remains = size;
491 action->generic_action.max_duration = NO_MAX_DURATION;
492 action->generic_action.start = surf_get_clock();
493 action->generic_action.finish = -1.0;
496 action->generic_action.resource_type =
497 (surf_resource_t) surf_workstation_resource;
498 action->suspended = 0; /* Should be useless because of the
499 calloc but it seems to help valgrind... */
500 action->generic_action.state_set =
501 surf_workstation_resource->common_public->states.running_action_set;
503 xbt_dynar_push(card_src->outgoing_communications, &action);
504 xbt_dynar_push(card_dst->incomming_communications, &action);
506 xbt_swag_insert(action, action->generic_action.state_set);
509 action->latency = 0.0;
510 for (i = 0; i < route_size; i++)
511 action->latency += route->links[i]->lat_current;
512 action->lat_current = action->latency;
514 if(action->latency>0)
515 action->variable = lmm_variable_new(maxmin_system, action, 0.0, -1.0,
516 route_size+4); /* +1 for the src bus
519 +1 for the dst cpu */
521 action->variable = lmm_variable_new(maxmin_system, action, 1.0, -1.0,
525 if(action->lat_current>0)
526 lmm_update_variable_bound(maxmin_system, action->variable,
527 SG_TCP_CTE_GAMMA / (2.0 * action->lat_current));
529 lmm_update_variable_bound(maxmin_system, action->variable, -1.0);
531 if(action->lat_current>0)
532 lmm_update_variable_bound(maxmin_system, action->variable,
533 min(action->rate,SG_TCP_CTE_GAMMA / (2.0 * action->lat_current)));
535 lmm_update_variable_bound(maxmin_system, action->variable, action->rate);
538 for (i = 0; i < route_size; i++)
539 lmm_expand(maxmin_system, route->links[i]->constraint, action->variable, 1.0);
541 lmm_expand(maxmin_system, card_src->bus, action->variable, 1.0);
543 lmm_expand(maxmin_system, card_dst->bus, action->variable, 1.0);
544 lmm_expand(maxmin_system, card_src->constraint, action->variable, 0.0);
545 lmm_expand(maxmin_system, card_dst->constraint, action->variable, 0.0);
548 return (surf_action_t) action;
551 /* FIXME: execute_parallel_task */
552 static surf_action_t execute_parallel_task(int workstation_nb,
553 void **workstation_list,
554 double *computation_amount,
555 double *communication_amount,
559 surf_action_workstation_KCCFLN05_t action = NULL;
561 xbt_dict_t network_link_set = xbt_dict_new();
562 xbt_dict_cursor_t cursor = NULL;
566 network_link_KCCFLN05_t link;
568 /* Compute the number of affected resources... */
569 for(i=0; i< workstation_nb; i++) {
570 for(j=0; j< workstation_nb; j++) {
571 cpu_KCCFLN05_t card_src = workstation_list[i];
572 cpu_KCCFLN05_t card_dst = workstation_list[j];
573 int route_size = ROUTE(card_src->id, card_dst->id).size;
574 network_link_KCCFLN05_t *route = ROUTE(card_src->id, card_dst->id).links;
576 if(communication_amount[i*workstation_nb+j]>0)
577 for(k=0; k< route_size; k++) {
578 xbt_dict_set(network_link_set, route[k]->name, route[k], NULL);
583 xbt_dict_foreach(network_link_set, cursor, name, link) {
587 xbt_dict_free(&network_link_set);
589 for (i = 0; i<workstation_nb; i++)
590 if(computation_amount[i]>0) nb_host++;
592 if(nb_link + workstation_nb == 0)
595 action = xbt_new0(s_surf_action_workstation_KCCFLN05_t, 1);
596 action->generic_action.using = 1;
597 action->generic_action.cost = amount;
598 action->generic_action.remains = amount;
599 action->generic_action.max_duration = NO_MAX_DURATION;
600 action->generic_action.start = -1.0;
601 action->generic_action.finish = -1.0;
602 action->generic_action.resource_type =
603 (surf_resource_t) surf_workstation_resource;
604 action->suspended = 0; /* Should be useless because of the
605 calloc but it seems to help valgrind... */
606 action->generic_action.state_set =
607 surf_workstation_resource->common_public->states.running_action_set;
609 xbt_swag_insert(action, action->generic_action.state_set);
613 action->variable = lmm_variable_new(maxmin_system, action, 1.0, -1.0,
616 action->variable = lmm_variable_new(maxmin_system, action, 1.0, action->rate,
619 for (i = 0; i<workstation_nb; i++)
620 if(computation_amount[i]>0)
621 lmm_expand(maxmin_system, ((cpu_KCCFLN05_t) workstation_list[i])->constraint,
622 action->variable, computation_amount[i]);
624 for (i=0; i<workstation_nb; i++) {
625 for(j=0; j< workstation_nb; j++) {
626 cpu_KCCFLN05_t card_src = workstation_list[i];
627 cpu_KCCFLN05_t card_dst = workstation_list[j];
628 int route_size = ROUTE(card_src->id, card_dst->id).size;
629 network_link_KCCFLN05_t *route = ROUTE(card_src->id, card_dst->id).links;
631 for(k=0; k< route_size; k++) {
632 if(communication_amount[i*workstation_nb+j]>0) {
633 lmm_expand_add(maxmin_system, route[k]->constraint,
634 action->variable, communication_amount[i*workstation_nb+j]);
640 return (surf_action_t) action;
643 /* returns an array of network_link_KCCFLN05_t */
644 static const void** get_route(void *src, void *dst) {
645 cpu_KCCFLN05_t card_src = src;
646 cpu_KCCFLN05_t card_dst = dst;
647 route_KCCFLN05_t route = &(ROUTE(card_src->id, card_dst->id));
649 return (const void**) route->links;
652 static int get_route_size(void *src, void *dst) {
653 cpu_KCCFLN05_t card_src = src;
654 cpu_KCCFLN05_t card_dst = dst;
655 route_KCCFLN05_t route = &(ROUTE(card_src->id, card_dst->id));
659 static const char *get_link_name(const void *link) {
660 return ((network_link_KCCFLN05_t) link)->name;
663 static double get_link_bandwidth(const void *link) {
664 return ((network_link_KCCFLN05_t) link)->bw_current;
667 static double get_link_latency(const void *link) {
668 return ((network_link_KCCFLN05_t) link)->lat_current;
671 /**************************************/
672 /*** Resource Creation & Destruction **/
673 /**************************************/
675 static void cpu_free(void *cpu)
677 free(((cpu_KCCFLN05_t) cpu)->name);
678 xbt_dynar_free(&(((cpu_KCCFLN05_t) cpu)->incomming_communications));
679 xbt_dynar_free(&(((cpu_KCCFLN05_t) cpu)->outgoing_communications));
683 static cpu_KCCFLN05_t cpu_new(const char *name, double power_scale,
684 double power_initial,
685 tmgr_trace_t power_trace,
686 e_surf_cpu_state_t state_initial,
687 tmgr_trace_t state_trace,
688 double interference_send,
689 double interference_recv,
690 double interference_send_recv,
691 double max_outgoing_rate)
693 cpu_KCCFLN05_t cpu = xbt_new0(s_cpu_KCCFLN05_t, 1);
695 cpu->resource = (surf_resource_t) surf_workstation_resource;
696 cpu->type = SURF_WORKSTATION_RESOURCE_CPU;
697 cpu->name = xbt_strdup(name);
698 cpu->id = nb_workstation++;
700 cpu->power_scale = power_scale;
701 xbt_assert0(cpu->power_scale > 0, "Power has to be >0");
703 cpu->power_current = power_initial;
706 tmgr_history_add_trace(history, power_trace, 0.0, 0, cpu);
708 cpu->state_current = state_initial;
711 tmgr_history_add_trace(history, state_trace, 0.0, 0, cpu);
713 cpu->interference_send = interference_send;
714 cpu->interference_recv = interference_recv;
715 cpu->interference_send_recv = interference_send_recv;
718 lmm_constraint_new(maxmin_system, cpu,
719 cpu->power_current * cpu->power_scale);
720 if (max_outgoing_rate > 0)
721 cpu->bus = lmm_constraint_new(maxmin_system, cpu, max_outgoing_rate);
723 cpu->incomming_communications =
724 xbt_dynar_new(sizeof(surf_action_workstation_KCCFLN05_t), NULL);
725 cpu->outgoing_communications =
726 xbt_dynar_new(sizeof(surf_action_workstation_KCCFLN05_t), NULL);
728 xbt_dict_set(workstation_set, name, cpu, cpu_free);
733 static void parse_cpu(void)
735 double power_scale = 0.0;
736 double power_initial = 0.0;
737 tmgr_trace_t power_trace = NULL;
738 e_surf_cpu_state_t state_initial = SURF_CPU_OFF;
739 tmgr_trace_t state_trace = NULL;
740 double interference_send = 0.0;
741 double interference_recv = 0.0;
742 double interference_send_recv = 0.0;
743 double max_outgoing_rate = -1.0;
745 surf_parse_get_double(&power_scale, A_surfxml_cpu_power);
746 surf_parse_get_double(&power_initial, A_surfxml_cpu_availability);
747 surf_parse_get_trace(&power_trace, A_surfxml_cpu_availability_file);
749 xbt_assert0((A_surfxml_cpu_state == A_surfxml_cpu_state_ON) ||
750 (A_surfxml_cpu_state == A_surfxml_cpu_state_OFF),
752 if (A_surfxml_cpu_state == A_surfxml_cpu_state_ON)
753 state_initial = SURF_CPU_ON;
754 if (A_surfxml_cpu_state == A_surfxml_cpu_state_OFF)
755 state_initial = SURF_CPU_OFF;
756 surf_parse_get_trace(&state_trace, A_surfxml_cpu_state_file);
758 surf_parse_get_double(&interference_send,
759 A_surfxml_cpu_interference_send);
760 surf_parse_get_double(&interference_recv,
761 A_surfxml_cpu_interference_recv);
762 surf_parse_get_double(&interference_send_recv,
763 A_surfxml_cpu_interference_send_recv);
764 surf_parse_get_double(&max_outgoing_rate,
765 A_surfxml_cpu_max_outgoing_rate);
767 cpu_new(A_surfxml_cpu_name, power_scale, power_initial, power_trace,
768 state_initial, state_trace, interference_send, interference_recv,
769 interference_send_recv, max_outgoing_rate);
772 static void create_routing_table(void)
775 xbt_new0(s_route_KCCFLN05_t, nb_workstation * nb_workstation);
778 static void network_link_free(void *nw_link)
780 free(((network_link_KCCFLN05_t) nw_link)->name);
784 static network_link_KCCFLN05_t network_link_new(char *name,
786 tmgr_trace_t bw_trace,
788 tmgr_trace_t lat_trace,
789 e_surf_network_link_state_t
791 tmgr_trace_t state_trace,
792 e_surf_network_link_sharing_policy_t policy)
794 network_link_KCCFLN05_t nw_link = xbt_new0(s_network_link_KCCFLN05_t, 1);
797 nw_link->resource = (surf_resource_t) surf_workstation_resource;
798 nw_link->type = SURF_WORKSTATION_RESOURCE_LINK;
799 nw_link->name = name;
800 nw_link->bw_current = bw_initial;
803 tmgr_history_add_trace(history, bw_trace, 0.0, 0, nw_link);
804 nw_link->state_current = state_initial;
805 nw_link->lat_current = lat_initial;
808 tmgr_history_add_trace(history, lat_trace, 0.0, 0, nw_link);
810 nw_link->state_event =
811 tmgr_history_add_trace(history, state_trace, 0.0, 0, nw_link);
813 nw_link->constraint =
814 lmm_constraint_new(maxmin_system, nw_link, nw_link->bw_current);
816 if(policy == SURF_NETWORK_LINK_FATPIPE)
817 lmm_constraint_shared(nw_link->constraint);
819 xbt_dict_set(network_link_set, name, nw_link, network_link_free);
824 static void parse_network_link(void)
828 tmgr_trace_t bw_trace;
830 tmgr_trace_t lat_trace;
831 e_surf_network_link_state_t state_initial = SURF_NETWORK_LINK_ON;
832 e_surf_network_link_sharing_policy_t policy_initial = SURF_NETWORK_LINK_SHARED;
833 tmgr_trace_t state_trace;
835 name = xbt_strdup(A_surfxml_network_link_name);
836 surf_parse_get_double(&bw_initial,A_surfxml_network_link_bandwidth);
837 surf_parse_get_trace(&bw_trace, A_surfxml_network_link_bandwidth_file);
838 surf_parse_get_double(&lat_initial,A_surfxml_network_link_latency);
839 surf_parse_get_trace(&lat_trace, A_surfxml_network_link_latency_file);
841 xbt_assert0((A_surfxml_network_link_state==A_surfxml_network_link_state_ON)||
842 (A_surfxml_network_link_state==A_surfxml_network_link_state_OFF),
844 if (A_surfxml_network_link_state==A_surfxml_network_link_state_ON)
845 state_initial = SURF_NETWORK_LINK_ON;
846 else if (A_surfxml_network_link_state==A_surfxml_network_link_state_OFF)
847 state_initial = SURF_NETWORK_LINK_OFF;
849 if (A_surfxml_network_link_sharing_policy==A_surfxml_network_link_sharing_policy_SHARED)
850 policy_initial = SURF_NETWORK_LINK_SHARED;
851 else if (A_surfxml_network_link_sharing_policy==A_surfxml_network_link_sharing_policy_FATPIPE)
852 policy_initial = SURF_NETWORK_LINK_FATPIPE;
854 surf_parse_get_trace(&state_trace,A_surfxml_network_link_state_file);
856 network_link_new(name, bw_initial, bw_trace,
857 lat_initial, lat_trace, state_initial, state_trace,
861 static void route_new(int src_id, int dst_id, char **links, int nb_link,
862 double impact_on_src, double impact_on_dst,
863 double impact_on_src_with_other_recv,
864 double impact_on_dst_with_other_send)
866 network_link_KCCFLN05_t *link_list = NULL;
868 route_KCCFLN05_t route = &(ROUTE(src_id, dst_id));
870 route->size = nb_link;
871 link_list = route->links = xbt_new0(network_link_KCCFLN05_t, nb_link);
872 for (i = 0; i < nb_link; i++) {
873 link_list[i] = xbt_dict_get_or_null(network_link_set, links[i]);
877 route->impact_on_src = impact_on_src;
878 route->impact_on_dst = impact_on_src;
879 route->impact_on_src_with_other_recv = impact_on_src_with_other_recv;
880 route->impact_on_dst_with_other_send = impact_on_dst_with_other_send;
883 static int nb_link = 0;
884 static char **link_name = NULL;
885 static int src_id = -1;
886 static int dst_id = -1;
887 static double impact_on_src;
888 static double impact_on_dst;
889 static double impact_on_src_with_other_recv;
890 static double impact_on_dst_with_other_send;
892 static void parse_route_set_endpoints(void)
894 src_id = ((cpu_KCCFLN05_t) name_service(A_surfxml_route_src))->id;
895 dst_id = ((cpu_KCCFLN05_t) name_service(A_surfxml_route_dst))->id;
896 surf_parse_get_double(&impact_on_src, A_surfxml_route_impact_on_src);
897 surf_parse_get_double(&impact_on_dst, A_surfxml_route_impact_on_dst);
898 surf_parse_get_double(&impact_on_src_with_other_recv,
899 A_surfxml_route_impact_on_src_with_other_recv);
900 surf_parse_get_double(&impact_on_dst_with_other_send,
901 A_surfxml_route_impact_on_dst_with_other_send);
907 static void parse_route_elem(void)
910 link_name = xbt_realloc(link_name, (nb_link) * sizeof(char *));
911 link_name[(nb_link) - 1] = xbt_strdup(A_surfxml_route_element_name);
914 static void parse_route_set_route(void)
916 route_new(src_id, dst_id, link_name, nb_link, impact_on_src,
917 impact_on_dst, impact_on_src_with_other_recv,
918 impact_on_dst_with_other_send);
921 static void parse_file(const char *file)
925 /* Figuring out the cpus */
926 surf_parse_reset_parser();
927 ETag_surfxml_cpu_fun = parse_cpu;
928 surf_parse_open(file);
929 xbt_assert1((!surf_parse()), "Parse error in %s", file);
932 create_routing_table();
934 /* Figuring out the network links */
935 surf_parse_reset_parser();
936 ETag_surfxml_network_link_fun = parse_network_link;
937 surf_parse_open(file);
938 xbt_assert1((!surf_parse()), "Parse error in %s", file);
941 /* Building the routes */
942 surf_parse_reset_parser();
943 STag_surfxml_route_fun = parse_route_set_endpoints;
944 ETag_surfxml_route_element_fun = parse_route_elem;
945 ETag_surfxml_route_fun = parse_route_set_route;
946 surf_parse_open(file);
947 xbt_assert1((!surf_parse()), "Parse error in %s", file);
950 /* Adding loopback if needed */
951 for (i = 0; i < nb_workstation; i++)
952 if(!ROUTE(i,i).size) {
954 loopback = network_link_new(xbt_strdup("__MSG_loopback__"),
955 498.00, NULL, 0.000015, NULL,
956 SURF_NETWORK_LINK_ON, NULL,
957 SURF_NETWORK_LINK_FATPIPE);
959 ROUTE(i,i).links = xbt_new0(network_link_KCCFLN05_t, 1);
960 ROUTE(i,i).links[0] = loopback;
965 /**************************************/
966 /********* Module creation ***********/
967 /**************************************/
969 static void resource_init_internal(void)
971 s_surf_action_t action;
973 surf_workstation_resource = xbt_new0(s_surf_workstation_resource_t, 1);
975 surf_workstation_resource->common_private =
976 xbt_new0(s_surf_resource_private_t, 1);
977 surf_workstation_resource->common_public =
978 xbt_new0(s_surf_resource_public_t, 1);
979 surf_workstation_resource->extension_public =
980 xbt_new0(s_surf_workstation_resource_extension_public_t, 1);
982 surf_workstation_resource->common_public->states.ready_action_set =
983 xbt_swag_new(xbt_swag_offset(action, state_hookup));
984 surf_workstation_resource->common_public->states.running_action_set =
985 xbt_swag_new(xbt_swag_offset(action, state_hookup));
986 surf_workstation_resource->common_public->states.failed_action_set =
987 xbt_swag_new(xbt_swag_offset(action, state_hookup));
988 surf_workstation_resource->common_public->states.done_action_set =
989 xbt_swag_new(xbt_swag_offset(action, state_hookup));
991 surf_workstation_resource->common_public->name_service = name_service;
992 surf_workstation_resource->common_public->get_resource_name = get_resource_name;
993 surf_workstation_resource->common_public->action_get_state = surf_action_get_state;
994 surf_workstation_resource->common_public->action_get_start_time =
995 surf_action_get_start_time;
996 surf_workstation_resource->common_public->action_get_finish_time =
997 surf_action_get_finish_time;
998 surf_workstation_resource->common_public->action_use = action_use;
999 surf_workstation_resource->common_public->action_free = action_free;
1000 surf_workstation_resource->common_public->action_cancel = action_cancel;
1001 surf_workstation_resource->common_public->action_recycle = action_recycle;
1002 surf_workstation_resource->common_public->action_change_state = surf_action_change_state;
1003 surf_workstation_resource->common_public->action_set_data = surf_action_set_data;
1004 surf_workstation_resource->common_public->suspend = action_suspend;
1005 surf_workstation_resource->common_public->resume = action_resume;
1006 surf_workstation_resource->common_public->is_suspended = action_is_suspended;
1007 surf_workstation_resource->common_public->set_max_duration = action_set_max_duration;
1008 surf_workstation_resource->common_public->set_priority = action_set_priority;
1009 surf_workstation_resource->common_public->name = "Workstation KCCFLN05";
1011 surf_workstation_resource->common_private->resource_used = resource_used;
1012 surf_workstation_resource->common_private->share_resources = share_resources;
1013 surf_workstation_resource->common_private->update_actions_state = update_actions_state;
1014 surf_workstation_resource->common_private->update_resource_state = update_resource_state;
1015 surf_workstation_resource->common_private->finalize = finalize;
1017 surf_workstation_resource->extension_public->execute = execute;
1018 surf_workstation_resource->extension_public->sleep = action_sleep;
1019 surf_workstation_resource->extension_public->get_state = resource_get_state;
1020 surf_workstation_resource->extension_public->get_speed = get_speed;
1021 surf_workstation_resource->extension_public->get_available_speed = get_available_speed;
1022 surf_workstation_resource->extension_public->communicate = communicate;
1023 surf_workstation_resource->extension_public->execute_parallel_task = execute_parallel_task;
1024 surf_workstation_resource->extension_public->get_route = get_route;
1025 surf_workstation_resource->extension_public->get_route_size = get_route_size;
1026 surf_workstation_resource->extension_public->get_link_name = get_link_name;
1027 surf_workstation_resource->extension_public->get_link_bandwidth = get_link_bandwidth;
1028 surf_workstation_resource->extension_public->get_link_latency = get_link_latency;
1030 workstation_set = xbt_dict_new();
1031 network_link_set = xbt_dict_new();
1033 xbt_assert0(maxmin_system, "surf_init has to be called first!");
1036 /**************************************/
1037 /*************** Generic **************/
1038 /**************************************/
1039 void surf_workstation_resource_init_KCCFLN05(const char *filename)
1041 xbt_assert0(!surf_cpu_resource, "CPU resource type already defined");
1042 xbt_assert0(!surf_network_resource, "network resource type already defined");
1043 resource_init_internal();
1044 parse_file(filename);
1046 xbt_dynar_push(resource_list, &surf_workstation_resource);