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(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 <= 0) &&
306 (lmm_get_variable_weight(action->variable)>0)) {
307 action->generic_action.finish = surf_get_clock();
308 surf_action_change_state((surf_action_t) action, SURF_ACTION_DONE);
309 } else if ((action->generic_action.max_duration != NO_MAX_DURATION) &&
310 (action->generic_action.max_duration <= 0)) {
311 action->generic_action.finish = surf_get_clock();
312 surf_action_change_state((surf_action_t) action, SURF_ACTION_DONE);
314 /* Need to check that none of the resource has failed */
315 lmm_constraint_t cnst = NULL;
317 void *constraint_id = NULL;
320 lmm_get_cnst_from_var(maxmin_system, action->variable,
322 constraint_id = lmm_constraint_id(cnst);
324 /* if(((network_link_KCCFLN05_t)constraint_id)->type== */
325 /* SURF_WORKSTATION_RESOURCE_LINK) { */
326 /* DEBUG2("Checking for link %s (%p)", */
327 /* ((network_link_KCCFLN05_t)constraint_id)->name, */
328 /* ((network_link_KCCFLN05_t)constraint_id)); */
330 /* if(((cpu_KCCFLN05_t)constraint_id)->type== */
331 /* SURF_WORKSTATION_RESOURCE_CPU) { */
332 /* DEBUG3("Checking for cpu %s (%p) : %s", */
333 /* ((cpu_KCCFLN05_t)constraint_id)->name, */
334 /* ((cpu_KCCFLN05_t)constraint_id), */
335 /* ((cpu_KCCFLN05_t)constraint_id)->state_current==SURF_CPU_OFF?"Off":"On"); */
338 if(((((network_link_KCCFLN05_t)constraint_id)->type==
339 SURF_WORKSTATION_RESOURCE_LINK) &&
340 (((network_link_KCCFLN05_t)constraint_id)->state_current==
341 SURF_NETWORK_LINK_OFF)) ||
342 ((((cpu_KCCFLN05_t)constraint_id)->type==
343 SURF_WORKSTATION_RESOURCE_CPU) &&
344 (((cpu_KCCFLN05_t)constraint_id)->state_current==
346 DEBUG1("Action (%p) Failed!!",action);
347 action->generic_action.finish = surf_get_clock();
348 surf_action_change_state((surf_action_t) action, SURF_ACTION_FAILED);
357 static void update_resource_state(void *id,
358 tmgr_trace_event_t event_type,
361 cpu_KCCFLN05_t cpu = id;
362 network_link_KCCFLN05_t nw_link = id ;
364 if(nw_link->type == SURF_WORKSTATION_RESOURCE_LINK) {
365 DEBUG2("Updating link %s (%p)",nw_link->name,nw_link);
366 if (event_type == nw_link->bw_event) {
367 nw_link->bw_current = value;
368 lmm_update_constraint_bound(maxmin_system, nw_link->constraint,
369 nw_link->bw_current);
370 } else if (event_type == nw_link->lat_event) {
371 double delta = value - nw_link->lat_current;
372 lmm_variable_t var = NULL;
373 surf_action_workstation_KCCFLN05_t action = NULL;
375 nw_link->lat_current = value;
376 while (lmm_get_var_from_cnst(maxmin_system, nw_link->constraint, &var)) {
377 action = lmm_variable_id(var);
378 action->lat_current += delta;
380 lmm_update_variable_bound(maxmin_system, action->variable,
381 SG_TCP_CTE_GAMMA / (2.0 * action->lat_current));
383 lmm_update_variable_bound(maxmin_system, action->variable,
384 min(action->rate,SG_TCP_CTE_GAMMA / (2.0 * action->lat_current)));
385 if(action->suspended==0)
386 lmm_update_variable_weight(maxmin_system, action->variable,
387 action->lat_current);
388 lmm_update_variable_latency(maxmin_system, action->variable, delta);
392 } else if (event_type == nw_link->state_event) {
394 nw_link->state_current = SURF_NETWORK_LINK_ON;
396 nw_link->state_current = SURF_NETWORK_LINK_OFF;
398 CRITICAL0("Unknown event ! \n");
402 } else if(cpu->type == SURF_WORKSTATION_RESOURCE_CPU) {
403 DEBUG3("Updating cpu %s (%p) with value %g",cpu->name,cpu,value);
404 if (event_type == cpu->power_event) {
405 cpu->power_current = value;
406 __update_cpu_usage(cpu);
407 } else if (event_type == cpu->state_event) {
409 cpu->state_current = SURF_CPU_ON;
411 cpu->state_current = SURF_CPU_OFF;
413 CRITICAL0("Unknown event ! \n");
423 static void finalize(void)
427 xbt_dict_free(&network_link_set);
428 xbt_dict_free(&workstation_set);
429 xbt_dict_free(&router_set);
430 if (parallel_task_network_link_set != NULL) {
431 xbt_dict_free(¶llel_task_network_link_set);
433 xbt_swag_free(surf_workstation_resource->common_public->states.
435 xbt_swag_free(surf_workstation_resource->common_public->states.
437 xbt_swag_free(surf_workstation_resource->common_public->states.
439 xbt_swag_free(surf_workstation_resource->common_public->states.
442 free(surf_workstation_resource->common_public);
443 free(surf_workstation_resource->common_private);
444 free(surf_workstation_resource->extension_public);
446 free(surf_workstation_resource);
447 surf_workstation_resource = NULL;
449 for (i = 0; i < nb_workstation; i++)
450 for (j = 0; j < nb_workstation; j++)
451 free(ROUTE(i, j).links);
453 routing_table = NULL;
457 lmm_system_free(maxmin_system);
458 maxmin_system = NULL;
462 /**************************************/
463 /******* Resource Private **********/
464 /**************************************/
466 static surf_action_t execute(void *cpu, double size)
468 surf_action_workstation_KCCFLN05_t action = NULL;
469 cpu_KCCFLN05_t CPU = cpu;
471 XBT_IN2("(%s,%g)",CPU->name,size);
472 action = xbt_new0(s_surf_action_workstation_KCCFLN05_t, 1);
474 action->generic_action.using = 1;
475 action->generic_action.cost = size;
476 action->generic_action.remains = size;
477 action->generic_action.priority = 1.0;
478 action->generic_action.max_duration = NO_MAX_DURATION;
479 action->generic_action.start = surf_get_clock();
480 action->generic_action.finish = -1.0;
481 action->generic_action.resource_type =
482 (surf_resource_t) surf_workstation_resource;
483 action->suspended = 0;
485 if (CPU->state_current == SURF_CPU_ON)
486 action->generic_action.state_set =
487 surf_workstation_resource->common_public->states.running_action_set;
489 action->generic_action.state_set =
490 surf_workstation_resource->common_public->states.failed_action_set;
491 xbt_swag_insert(action, action->generic_action.state_set);
493 action->variable = lmm_variable_new(maxmin_system, action,
494 action->generic_action.priority, -1.0, 1);
495 lmm_expand(maxmin_system, CPU->constraint, action->variable,
498 return (surf_action_t) action;
501 static surf_action_t action_sleep(void *cpu, double duration)
503 surf_action_workstation_KCCFLN05_t action = NULL;
505 XBT_IN2("(%s,%g)",((cpu_KCCFLN05_t)cpu)->name,duration);
507 action = (surf_action_workstation_KCCFLN05_t) execute(cpu, 1.0);
508 action->generic_action.max_duration = duration;
509 action->suspended = 2;
510 lmm_update_variable_weight(maxmin_system, action->variable, 0.0);
513 return (surf_action_t) action;
516 static e_surf_cpu_state_t resource_get_state(void *cpu)
518 return ((cpu_KCCFLN05_t) cpu)->state_current;
521 static double get_speed(void *cpu, double load)
523 return load*(((cpu_KCCFLN05_t) cpu)->power_scale);
526 static double get_available_speed(void *cpu)
528 return ((cpu_KCCFLN05_t) cpu)->power_current;
532 static surf_action_t communicate(void *src, void *dst, double size, double rate)
534 surf_action_workstation_KCCFLN05_t action = NULL;
535 cpu_KCCFLN05_t card_src = src;
536 cpu_KCCFLN05_t card_dst = dst;
537 route_KCCFLN05_t route = &(ROUTE(card_src->id, card_dst->id));
538 int route_size = route->size;
541 XBT_IN4("(%s,%s,%g,%g)",card_src->name,card_dst->name,size,rate);
542 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);
544 action = xbt_new0(s_surf_action_workstation_KCCFLN05_t, 1);
546 action->generic_action.using = 1;
547 action->generic_action.cost = size;
548 action->generic_action.remains = size;
549 action->generic_action.max_duration = NO_MAX_DURATION;
550 action->generic_action.start = surf_get_clock();
551 action->generic_action.finish = -1.0;
554 action->generic_action.resource_type =
555 (surf_resource_t) surf_workstation_resource;
556 action->suspended = 0; /* Should be useless because of the
557 calloc but it seems to help valgrind... */
558 action->generic_action.state_set =
559 surf_workstation_resource->common_public->states.running_action_set;
561 xbt_dynar_push(card_src->outgoing_communications, &action);
562 xbt_dynar_push(card_dst->incomming_communications, &action);
564 xbt_swag_insert(action, action->generic_action.state_set);
567 action->latency = 0.0;
568 for (i = 0; i < route_size; i++)
569 action->latency += route->links[i]->lat_current;
570 action->lat_current = action->latency;
572 if(action->latency>0)
573 action->variable = lmm_variable_new(maxmin_system, action, 0.0, -1.0,
574 route_size+4); /* +1 for the src bus
577 +1 for the dst cpu */
579 action->variable = lmm_variable_new(maxmin_system, action, 1.0, -1.0,
583 if(action->lat_current>0)
584 lmm_update_variable_bound(maxmin_system, action->variable,
585 SG_TCP_CTE_GAMMA / (2.0 * action->lat_current));
587 lmm_update_variable_bound(maxmin_system, action->variable, -1.0);
589 if(action->lat_current>0)
590 lmm_update_variable_bound(maxmin_system, action->variable,
591 min(action->rate,SG_TCP_CTE_GAMMA / (2.0 * action->lat_current)));
593 lmm_update_variable_bound(maxmin_system, action->variable, action->rate);
596 lmm_update_variable_latency(maxmin_system, action->variable, action->latency);
598 for (i = 0; i < route_size; i++)
599 lmm_expand(maxmin_system, route->links[i]->constraint, action->variable, 1.0);
601 lmm_expand(maxmin_system, card_src->bus, action->variable, 1.0);
603 lmm_expand(maxmin_system, card_dst->bus, action->variable, 1.0);
604 lmm_expand(maxmin_system, card_src->constraint, action->variable, 0.0);
605 lmm_expand(maxmin_system, card_dst->constraint, action->variable, 0.0);
608 return (surf_action_t) action;
611 static surf_action_t execute_parallel_task(int workstation_nb,
612 void **workstation_list,
613 double *computation_amount,
614 double *communication_amount,
618 surf_action_workstation_KCCFLN05_t action = NULL;
623 if (parallel_task_network_link_set == NULL) {
624 parallel_task_network_link_set = xbt_dict_new_ext(workstation_nb * workstation_nb * 10);
627 /* Compute the number of affected resources... */
628 for(i=0; i< workstation_nb; i++) {
629 for(j=0; j< workstation_nb; j++) {
630 cpu_KCCFLN05_t card_src = workstation_list[i];
631 cpu_KCCFLN05_t card_dst = workstation_list[j];
632 int route_size = ROUTE(card_src->id, card_dst->id).size;
633 network_link_KCCFLN05_t *route = ROUTE(card_src->id, card_dst->id).links;
635 if(communication_amount[i*workstation_nb+j]>0)
636 for(k=0; k< route_size; k++) {
637 xbt_dict_set(parallel_task_network_link_set, route[k]->name, route[k], NULL);
641 nb_link = xbt_dict_length(parallel_task_network_link_set);
642 xbt_dict_reset(parallel_task_network_link_set);
645 for (i = 0; i<workstation_nb; i++)
646 if(computation_amount[i]>0) nb_host++;
649 if(nb_link + nb_host == 0) /* was workstation_nb... */
652 action = xbt_new0(s_surf_action_workstation_KCCFLN05_t, 1);
653 DEBUG3("Creating a parallel task (%p) with %d cpus and %d links.",
654 action, nb_host, nb_link);
655 action->generic_action.using = 1;
656 action->generic_action.cost = amount;
657 action->generic_action.remains = amount;
658 action->generic_action.max_duration = NO_MAX_DURATION;
659 action->generic_action.start = -1.0;
660 action->generic_action.finish = -1.0;
661 action->generic_action.resource_type =
662 (surf_resource_t) surf_workstation_resource;
663 action->suspended = 0; /* Should be useless because of the
664 calloc but it seems to help valgrind... */
665 action->generic_action.state_set =
666 surf_workstation_resource->common_public->states.running_action_set;
668 xbt_swag_insert(action, action->generic_action.state_set);
672 action->variable = lmm_variable_new(maxmin_system, action, 1.0, -1.0,
675 action->variable = lmm_variable_new(maxmin_system, action, 1.0, action->rate,
678 for (i = 0; i<workstation_nb; i++)
679 if(computation_amount[i]>0)
680 lmm_expand(maxmin_system, ((cpu_KCCFLN05_t) workstation_list[i])->constraint,
681 action->variable, computation_amount[i]);
683 for (i=0; i<workstation_nb; i++) {
684 for(j=0; j< workstation_nb; j++) {
685 cpu_KCCFLN05_t card_src = workstation_list[i];
686 cpu_KCCFLN05_t card_dst = workstation_list[j];
687 int route_size = ROUTE(card_src->id, card_dst->id).size;
688 network_link_KCCFLN05_t *route = ROUTE(card_src->id, card_dst->id).links;
690 for(k=0; k< route_size; k++) {
691 if(communication_amount[i*workstation_nb+j]>0) {
692 lmm_expand_add(maxmin_system, route[k]->constraint,
693 action->variable, communication_amount[i*workstation_nb+j]);
699 return (surf_action_t) action;
702 /* returns an array of network_link_KCCFLN05_t */
703 static const void** get_route(void *src, void *dst) {
704 cpu_KCCFLN05_t card_src = src;
705 cpu_KCCFLN05_t card_dst = dst;
706 route_KCCFLN05_t route = &(ROUTE(card_src->id, card_dst->id));
708 return (const void**) route->links;
711 static int get_route_size(void *src, void *dst) {
712 cpu_KCCFLN05_t card_src = src;
713 cpu_KCCFLN05_t card_dst = dst;
714 route_KCCFLN05_t route = &(ROUTE(card_src->id, card_dst->id));
718 static const char *get_link_name(const void *link) {
719 return ((network_link_KCCFLN05_t) link)->name;
722 static double get_link_bandwidth(const void *link) {
723 return ((network_link_KCCFLN05_t) link)->bw_current;
726 static double get_link_latency(const void *link) {
727 return ((network_link_KCCFLN05_t) link)->lat_current;
730 /**************************************/
731 /*** Resource Creation & Destruction **/
732 /**************************************/
735 static void router_free(void *router)
737 free( ((router_KCCFLN05_t) router)->name );
740 static void router_new(const char *name)
742 static unsigned int nb_routers = 0;
744 INFO1("Creating a router %s", name);
746 router_KCCFLN05_t router;
747 router = xbt_new0(s_router_KCCFLN05_t, 1);
749 router->name = xbt_strdup(name);
750 router->id = nb_routers++;
751 xbt_dict_set(router_set, name, router, router_free);
754 static void parse_routers(void)
756 //add a dumb router just to be GTNETS compatible
757 router_new(A_surfxml_router_name);
760 static void cpu_free(void *cpu)
762 free(((cpu_KCCFLN05_t) cpu)->name);
763 xbt_dynar_free(&(((cpu_KCCFLN05_t) cpu)->incomming_communications));
764 xbt_dynar_free(&(((cpu_KCCFLN05_t) cpu)->outgoing_communications));
768 static cpu_KCCFLN05_t cpu_new(const char *name, double power_scale,
769 double power_initial,
770 tmgr_trace_t power_trace,
771 e_surf_cpu_state_t state_initial,
772 tmgr_trace_t state_trace,
773 double interference_send,
774 double interference_recv,
775 double interference_send_recv,
776 double max_outgoing_rate)
778 cpu_KCCFLN05_t cpu = xbt_new0(s_cpu_KCCFLN05_t, 1);
780 cpu->resource = (surf_resource_t) surf_workstation_resource;
781 cpu->type = SURF_WORKSTATION_RESOURCE_CPU;
782 cpu->name = xbt_strdup(name);
783 cpu->id = nb_workstation++;
785 cpu->power_scale = power_scale;
786 xbt_assert0(cpu->power_scale > 0, "Power has to be >0");
788 cpu->power_current = power_initial;
791 tmgr_history_add_trace(history, power_trace, 0.0, 0, cpu);
793 cpu->state_current = state_initial;
796 tmgr_history_add_trace(history, state_trace, 0.0, 0, cpu);
798 cpu->interference_send = interference_send;
799 cpu->interference_recv = interference_recv;
800 cpu->interference_send_recv = interference_send_recv;
803 lmm_constraint_new(maxmin_system, cpu,
804 cpu->power_current * cpu->power_scale);
805 if (max_outgoing_rate > 0)
806 cpu->bus = lmm_constraint_new(maxmin_system, cpu, max_outgoing_rate);
808 cpu->incomming_communications =
809 xbt_dynar_new(sizeof(surf_action_workstation_KCCFLN05_t), NULL);
810 cpu->outgoing_communications =
811 xbt_dynar_new(sizeof(surf_action_workstation_KCCFLN05_t), NULL);
813 xbt_dict_set(workstation_set, name, cpu, cpu_free);
818 static void parse_cpu(void)
820 double power_scale = 0.0;
821 double power_initial = 0.0;
822 tmgr_trace_t power_trace = NULL;
823 e_surf_cpu_state_t state_initial = SURF_CPU_OFF;
824 tmgr_trace_t state_trace = NULL;
825 double interference_send = 0.0;
826 double interference_recv = 0.0;
827 double interference_send_recv = 0.0;
828 double max_outgoing_rate = -1.0;
830 surf_parse_get_double(&power_scale, A_surfxml_cpu_power);
831 surf_parse_get_double(&power_initial, A_surfxml_cpu_availability);
832 surf_parse_get_trace(&power_trace, A_surfxml_cpu_availability_file);
834 xbt_assert0((A_surfxml_cpu_state == A_surfxml_cpu_state_ON) ||
835 (A_surfxml_cpu_state == A_surfxml_cpu_state_OFF),
837 if (A_surfxml_cpu_state == A_surfxml_cpu_state_ON)
838 state_initial = SURF_CPU_ON;
839 if (A_surfxml_cpu_state == A_surfxml_cpu_state_OFF)
840 state_initial = SURF_CPU_OFF;
841 surf_parse_get_trace(&state_trace, A_surfxml_cpu_state_file);
843 surf_parse_get_double(&interference_send,
844 A_surfxml_cpu_interference_send);
845 surf_parse_get_double(&interference_recv,
846 A_surfxml_cpu_interference_recv);
847 surf_parse_get_double(&interference_send_recv,
848 A_surfxml_cpu_interference_send_recv);
849 surf_parse_get_double(&max_outgoing_rate,
850 A_surfxml_cpu_max_outgoing_rate);
852 cpu_new(A_surfxml_cpu_name, power_scale, power_initial, power_trace,
853 state_initial, state_trace, interference_send, interference_recv,
854 interference_send_recv, max_outgoing_rate);
857 static void create_routing_table(void)
860 xbt_new0(s_route_KCCFLN05_t, nb_workstation * nb_workstation);
863 static void network_link_free(void *nw_link)
865 free(((network_link_KCCFLN05_t) nw_link)->name);
869 static network_link_KCCFLN05_t network_link_new(char *name,
871 tmgr_trace_t bw_trace,
873 tmgr_trace_t lat_trace,
874 e_surf_network_link_state_t
876 tmgr_trace_t state_trace,
877 e_surf_network_link_sharing_policy_t policy)
879 network_link_KCCFLN05_t nw_link = xbt_new0(s_network_link_KCCFLN05_t, 1);
882 nw_link->resource = (surf_resource_t) surf_workstation_resource;
883 nw_link->type = SURF_WORKSTATION_RESOURCE_LINK;
884 nw_link->name = name;
885 nw_link->bw_current = bw_initial;
888 tmgr_history_add_trace(history, bw_trace, 0.0, 0, nw_link);
889 nw_link->state_current = state_initial;
890 nw_link->lat_current = lat_initial;
893 tmgr_history_add_trace(history, lat_trace, 0.0, 0, nw_link);
895 nw_link->state_event =
896 tmgr_history_add_trace(history, state_trace, 0.0, 0, nw_link);
898 nw_link->constraint =
899 lmm_constraint_new(maxmin_system, nw_link, nw_link->bw_current);
901 if(policy == SURF_NETWORK_LINK_FATPIPE)
902 lmm_constraint_shared(nw_link->constraint);
904 xbt_dict_set(network_link_set, name, nw_link, network_link_free);
909 static void parse_network_link(void)
913 tmgr_trace_t bw_trace;
915 tmgr_trace_t lat_trace;
916 e_surf_network_link_state_t state_initial = SURF_NETWORK_LINK_ON;
917 e_surf_network_link_sharing_policy_t policy_initial = SURF_NETWORK_LINK_SHARED;
918 tmgr_trace_t state_trace;
920 name = xbt_strdup(A_surfxml_network_link_name);
921 surf_parse_get_double(&bw_initial,A_surfxml_network_link_bandwidth);
922 surf_parse_get_trace(&bw_trace, A_surfxml_network_link_bandwidth_file);
923 surf_parse_get_double(&lat_initial,A_surfxml_network_link_latency);
924 surf_parse_get_trace(&lat_trace, A_surfxml_network_link_latency_file);
926 xbt_assert0((A_surfxml_network_link_state==A_surfxml_network_link_state_ON)||
927 (A_surfxml_network_link_state==A_surfxml_network_link_state_OFF),
929 if (A_surfxml_network_link_state==A_surfxml_network_link_state_ON)
930 state_initial = SURF_NETWORK_LINK_ON;
931 else if (A_surfxml_network_link_state==A_surfxml_network_link_state_OFF)
932 state_initial = SURF_NETWORK_LINK_OFF;
934 if (A_surfxml_network_link_sharing_policy==A_surfxml_network_link_sharing_policy_SHARED)
935 policy_initial = SURF_NETWORK_LINK_SHARED;
936 else if (A_surfxml_network_link_sharing_policy==A_surfxml_network_link_sharing_policy_FATPIPE)
937 policy_initial = SURF_NETWORK_LINK_FATPIPE;
939 surf_parse_get_trace(&state_trace,A_surfxml_network_link_state_file);
941 network_link_new(name, bw_initial, bw_trace,
942 lat_initial, lat_trace, state_initial, state_trace,
946 static void route_new(int src_id, int dst_id, network_link_KCCFLN05_t *link_list, int nb_link,
947 double impact_on_src, double impact_on_dst,
948 double impact_on_src_with_other_recv,
949 double impact_on_dst_with_other_send)
951 route_KCCFLN05_t route = &(ROUTE(src_id, dst_id));
953 route->size = nb_link;
954 route->links = link_list = xbt_realloc(link_list, sizeof(network_link_KCCFLN05_t) * nb_link);
955 route->impact_on_src = impact_on_src;
956 route->impact_on_dst = impact_on_src;
957 route->impact_on_src_with_other_recv = impact_on_src_with_other_recv;
958 route->impact_on_dst_with_other_send = impact_on_dst_with_other_send;
962 static int link_list_capacity;
963 static network_link_KCCFLN05_t *link_list = NULL;
964 static int src_id = -1;
965 static int dst_id = -1;
966 static double impact_on_src;
967 static double impact_on_dst;
968 static double impact_on_src_with_other_recv;
969 static double impact_on_dst_with_other_send;
971 static void parse_route_set_endpoints(void)
973 cpu_KCCFLN05_t cpu_tmp = NULL;
975 cpu_tmp = (cpu_KCCFLN05_t) name_service(A_surfxml_route_src);
976 if(cpu_tmp != NULL) {
977 src_id = cpu_tmp->id;
979 xbt_assert1(xbt_dict_get_or_null(router_set, A_surfxml_route_src),
980 "Invalid name '%s': neither a cpu nor a router!",
981 A_surfxml_route_src);
986 cpu_tmp = (cpu_KCCFLN05_t) name_service(A_surfxml_route_dst);
987 if(cpu_tmp != NULL) {
988 dst_id = cpu_tmp->id;
990 xbt_assert1(xbt_dict_get_or_null(router_set, A_surfxml_route_dst),
991 "Invalid name '%s': neither a cpu nor a router!",
992 A_surfxml_route_dst);
997 surf_parse_get_double(&impact_on_src, A_surfxml_route_impact_on_src);
998 surf_parse_get_double(&impact_on_dst, A_surfxml_route_impact_on_dst);
999 surf_parse_get_double(&impact_on_src_with_other_recv,
1000 A_surfxml_route_impact_on_src_with_other_recv);
1001 surf_parse_get_double(&impact_on_dst_with_other_send,
1002 A_surfxml_route_impact_on_dst_with_other_send);
1005 link_list_capacity = 1;
1006 link_list = xbt_new(network_link_KCCFLN05_t, link_list_capacity);
1010 static void parse_route_elem(void)
1013 if (nb_link == link_list_capacity) {
1014 link_list_capacity *= 2;
1015 link_list = xbt_realloc(link_list, (link_list_capacity) * sizeof(network_link_KCCFLN05_t));
1018 link_list[nb_link++] = xbt_dict_get(network_link_set, A_surfxml_route_element_name);
1020 RETHROW1("Link %s not found (dict raised this exception: %s)",A_surfxml_route_element_name);
1024 static void parse_route_set_route(void)
1026 if( src_id != -1 && dst_id != -1 )
1027 route_new(src_id, dst_id, link_list, nb_link, impact_on_src,
1028 impact_on_dst, impact_on_src_with_other_recv,
1029 impact_on_dst_with_other_send);
1032 static void parse_file(const char *file)
1036 /* Figuring out the cpus */
1037 surf_parse_reset_parser();
1038 ETag_surfxml_cpu_fun = parse_cpu;
1039 surf_parse_open(file);
1040 xbt_assert1((!surf_parse()), "Parse error in %s", file);
1043 create_routing_table();
1045 /* Figuring out the router (added after GTNETS) */
1046 surf_parse_reset_parser();
1047 STag_surfxml_router_fun=parse_routers;
1048 surf_parse_open(file);
1049 xbt_assert1((!surf_parse()),"Parse error in %s",file);
1052 /* Figuring out the network links */
1053 surf_parse_reset_parser();
1054 ETag_surfxml_network_link_fun = parse_network_link;
1055 surf_parse_open(file);
1056 xbt_assert1((!surf_parse()), "Parse error in %s", file);
1059 /* Building the routes */
1060 surf_parse_reset_parser();
1061 STag_surfxml_route_fun = parse_route_set_endpoints;
1062 ETag_surfxml_route_element_fun = parse_route_elem;
1063 ETag_surfxml_route_fun = parse_route_set_route;
1064 surf_parse_open(file);
1065 xbt_assert1((!surf_parse()), "Parse error in %s", file);
1068 /* Adding loopback if needed */
1069 for (i = 0; i < nb_workstation; i++)
1070 if(!ROUTE(i,i).size) {
1072 loopback = network_link_new(xbt_strdup("__MSG_loopback__"),
1073 498000000, NULL, 0.000015, NULL,
1074 SURF_NETWORK_LINK_ON, NULL,
1075 SURF_NETWORK_LINK_FATPIPE);
1077 ROUTE(i,i).links = xbt_new0(network_link_KCCFLN05_t, 1);
1078 ROUTE(i,i).links[0] = loopback;
1083 /**************************************/
1084 /********* Module creation ***********/
1085 /**************************************/
1087 static void resource_init_internal(void)
1089 s_surf_action_t action;
1091 surf_workstation_resource = xbt_new0(s_surf_workstation_resource_t, 1);
1093 surf_workstation_resource->common_private =
1094 xbt_new0(s_surf_resource_private_t, 1);
1095 surf_workstation_resource->common_public =
1096 xbt_new0(s_surf_resource_public_t, 1);
1097 surf_workstation_resource->extension_public =
1098 xbt_new0(s_surf_workstation_resource_extension_public_t, 1);
1100 surf_workstation_resource->common_public->states.ready_action_set =
1101 xbt_swag_new(xbt_swag_offset(action, state_hookup));
1102 surf_workstation_resource->common_public->states.running_action_set =
1103 xbt_swag_new(xbt_swag_offset(action, state_hookup));
1104 surf_workstation_resource->common_public->states.failed_action_set =
1105 xbt_swag_new(xbt_swag_offset(action, state_hookup));
1106 surf_workstation_resource->common_public->states.done_action_set =
1107 xbt_swag_new(xbt_swag_offset(action, state_hookup));
1109 surf_workstation_resource->common_public->name_service = name_service;
1110 surf_workstation_resource->common_public->get_resource_name = get_resource_name;
1111 surf_workstation_resource->common_public->action_get_state = surf_action_get_state;
1112 surf_workstation_resource->common_public->action_get_start_time =
1113 surf_action_get_start_time;
1114 surf_workstation_resource->common_public->action_get_finish_time =
1115 surf_action_get_finish_time;
1116 surf_workstation_resource->common_public->action_use = action_use;
1117 surf_workstation_resource->common_public->action_free = action_free;
1118 surf_workstation_resource->common_public->action_cancel = action_cancel;
1119 surf_workstation_resource->common_public->action_recycle = action_recycle;
1120 surf_workstation_resource->common_public->action_change_state = surf_action_change_state;
1121 surf_workstation_resource->common_public->action_set_data = surf_action_set_data;
1122 surf_workstation_resource->common_public->suspend = action_suspend;
1123 surf_workstation_resource->common_public->resume = action_resume;
1124 surf_workstation_resource->common_public->is_suspended = action_is_suspended;
1125 surf_workstation_resource->common_public->set_max_duration = action_set_max_duration;
1126 surf_workstation_resource->common_public->set_priority = action_set_priority;
1127 surf_workstation_resource->common_public->name = "Workstation KCCFLN05";
1129 surf_workstation_resource->common_private->resource_used = resource_used;
1130 surf_workstation_resource->common_private->share_resources = share_resources;
1131 surf_workstation_resource->common_private->update_actions_state = update_actions_state;
1132 surf_workstation_resource->common_private->update_resource_state = update_resource_state;
1133 surf_workstation_resource->common_private->finalize = finalize;
1135 surf_workstation_resource->extension_public->execute = execute;
1136 surf_workstation_resource->extension_public->sleep = action_sleep;
1137 surf_workstation_resource->extension_public->get_state = resource_get_state;
1138 surf_workstation_resource->extension_public->get_speed = get_speed;
1139 surf_workstation_resource->extension_public->get_available_speed = get_available_speed;
1140 surf_workstation_resource->extension_public->communicate = communicate;
1141 surf_workstation_resource->extension_public->execute_parallel_task = execute_parallel_task;
1142 surf_workstation_resource->extension_public->get_route = get_route;
1143 surf_workstation_resource->extension_public->get_route_size = get_route_size;
1144 surf_workstation_resource->extension_public->get_link_name = get_link_name;
1145 surf_workstation_resource->extension_public->get_link_bandwidth = get_link_bandwidth;
1146 surf_workstation_resource->extension_public->get_link_latency = get_link_latency;
1148 workstation_set = xbt_dict_new();
1149 router_set = xbt_dict_new();
1150 network_link_set = xbt_dict_new();
1152 xbt_assert0(maxmin_system, "surf_init has to be called first!");
1155 /**************************************/
1156 /*************** Generic **************/
1157 /**************************************/
1158 void surf_workstation_resource_init_KCCFLN05(const char *filename)
1160 xbt_assert0(!surf_cpu_resource, "CPU resource type already defined");
1161 xbt_assert0(!surf_network_resource, "network resource type already defined");
1162 resource_init_internal();
1163 parse_file(filename);
1165 xbt_dynar_push(resource_list, &surf_workstation_resource);