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;
19 static xbt_dict_t parallel_task_network_link_set = NULL;
20 //added to work with GTNETS
21 static xbt_dict_t router_set = NULL;
23 /*xbt_dict_t network_link_set = NULL;*/
26 /* convenient function */
27 static void __update_cpu_usage(cpu_KCCFLN05_t cpu)
30 surf_action_workstation_KCCFLN05_t action = NULL;
31 if ((!xbt_dynar_length(cpu->incomming_communications)) &&
32 (!xbt_dynar_length(cpu->outgoing_communications))) {
33 /* No communications */
34 lmm_update_constraint_bound(maxmin_system, cpu->constraint,
35 cpu->power_current * cpu->power_scale);
36 } else if ((!xbt_dynar_length(cpu->incomming_communications))
37 && (xbt_dynar_length(cpu->outgoing_communications))) {
39 lmm_update_constraint_bound(maxmin_system, cpu->constraint,
40 cpu->power_current * cpu->power_scale *
41 cpu->interference_send);
42 xbt_dynar_foreach(cpu->outgoing_communications, cpt, action)
43 lmm_elem_set_value(maxmin_system,cpu->constraint,action->variable,
44 cpu->power_current * cpu->power_scale *
45 ROUTE(action->src->id, action->dst->id).impact_on_src
47 } else if ((xbt_dynar_length(cpu->incomming_communications)) &&
48 (!xbt_dynar_length(cpu->outgoing_communications))) {
50 lmm_update_constraint_bound(maxmin_system, cpu->constraint,
51 cpu->power_current * cpu->power_scale *
52 cpu->interference_recv);
53 xbt_dynar_foreach(cpu->incomming_communications, cpt, action)
54 lmm_elem_set_value(maxmin_system,cpu->constraint,action->variable,
55 cpu->power_current * cpu->power_scale *
56 ROUTE(action->src->id, action->dst->id).impact_on_dst
59 /* Emission & Reception */
60 lmm_update_constraint_bound(maxmin_system, cpu->constraint,
61 cpu->power_current * cpu->power_scale *
62 cpu->interference_send_recv);
63 xbt_dynar_foreach(cpu->outgoing_communications, cpt, action)
64 lmm_elem_set_value(maxmin_system,cpu->constraint,action->variable,
65 cpu->power_current * cpu->power_scale *
66 ROUTE(action->src->id, action->dst->id).impact_on_src_with_other_recv
68 xbt_dynar_foreach(cpu->incomming_communications, cpt, action)
69 lmm_elem_set_value(maxmin_system,cpu->constraint,action->variable,
70 cpu->power_current * cpu->power_scale *
71 ROUTE(action->src->id, action->dst->id).impact_on_dst_with_other_send
76 /**************************************/
77 /******* Resource Public **********/
78 /**************************************/
80 static void *name_service(const char *name)
86 res = xbt_dict_get_or_null(workstation_set, name);
88 if (e.category != not_found_error)
90 WARN1("Host '%s' not found, verifing if it is a router", name);
98 static const char *get_resource_name(void *resource_id)
100 /* We can freely cast as a cpu_KCCFLN05_t because it has the same
101 prefix as network_link_KCCFLN05_t. However, only cpu_KCCFLN05_t
102 will theoretically be given as an argument here. */
103 return ((cpu_KCCFLN05_t) resource_id)->name;
106 /* action_get_state is inherited from the surf module */
108 static void action_use(surf_action_t action)
114 static int action_free(surf_action_t action)
117 surf_action_t act = NULL;
118 cpu_KCCFLN05_t src = ((surf_action_workstation_KCCFLN05_t) action)->src;
119 cpu_KCCFLN05_t dst = ((surf_action_workstation_KCCFLN05_t) action)->dst;
122 if (!action->using) {
123 xbt_swag_remove(action, action->state_set);
124 if (((surf_action_workstation_KCCFLN05_t) action)->variable)
125 lmm_variable_free(maxmin_system,
126 ((surf_action_workstation_KCCFLN05_t) action)->
129 xbt_dynar_foreach(src->outgoing_communications, cpt, act)
131 xbt_dynar_remove_at(src->outgoing_communications, cpt, &act);
136 xbt_dynar_foreach(dst->incomming_communications, cpt, act)
138 xbt_dynar_remove_at(dst->incomming_communications, cpt, &act);
142 if(src && (!xbt_dynar_length(src->outgoing_communications)))
143 __update_cpu_usage(src);
144 if(dst && (!xbt_dynar_length(dst->incomming_communications)))
145 __update_cpu_usage(dst);
153 static void action_cancel(surf_action_t action)
155 surf_action_change_state(action, SURF_ACTION_FAILED);
159 static void action_recycle(surf_action_t action)
165 /* action_change_state is inherited from the surf module */
166 /* action_set_data is inherited from the surf module */
168 static void action_suspend(surf_action_t action)
170 XBT_IN1("(%p))",action);
171 if(((surf_action_workstation_KCCFLN05_t) action)->suspended != 2) {
172 ((surf_action_workstation_KCCFLN05_t) action)->suspended = 1;
173 lmm_update_variable_weight(maxmin_system,
174 ((surf_action_workstation_KCCFLN05_t)
175 action)->variable, 0.0);
180 static void action_resume(surf_action_t action)
182 XBT_IN1("(%p)",action);
183 if(((surf_action_workstation_KCCFLN05_t) action)->suspended !=2) {
184 if(((surf_action_workstation_KCCFLN05_t)action)->lat_current==0.0)
185 lmm_update_variable_weight(maxmin_system,
186 ((surf_action_workstation_KCCFLN05_t)
187 action)->variable, 1.0);
189 lmm_update_variable_weight(maxmin_system,
190 ((surf_action_workstation_KCCFLN05_t) action)->variable,
191 ((surf_action_workstation_KCCFLN05_t) action)->lat_current);
193 ((surf_action_workstation_KCCFLN05_t) action)->suspended = 0;
198 static int action_is_suspended(surf_action_t action)
200 return (((surf_action_workstation_KCCFLN05_t) action)->suspended==1);
203 static void action_set_max_duration(surf_action_t action, double duration)
204 { /* FIXME: should inherit */
205 XBT_IN2("(%p,%g)",action,duration);
206 action->max_duration = duration;
211 static void action_set_priority(surf_action_t action, double priority)
212 { /* FIXME: should inherit */
213 XBT_IN2("(%p,%g)",action,priority);
214 action->priority = priority;
218 /**************************************/
219 /******* Resource Private **********/
220 /**************************************/
222 static int resource_used(void *resource_id)
224 /* We can freely cast as a network_link_KCCFLN05_t because it has
225 the same prefix as cpu_KCCFLN05_t */
226 if(((cpu_KCCFLN05_t) resource_id)->type == SURF_WORKSTATION_RESOURCE_CPU)
227 return (lmm_constraint_used(maxmin_system,
228 ((cpu_KCCFLN05_t) resource_id)->
230 ((((cpu_KCCFLN05_t) resource_id)->bus)?
231 lmm_constraint_used(maxmin_system,
232 ((cpu_KCCFLN05_t) resource_id)->
235 return lmm_constraint_used(maxmin_system,
236 ((network_link_KCCFLN05_t) resource_id)->
241 static double share_resources(double now)
243 s_surf_action_workstation_KCCFLN05_t s_action;
244 surf_action_workstation_KCCFLN05_t action = NULL;
246 xbt_swag_t running_actions = surf_workstation_resource->common_public->states.running_action_set;
247 double min = generic_maxmin_share_resources(running_actions,
248 xbt_swag_offset(s_action, variable));
250 xbt_swag_foreach(action, running_actions) {
251 if(action->latency>0) {
253 min = action->latency;
254 DEBUG3("Updating min (value) with %p (start %f): %f",action,
255 action->generic_action.start, min);
257 else if (action->latency<min) {
258 min = action->latency;
259 DEBUG3("Updating min (latency) with %p (start %f): %f",action,
260 action->generic_action.start, min);
265 DEBUG1("min value : %f",min);
270 static void update_actions_state(double now, double delta)
273 surf_action_workstation_KCCFLN05_t action = NULL;
274 surf_action_workstation_KCCFLN05_t next_action = NULL;
275 xbt_swag_t running_actions =
276 surf_workstation_resource->common_public->states.running_action_set;
278 xbt_swag_foreach_safe(action, next_action, running_actions) {
280 if (action->latency > 0) {
281 if (action->latency > deltap) {
282 double_update(&(action->latency), deltap);
285 double_update(&(deltap), action->latency);
286 action->latency = 0.0;
288 if ((action->latency == 0.0) && (action->suspended==0)) {
289 if((action)->lat_current==0.0)
290 lmm_update_variable_weight(maxmin_system,action->variable, 1.0);
292 lmm_update_variable_weight(maxmin_system, action->variable,
293 action->lat_current);
296 DEBUG3("Action (%p) : remains (%g) updated by %g.",
297 action, action->generic_action.remains,
298 lmm_variable_getvalue(action->variable) * deltap);
299 double_update(&(action->generic_action.remains),
300 lmm_variable_getvalue(action->variable) * deltap);
302 if (action->generic_action.max_duration != NO_MAX_DURATION)
303 double_update(&(action->generic_action.max_duration), delta);
305 /* if(action->generic_action.remains<.00001) action->generic_action.remains=0; */
307 if ((action->generic_action.remains <= 0) &&
308 (lmm_get_variable_weight(action->variable)>0)) {
309 action->generic_action.finish = surf_get_clock();
310 surf_action_change_state((surf_action_t) action, SURF_ACTION_DONE);
311 } else if ((action->generic_action.max_duration != NO_MAX_DURATION) &&
312 (action->generic_action.max_duration <= 0)) {
313 action->generic_action.finish = surf_get_clock();
314 surf_action_change_state((surf_action_t) action, SURF_ACTION_DONE);
315 } else { /* Need to check that none of the resource has failed */
316 lmm_constraint_t cnst = NULL;
318 void *constraint_id = NULL;
321 lmm_get_cnst_from_var(maxmin_system, action->variable,
323 constraint_id = lmm_constraint_id(cnst);
324 if(((((network_link_KCCFLN05_t)constraint_id)->type==
325 SURF_WORKSTATION_RESOURCE_LINK) &&
326 (((network_link_KCCFLN05_t)constraint_id)->state_current==
327 SURF_NETWORK_LINK_OFF)) ||
328 ((((cpu_KCCFLN05_t)constraint_id)->type==
329 SURF_WORKSTATION_RESOURCE_CPU) &&
330 (((cpu_KCCFLN05_t)constraint_id)->state_current==
332 action->generic_action.finish = surf_get_clock();
333 surf_action_change_state((surf_action_t) action, SURF_ACTION_FAILED);
342 static void update_resource_state(void *id,
343 tmgr_trace_event_t event_type,
346 cpu_KCCFLN05_t cpu = id;
347 network_link_KCCFLN05_t nw_link = id ;
349 if(nw_link->type == SURF_WORKSTATION_RESOURCE_LINK) {
350 if (event_type == nw_link->bw_event) {
351 nw_link->bw_current = value;
352 lmm_update_constraint_bound(maxmin_system, nw_link->constraint,
353 nw_link->bw_current);
354 } else if (event_type == nw_link->lat_event) {
355 double delta = value - nw_link->lat_current;
356 lmm_variable_t var = NULL;
357 surf_action_workstation_KCCFLN05_t action = NULL;
359 nw_link->lat_current = value;
360 while (lmm_get_var_from_cnst(maxmin_system, nw_link->constraint, &var)) {
361 action = lmm_variable_id(var);
362 action->lat_current += delta;
364 lmm_update_variable_bound(maxmin_system, action->variable,
365 SG_TCP_CTE_GAMMA / (2.0 * action->lat_current));
367 lmm_update_variable_bound(maxmin_system, action->variable,
368 min(action->rate,SG_TCP_CTE_GAMMA / (2.0 * action->lat_current)));
369 if(action->suspended==0)
370 lmm_update_variable_weight(maxmin_system, action->variable,
371 action->lat_current);
372 lmm_update_variable_latency(maxmin_system, action->variable, delta);
376 } else if (event_type == nw_link->state_event) {
378 nw_link->state_current = SURF_NETWORK_LINK_ON;
380 nw_link->state_current = SURF_NETWORK_LINK_OFF;
382 CRITICAL0("Unknown event ! \n");
386 } else if(cpu->type == SURF_WORKSTATION_RESOURCE_CPU) {
387 if (event_type == cpu->power_event) {
388 cpu->power_current = value;
389 __update_cpu_usage(cpu);
390 } else if (event_type == cpu->state_event) {
392 cpu->state_current = SURF_CPU_ON;
394 cpu->state_current = SURF_CPU_OFF;
396 CRITICAL0("Unknown event ! \n");
406 static void finalize(void)
410 xbt_dict_free(&network_link_set);
411 xbt_dict_free(&workstation_set);
412 xbt_dict_free(&router_set);
413 if (parallel_task_network_link_set != NULL) {
414 xbt_dict_free(¶llel_task_network_link_set);
416 xbt_swag_free(surf_workstation_resource->common_public->states.
418 xbt_swag_free(surf_workstation_resource->common_public->states.
420 xbt_swag_free(surf_workstation_resource->common_public->states.
422 xbt_swag_free(surf_workstation_resource->common_public->states.
425 free(surf_workstation_resource->common_public);
426 free(surf_workstation_resource->common_private);
427 free(surf_workstation_resource->extension_public);
429 free(surf_workstation_resource);
430 surf_workstation_resource = NULL;
432 for (i = 0; i < nb_workstation; i++)
433 for (j = 0; j < nb_workstation; j++)
434 free(ROUTE(i, j).links);
436 routing_table = NULL;
440 lmm_system_free(maxmin_system);
441 maxmin_system = NULL;
445 /**************************************/
446 /******* Resource Private **********/
447 /**************************************/
449 static surf_action_t execute(void *cpu, double size)
451 surf_action_workstation_KCCFLN05_t action = NULL;
452 cpu_KCCFLN05_t CPU = cpu;
454 XBT_IN2("(%s,%g)",CPU->name,size);
455 action = xbt_new0(s_surf_action_workstation_KCCFLN05_t, 1);
457 action->generic_action.using = 1;
458 action->generic_action.cost = size;
459 action->generic_action.remains = size;
460 action->generic_action.priority = 1.0;
461 action->generic_action.max_duration = NO_MAX_DURATION;
462 action->generic_action.start = surf_get_clock();
463 action->generic_action.finish = -1.0;
464 action->generic_action.resource_type =
465 (surf_resource_t) surf_workstation_resource;
466 action->suspended = 0;
468 if (CPU->state_current == SURF_CPU_ON)
469 action->generic_action.state_set =
470 surf_workstation_resource->common_public->states.running_action_set;
472 action->generic_action.state_set =
473 surf_workstation_resource->common_public->states.failed_action_set;
474 xbt_swag_insert(action, action->generic_action.state_set);
476 action->variable = lmm_variable_new(maxmin_system, action,
477 action->generic_action.priority, -1.0, 1);
478 lmm_expand(maxmin_system, CPU->constraint, action->variable,
481 return (surf_action_t) action;
484 static surf_action_t action_sleep(void *cpu, double duration)
486 surf_action_workstation_KCCFLN05_t action = NULL;
488 XBT_IN2("(%s,%g)",((cpu_KCCFLN05_t)cpu)->name,duration);
490 action = (surf_action_workstation_KCCFLN05_t) execute(cpu, 1.0);
491 action->generic_action.max_duration = duration;
492 action->suspended = 2;
493 lmm_update_variable_weight(maxmin_system, action->variable, 0.0);
496 return (surf_action_t) action;
499 static e_surf_cpu_state_t resource_get_state(void *cpu)
501 return ((cpu_KCCFLN05_t) cpu)->state_current;
504 static double get_speed(void *cpu, double load)
506 return load*(((cpu_KCCFLN05_t) cpu)->power_scale);
509 static double get_available_speed(void *cpu)
511 return ((cpu_KCCFLN05_t) cpu)->power_current;
515 static surf_action_t communicate(void *src, void *dst, double size, double rate)
517 surf_action_workstation_KCCFLN05_t action = NULL;
518 cpu_KCCFLN05_t card_src = src;
519 cpu_KCCFLN05_t card_dst = dst;
520 route_KCCFLN05_t route = &(ROUTE(card_src->id, card_dst->id));
521 int route_size = route->size;
524 XBT_IN4("(%s,%s,%g,%g)",card_src->name,card_dst->name,size,rate);
525 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);
527 action = xbt_new0(s_surf_action_workstation_KCCFLN05_t, 1);
529 action->generic_action.using = 1;
530 action->generic_action.cost = size;
531 action->generic_action.remains = size;
532 action->generic_action.max_duration = NO_MAX_DURATION;
533 action->generic_action.start = surf_get_clock();
534 action->generic_action.finish = -1.0;
537 action->generic_action.resource_type =
538 (surf_resource_t) surf_workstation_resource;
539 action->suspended = 0; /* Should be useless because of the
540 calloc but it seems to help valgrind... */
541 action->generic_action.state_set =
542 surf_workstation_resource->common_public->states.running_action_set;
544 xbt_dynar_push(card_src->outgoing_communications, &action);
545 xbt_dynar_push(card_dst->incomming_communications, &action);
547 xbt_swag_insert(action, action->generic_action.state_set);
550 action->latency = 0.0;
551 for (i = 0; i < route_size; i++)
552 action->latency += route->links[i]->lat_current;
553 action->lat_current = action->latency;
555 if(action->latency>0)
556 action->variable = lmm_variable_new(maxmin_system, action, 0.0, -1.0,
557 route_size+4); /* +1 for the src bus
560 +1 for the dst cpu */
562 action->variable = lmm_variable_new(maxmin_system, action, 1.0, -1.0,
566 if(action->lat_current>0)
567 lmm_update_variable_bound(maxmin_system, action->variable,
568 SG_TCP_CTE_GAMMA / (2.0 * action->lat_current));
570 lmm_update_variable_bound(maxmin_system, action->variable, -1.0);
572 if(action->lat_current>0)
573 lmm_update_variable_bound(maxmin_system, action->variable,
574 min(action->rate,SG_TCP_CTE_GAMMA / (2.0 * action->lat_current)));
576 lmm_update_variable_bound(maxmin_system, action->variable, action->rate);
579 lmm_update_variable_latency(maxmin_system, action->variable, action->latency);
581 for (i = 0; i < route_size; i++)
582 lmm_expand(maxmin_system, route->links[i]->constraint, action->variable, 1.0);
584 lmm_expand(maxmin_system, card_src->bus, action->variable, 1.0);
586 lmm_expand(maxmin_system, card_dst->bus, action->variable, 1.0);
587 lmm_expand(maxmin_system, card_src->constraint, action->variable, 0.0);
588 lmm_expand(maxmin_system, card_dst->constraint, action->variable, 0.0);
591 return (surf_action_t) action;
594 static surf_action_t execute_parallel_task(int workstation_nb,
595 void **workstation_list,
596 double *computation_amount,
597 double *communication_amount,
601 surf_action_workstation_KCCFLN05_t action = NULL;
606 if (parallel_task_network_link_set == NULL) {
607 parallel_task_network_link_set = xbt_dict_new_ext(workstation_nb * workstation_nb * 10);
610 /* Compute the number of affected resources... */
611 for(i=0; i< workstation_nb; i++) {
612 for(j=0; j< workstation_nb; j++) {
613 cpu_KCCFLN05_t card_src = workstation_list[i];
614 cpu_KCCFLN05_t card_dst = workstation_list[j];
615 int route_size = ROUTE(card_src->id, card_dst->id).size;
616 network_link_KCCFLN05_t *route = ROUTE(card_src->id, card_dst->id).links;
618 if(communication_amount[i*workstation_nb+j]>0)
619 for(k=0; k< route_size; k++) {
620 xbt_dict_set(parallel_task_network_link_set, route[k]->name, route[k], NULL);
624 nb_link = xbt_dict_length(parallel_task_network_link_set);
625 xbt_dict_reset(parallel_task_network_link_set);
628 for (i = 0; i<workstation_nb; i++)
629 if(computation_amount[i]>0) nb_host++;
632 if(nb_link + nb_host == 0) /* was workstation_nb... */
635 action = xbt_new0(s_surf_action_workstation_KCCFLN05_t, 1);
636 DEBUG3("Creating a parallel task (%p) with %d cpus and %d links.",
637 action, nb_host, nb_link);
638 action->generic_action.using = 1;
639 action->generic_action.cost = amount;
640 action->generic_action.remains = amount;
641 action->generic_action.max_duration = NO_MAX_DURATION;
642 action->generic_action.start = -1.0;
643 action->generic_action.finish = -1.0;
644 action->generic_action.resource_type =
645 (surf_resource_t) surf_workstation_resource;
646 action->suspended = 0; /* Should be useless because of the
647 calloc but it seems to help valgrind... */
648 action->generic_action.state_set =
649 surf_workstation_resource->common_public->states.running_action_set;
651 xbt_swag_insert(action, action->generic_action.state_set);
655 action->variable = lmm_variable_new(maxmin_system, action, 1.0, -1.0,
658 action->variable = lmm_variable_new(maxmin_system, action, 1.0, action->rate,
661 for (i = 0; i<workstation_nb; i++)
662 if(computation_amount[i]>0)
663 lmm_expand(maxmin_system, ((cpu_KCCFLN05_t) workstation_list[i])->constraint,
664 action->variable, computation_amount[i]);
666 for (i=0; i<workstation_nb; i++) {
667 for(j=0; j< workstation_nb; j++) {
668 cpu_KCCFLN05_t card_src = workstation_list[i];
669 cpu_KCCFLN05_t card_dst = workstation_list[j];
670 int route_size = ROUTE(card_src->id, card_dst->id).size;
671 network_link_KCCFLN05_t *route = ROUTE(card_src->id, card_dst->id).links;
673 for(k=0; k< route_size; k++) {
674 if(communication_amount[i*workstation_nb+j]>0) {
675 lmm_expand_add(maxmin_system, route[k]->constraint,
676 action->variable, communication_amount[i*workstation_nb+j]);
682 return (surf_action_t) action;
685 /* returns an array of network_link_KCCFLN05_t */
686 static const void** get_route(void *src, void *dst) {
687 cpu_KCCFLN05_t card_src = src;
688 cpu_KCCFLN05_t card_dst = dst;
689 route_KCCFLN05_t route = &(ROUTE(card_src->id, card_dst->id));
691 return (const void**) route->links;
694 static int get_route_size(void *src, void *dst) {
695 cpu_KCCFLN05_t card_src = src;
696 cpu_KCCFLN05_t card_dst = dst;
697 route_KCCFLN05_t route = &(ROUTE(card_src->id, card_dst->id));
701 static const char *get_link_name(const void *link) {
702 return ((network_link_KCCFLN05_t) link)->name;
705 static double get_link_bandwidth(const void *link) {
706 return ((network_link_KCCFLN05_t) link)->bw_current;
709 static double get_link_latency(const void *link) {
710 return ((network_link_KCCFLN05_t) link)->lat_current;
713 /**************************************/
714 /*** Resource Creation & Destruction **/
715 /**************************************/
718 static void router_free(void *router)
720 free( ((router_KCCFLN05_t) router)->name );
723 static void router_new(const char *name)
725 static unsigned int nb_routers = 0;
727 INFO1("Creating a router %s", name);
729 router_KCCFLN05_t router;
730 router = xbt_new0(s_router_KCCFLN05_t, 1);
732 router->name = xbt_strdup(name);
733 router->id = nb_routers++;
734 xbt_dict_set(router_set, name, router, router_free);
737 static void parse_routers(void)
739 //add a dumb router just to be GTNETS compatible
740 router_new(A_surfxml_router_name);
743 static void cpu_free(void *cpu)
745 free(((cpu_KCCFLN05_t) cpu)->name);
746 xbt_dynar_free(&(((cpu_KCCFLN05_t) cpu)->incomming_communications));
747 xbt_dynar_free(&(((cpu_KCCFLN05_t) cpu)->outgoing_communications));
751 static cpu_KCCFLN05_t cpu_new(const char *name, double power_scale,
752 double power_initial,
753 tmgr_trace_t power_trace,
754 e_surf_cpu_state_t state_initial,
755 tmgr_trace_t state_trace,
756 double interference_send,
757 double interference_recv,
758 double interference_send_recv,
759 double max_outgoing_rate)
761 cpu_KCCFLN05_t cpu = xbt_new0(s_cpu_KCCFLN05_t, 1);
763 cpu->resource = (surf_resource_t) surf_workstation_resource;
764 cpu->type = SURF_WORKSTATION_RESOURCE_CPU;
765 cpu->name = xbt_strdup(name);
766 cpu->id = nb_workstation++;
768 cpu->power_scale = power_scale;
769 xbt_assert0(cpu->power_scale > 0, "Power has to be >0");
771 cpu->power_current = power_initial;
774 tmgr_history_add_trace(history, power_trace, 0.0, 0, cpu);
776 cpu->state_current = state_initial;
779 tmgr_history_add_trace(history, state_trace, 0.0, 0, cpu);
781 cpu->interference_send = interference_send;
782 cpu->interference_recv = interference_recv;
783 cpu->interference_send_recv = interference_send_recv;
786 lmm_constraint_new(maxmin_system, cpu,
787 cpu->power_current * cpu->power_scale);
788 if (max_outgoing_rate > 0)
789 cpu->bus = lmm_constraint_new(maxmin_system, cpu, max_outgoing_rate);
791 cpu->incomming_communications =
792 xbt_dynar_new(sizeof(surf_action_workstation_KCCFLN05_t), NULL);
793 cpu->outgoing_communications =
794 xbt_dynar_new(sizeof(surf_action_workstation_KCCFLN05_t), NULL);
796 xbt_dict_set(workstation_set, name, cpu, cpu_free);
801 static void parse_cpu(void)
803 double power_scale = 0.0;
804 double power_initial = 0.0;
805 tmgr_trace_t power_trace = NULL;
806 e_surf_cpu_state_t state_initial = SURF_CPU_OFF;
807 tmgr_trace_t state_trace = NULL;
808 double interference_send = 0.0;
809 double interference_recv = 0.0;
810 double interference_send_recv = 0.0;
811 double max_outgoing_rate = -1.0;
813 surf_parse_get_double(&power_scale, A_surfxml_cpu_power);
814 surf_parse_get_double(&power_initial, A_surfxml_cpu_availability);
815 surf_parse_get_trace(&power_trace, A_surfxml_cpu_availability_file);
817 xbt_assert0((A_surfxml_cpu_state == A_surfxml_cpu_state_ON) ||
818 (A_surfxml_cpu_state == A_surfxml_cpu_state_OFF),
820 if (A_surfxml_cpu_state == A_surfxml_cpu_state_ON)
821 state_initial = SURF_CPU_ON;
822 if (A_surfxml_cpu_state == A_surfxml_cpu_state_OFF)
823 state_initial = SURF_CPU_OFF;
824 surf_parse_get_trace(&state_trace, A_surfxml_cpu_state_file);
826 surf_parse_get_double(&interference_send,
827 A_surfxml_cpu_interference_send);
828 surf_parse_get_double(&interference_recv,
829 A_surfxml_cpu_interference_recv);
830 surf_parse_get_double(&interference_send_recv,
831 A_surfxml_cpu_interference_send_recv);
832 surf_parse_get_double(&max_outgoing_rate,
833 A_surfxml_cpu_max_outgoing_rate);
835 cpu_new(A_surfxml_cpu_name, power_scale, power_initial, power_trace,
836 state_initial, state_trace, interference_send, interference_recv,
837 interference_send_recv, max_outgoing_rate);
840 static void create_routing_table(void)
843 xbt_new0(s_route_KCCFLN05_t, nb_workstation * nb_workstation);
846 static void network_link_free(void *nw_link)
848 free(((network_link_KCCFLN05_t) nw_link)->name);
852 static network_link_KCCFLN05_t network_link_new(char *name,
854 tmgr_trace_t bw_trace,
856 tmgr_trace_t lat_trace,
857 e_surf_network_link_state_t
859 tmgr_trace_t state_trace,
860 e_surf_network_link_sharing_policy_t policy)
862 network_link_KCCFLN05_t nw_link = xbt_new0(s_network_link_KCCFLN05_t, 1);
865 nw_link->resource = (surf_resource_t) surf_workstation_resource;
866 nw_link->type = SURF_WORKSTATION_RESOURCE_LINK;
867 nw_link->name = name;
868 nw_link->bw_current = bw_initial;
871 tmgr_history_add_trace(history, bw_trace, 0.0, 0, nw_link);
872 nw_link->state_current = state_initial;
873 nw_link->lat_current = lat_initial;
876 tmgr_history_add_trace(history, lat_trace, 0.0, 0, nw_link);
878 nw_link->state_event =
879 tmgr_history_add_trace(history, state_trace, 0.0, 0, nw_link);
881 nw_link->constraint =
882 lmm_constraint_new(maxmin_system, nw_link, nw_link->bw_current);
884 if(policy == SURF_NETWORK_LINK_FATPIPE)
885 lmm_constraint_shared(nw_link->constraint);
887 xbt_dict_set(network_link_set, name, nw_link, network_link_free);
892 static void parse_network_link(void)
896 tmgr_trace_t bw_trace;
898 tmgr_trace_t lat_trace;
899 e_surf_network_link_state_t state_initial = SURF_NETWORK_LINK_ON;
900 e_surf_network_link_sharing_policy_t policy_initial = SURF_NETWORK_LINK_SHARED;
901 tmgr_trace_t state_trace;
903 name = xbt_strdup(A_surfxml_network_link_name);
904 surf_parse_get_double(&bw_initial,A_surfxml_network_link_bandwidth);
905 surf_parse_get_trace(&bw_trace, A_surfxml_network_link_bandwidth_file);
906 surf_parse_get_double(&lat_initial,A_surfxml_network_link_latency);
907 surf_parse_get_trace(&lat_trace, A_surfxml_network_link_latency_file);
909 xbt_assert0((A_surfxml_network_link_state==A_surfxml_network_link_state_ON)||
910 (A_surfxml_network_link_state==A_surfxml_network_link_state_OFF),
912 if (A_surfxml_network_link_state==A_surfxml_network_link_state_ON)
913 state_initial = SURF_NETWORK_LINK_ON;
914 else if (A_surfxml_network_link_state==A_surfxml_network_link_state_OFF)
915 state_initial = SURF_NETWORK_LINK_OFF;
917 if (A_surfxml_network_link_sharing_policy==A_surfxml_network_link_sharing_policy_SHARED)
918 policy_initial = SURF_NETWORK_LINK_SHARED;
919 else if (A_surfxml_network_link_sharing_policy==A_surfxml_network_link_sharing_policy_FATPIPE)
920 policy_initial = SURF_NETWORK_LINK_FATPIPE;
922 surf_parse_get_trace(&state_trace,A_surfxml_network_link_state_file);
924 network_link_new(name, bw_initial, bw_trace,
925 lat_initial, lat_trace, state_initial, state_trace,
929 static void route_new(int src_id, int dst_id, network_link_KCCFLN05_t *link_list, int nb_link,
930 double impact_on_src, double impact_on_dst,
931 double impact_on_src_with_other_recv,
932 double impact_on_dst_with_other_send)
934 route_KCCFLN05_t route = &(ROUTE(src_id, dst_id));
936 route->size = nb_link;
937 route->links = link_list = xbt_realloc(link_list, sizeof(network_link_KCCFLN05_t) * nb_link);
938 route->impact_on_src = impact_on_src;
939 route->impact_on_dst = impact_on_src;
940 route->impact_on_src_with_other_recv = impact_on_src_with_other_recv;
941 route->impact_on_dst_with_other_send = impact_on_dst_with_other_send;
945 static int link_list_capacity;
946 static network_link_KCCFLN05_t *link_list = NULL;
947 static int src_id = -1;
948 static int dst_id = -1;
949 static double impact_on_src;
950 static double impact_on_dst;
951 static double impact_on_src_with_other_recv;
952 static double impact_on_dst_with_other_send;
954 static void parse_route_set_endpoints(void)
956 cpu_KCCFLN05_t cpu_tmp = NULL;
958 cpu_tmp = (cpu_KCCFLN05_t) name_service(A_surfxml_route_src);
959 if(cpu_tmp != NULL) {
960 src_id = cpu_tmp->id;
962 xbt_assert1(xbt_dict_get_or_null(router_set, A_surfxml_route_src),
963 "Invalid name '%s': neither a cpu nor a router!",
964 A_surfxml_route_src);
969 cpu_tmp = (cpu_KCCFLN05_t) name_service(A_surfxml_route_dst);
970 if(cpu_tmp != NULL) {
971 dst_id = cpu_tmp->id;
973 xbt_assert1(xbt_dict_get_or_null(router_set, A_surfxml_route_dst),
974 "Invalid name '%s': neither a cpu nor a router!",
975 A_surfxml_route_dst);
980 surf_parse_get_double(&impact_on_src, A_surfxml_route_impact_on_src);
981 surf_parse_get_double(&impact_on_dst, A_surfxml_route_impact_on_dst);
982 surf_parse_get_double(&impact_on_src_with_other_recv,
983 A_surfxml_route_impact_on_src_with_other_recv);
984 surf_parse_get_double(&impact_on_dst_with_other_send,
985 A_surfxml_route_impact_on_dst_with_other_send);
988 link_list_capacity = 1;
989 link_list = xbt_new(network_link_KCCFLN05_t, link_list_capacity);
993 static void parse_route_elem(void)
996 if (nb_link == link_list_capacity) {
997 link_list_capacity *= 2;
998 link_list = xbt_realloc(link_list, (link_list_capacity) * sizeof(network_link_KCCFLN05_t));
1001 link_list[nb_link++] = xbt_dict_get(network_link_set, A_surfxml_route_element_name);
1003 RETHROW1("Link %s not found (dict raised this exception: %s)",A_surfxml_route_element_name);
1007 static void parse_route_set_route(void)
1009 if( src_id != -1 && dst_id != -1 )
1010 route_new(src_id, dst_id, link_list, nb_link, impact_on_src,
1011 impact_on_dst, impact_on_src_with_other_recv,
1012 impact_on_dst_with_other_send);
1015 static void parse_file(const char *file)
1019 /* Figuring out the cpus */
1020 surf_parse_reset_parser();
1021 ETag_surfxml_cpu_fun = parse_cpu;
1022 surf_parse_open(file);
1023 xbt_assert1((!surf_parse()), "Parse error in %s", file);
1026 create_routing_table();
1028 /* Figuring out the router (added after GTNETS) */
1029 surf_parse_reset_parser();
1030 STag_surfxml_router_fun=parse_routers;
1031 surf_parse_open(file);
1032 xbt_assert1((!surf_parse()),"Parse error in %s",file);
1035 /* Figuring out the network links */
1036 surf_parse_reset_parser();
1037 ETag_surfxml_network_link_fun = parse_network_link;
1038 surf_parse_open(file);
1039 xbt_assert1((!surf_parse()), "Parse error in %s", file);
1042 /* Building the routes */
1043 surf_parse_reset_parser();
1044 STag_surfxml_route_fun = parse_route_set_endpoints;
1045 ETag_surfxml_route_element_fun = parse_route_elem;
1046 ETag_surfxml_route_fun = parse_route_set_route;
1047 surf_parse_open(file);
1048 xbt_assert1((!surf_parse()), "Parse error in %s", file);
1051 /* Adding loopback if needed */
1052 for (i = 0; i < nb_workstation; i++)
1053 if(!ROUTE(i,i).size) {
1055 loopback = network_link_new(xbt_strdup("__MSG_loopback__"),
1056 498000000, NULL, 0.000015, NULL,
1057 SURF_NETWORK_LINK_ON, NULL,
1058 SURF_NETWORK_LINK_FATPIPE);
1060 ROUTE(i,i).links = xbt_new0(network_link_KCCFLN05_t, 1);
1061 ROUTE(i,i).links[0] = loopback;
1066 /**************************************/
1067 /********* Module creation ***********/
1068 /**************************************/
1070 static void resource_init_internal(void)
1072 s_surf_action_t action;
1074 surf_workstation_resource = xbt_new0(s_surf_workstation_resource_t, 1);
1076 surf_workstation_resource->common_private =
1077 xbt_new0(s_surf_resource_private_t, 1);
1078 surf_workstation_resource->common_public =
1079 xbt_new0(s_surf_resource_public_t, 1);
1080 surf_workstation_resource->extension_public =
1081 xbt_new0(s_surf_workstation_resource_extension_public_t, 1);
1083 surf_workstation_resource->common_public->states.ready_action_set =
1084 xbt_swag_new(xbt_swag_offset(action, state_hookup));
1085 surf_workstation_resource->common_public->states.running_action_set =
1086 xbt_swag_new(xbt_swag_offset(action, state_hookup));
1087 surf_workstation_resource->common_public->states.failed_action_set =
1088 xbt_swag_new(xbt_swag_offset(action, state_hookup));
1089 surf_workstation_resource->common_public->states.done_action_set =
1090 xbt_swag_new(xbt_swag_offset(action, state_hookup));
1092 surf_workstation_resource->common_public->name_service = name_service;
1093 surf_workstation_resource->common_public->get_resource_name = get_resource_name;
1094 surf_workstation_resource->common_public->action_get_state = surf_action_get_state;
1095 surf_workstation_resource->common_public->action_get_start_time =
1096 surf_action_get_start_time;
1097 surf_workstation_resource->common_public->action_get_finish_time =
1098 surf_action_get_finish_time;
1099 surf_workstation_resource->common_public->action_use = action_use;
1100 surf_workstation_resource->common_public->action_free = action_free;
1101 surf_workstation_resource->common_public->action_cancel = action_cancel;
1102 surf_workstation_resource->common_public->action_recycle = action_recycle;
1103 surf_workstation_resource->common_public->action_change_state = surf_action_change_state;
1104 surf_workstation_resource->common_public->action_set_data = surf_action_set_data;
1105 surf_workstation_resource->common_public->suspend = action_suspend;
1106 surf_workstation_resource->common_public->resume = action_resume;
1107 surf_workstation_resource->common_public->is_suspended = action_is_suspended;
1108 surf_workstation_resource->common_public->set_max_duration = action_set_max_duration;
1109 surf_workstation_resource->common_public->set_priority = action_set_priority;
1110 surf_workstation_resource->common_public->name = "Workstation KCCFLN05";
1112 surf_workstation_resource->common_private->resource_used = resource_used;
1113 surf_workstation_resource->common_private->share_resources = share_resources;
1114 surf_workstation_resource->common_private->update_actions_state = update_actions_state;
1115 surf_workstation_resource->common_private->update_resource_state = update_resource_state;
1116 surf_workstation_resource->common_private->finalize = finalize;
1118 surf_workstation_resource->extension_public->execute = execute;
1119 surf_workstation_resource->extension_public->sleep = action_sleep;
1120 surf_workstation_resource->extension_public->get_state = resource_get_state;
1121 surf_workstation_resource->extension_public->get_speed = get_speed;
1122 surf_workstation_resource->extension_public->get_available_speed = get_available_speed;
1123 surf_workstation_resource->extension_public->communicate = communicate;
1124 surf_workstation_resource->extension_public->execute_parallel_task = execute_parallel_task;
1125 surf_workstation_resource->extension_public->get_route = get_route;
1126 surf_workstation_resource->extension_public->get_route_size = get_route_size;
1127 surf_workstation_resource->extension_public->get_link_name = get_link_name;
1128 surf_workstation_resource->extension_public->get_link_bandwidth = get_link_bandwidth;
1129 surf_workstation_resource->extension_public->get_link_latency = get_link_latency;
1131 workstation_set = xbt_dict_new();
1132 router_set = xbt_dict_new();
1133 network_link_set = xbt_dict_new();
1135 xbt_assert0(maxmin_system, "surf_init has to be called first!");
1138 /**************************************/
1139 /*************** Generic **************/
1140 /**************************************/
1141 void surf_workstation_resource_init_KCCFLN05(const char *filename)
1143 xbt_assert0(!surf_cpu_resource, "CPU resource type already defined");
1144 xbt_assert0(!surf_network_resource, "network resource type already defined");
1145 resource_init_internal();
1146 parse_file(filename);
1148 xbt_dynar_push(resource_list, &surf_workstation_resource);