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;
21 /*xbt_dict_t network_link_set = NULL;*/
23 /* convenient function */
24 static void __update_cpu_usage(cpu_KCCFLN05_t cpu)
27 surf_action_workstation_KCCFLN05_t action = NULL;
28 if ((!xbt_dynar_length(cpu->incomming_communications)) &&
29 (!xbt_dynar_length(cpu->outgoing_communications))) {
30 /* No communications */
31 lmm_update_constraint_bound(maxmin_system, cpu->constraint,
32 cpu->power_current * cpu->power_scale);
33 } else if ((!xbt_dynar_length(cpu->incomming_communications))
34 && (xbt_dynar_length(cpu->outgoing_communications))) {
36 lmm_update_constraint_bound(maxmin_system, cpu->constraint,
37 cpu->power_current * cpu->power_scale *
38 cpu->interference_send);
39 xbt_dynar_foreach(cpu->outgoing_communications, cpt, action)
40 lmm_elem_set_value(maxmin_system,cpu->constraint,action->variable,
41 cpu->power_current * cpu->power_scale *
42 ROUTE(action->src->id, action->dst->id).impact_on_src
44 } else if ((xbt_dynar_length(cpu->incomming_communications)) &&
45 (!xbt_dynar_length(cpu->outgoing_communications))) {
47 lmm_update_constraint_bound(maxmin_system, cpu->constraint,
48 cpu->power_current * cpu->power_scale *
49 cpu->interference_recv);
50 xbt_dynar_foreach(cpu->incomming_communications, cpt, action)
51 lmm_elem_set_value(maxmin_system,cpu->constraint,action->variable,
52 cpu->power_current * cpu->power_scale *
53 ROUTE(action->src->id, action->dst->id).impact_on_dst
56 /* Emission & Reception */
57 lmm_update_constraint_bound(maxmin_system, cpu->constraint,
58 cpu->power_current * cpu->power_scale *
59 cpu->interference_send_recv);
60 xbt_dynar_foreach(cpu->outgoing_communications, cpt, action)
61 lmm_elem_set_value(maxmin_system,cpu->constraint,action->variable,
62 cpu->power_current * cpu->power_scale *
63 ROUTE(action->src->id, action->dst->id).impact_on_src_with_other_recv
65 xbt_dynar_foreach(cpu->incomming_communications, cpt, action)
66 lmm_elem_set_value(maxmin_system,cpu->constraint,action->variable,
67 cpu->power_current * cpu->power_scale *
68 ROUTE(action->src->id, action->dst->id).impact_on_dst_with_other_send
73 /**************************************/
74 /******* Resource Public **********/
75 /**************************************/
77 static void *name_service(const char *name)
79 return xbt_dict_get_or_null(workstation_set, name);
82 static const char *get_resource_name(void *resource_id)
84 /* We can freely cast as a cpu_KCCFLN05_t because it has the same
85 prefix as network_link_KCCFLN05_t. However, only cpu_KCCFLN05_t
86 will theoretically be given as an argument here. */
87 return ((cpu_KCCFLN05_t) resource_id)->name;
90 /* action_get_state is inherited from the surf module */
92 static void action_use(surf_action_t action)
98 static int action_free(surf_action_t action)
101 surf_action_t act = NULL;
102 cpu_KCCFLN05_t src = ((surf_action_workstation_KCCFLN05_t) action)->src;
103 cpu_KCCFLN05_t dst = ((surf_action_workstation_KCCFLN05_t) action)->dst;
106 if (!action->using) {
107 xbt_swag_remove(action, action->state_set);
108 if (((surf_action_workstation_KCCFLN05_t) action)->variable)
109 lmm_variable_free(maxmin_system,
110 ((surf_action_workstation_KCCFLN05_t) action)->
113 xbt_dynar_foreach(src->outgoing_communications, cpt, act)
115 xbt_dynar_remove_at(src->outgoing_communications, cpt, &act);
120 xbt_dynar_foreach(dst->incomming_communications, cpt, act)
122 xbt_dynar_remove_at(dst->incomming_communications, cpt, &act);
126 if(src && (!xbt_dynar_length(src->outgoing_communications)))
127 __update_cpu_usage(src);
128 if(dst && (!xbt_dynar_length(dst->incomming_communications)))
129 __update_cpu_usage(dst);
137 static void action_cancel(surf_action_t action)
139 surf_action_change_state(action, SURF_ACTION_FAILED);
143 static void action_recycle(surf_action_t action)
149 /* action_change_state is inherited from the surf module */
150 /* action_set_data is inherited from the surf module */
152 static void action_suspend(surf_action_t action)
154 XBT_IN1("(%p))",action);
155 if(((surf_action_workstation_KCCFLN05_t) action)->suspended != 2) {
156 ((surf_action_workstation_KCCFLN05_t) action)->suspended = 1;
157 lmm_update_variable_weight(maxmin_system,
158 ((surf_action_workstation_KCCFLN05_t)
159 action)->variable, 0.0);
164 static void action_resume(surf_action_t action)
166 XBT_IN1("(%p)",action);
167 if(((surf_action_workstation_KCCFLN05_t) action)->suspended !=2) {
168 if(((surf_action_workstation_KCCFLN05_t)action)->lat_current==0.0)
169 lmm_update_variable_weight(maxmin_system,
170 ((surf_action_workstation_KCCFLN05_t)
171 action)->variable, 1.0);
173 lmm_update_variable_weight(maxmin_system,
174 ((surf_action_workstation_KCCFLN05_t) action)->variable,
175 ((surf_action_workstation_KCCFLN05_t) action)->lat_current);
177 ((surf_action_workstation_KCCFLN05_t) action)->suspended = 0;
182 static int action_is_suspended(surf_action_t action)
184 return (((surf_action_workstation_KCCFLN05_t) action)->suspended==1);
187 static void action_set_max_duration(surf_action_t action, double duration)
188 { /* FIXME: should inherit */
189 XBT_IN2("(%p,%g)",action,duration);
190 action->max_duration = duration;
195 static void action_set_priority(surf_action_t action, double priority)
196 { /* FIXME: should inherit */
197 XBT_IN2("(%p,%g)",action,priority);
198 action->priority = priority;
202 /**************************************/
203 /******* Resource Private **********/
204 /**************************************/
206 static int resource_used(void *resource_id)
208 /* We can freely cast as a network_link_KCCFLN05_t because it has
209 the same prefix as cpu_KCCFLN05_t */
210 if(((cpu_KCCFLN05_t) resource_id)->type == SURF_WORKSTATION_RESOURCE_CPU)
211 return (lmm_constraint_used(maxmin_system,
212 ((cpu_KCCFLN05_t) resource_id)->
214 ((((cpu_KCCFLN05_t) resource_id)->bus)?
215 lmm_constraint_used(maxmin_system,
216 ((cpu_KCCFLN05_t) resource_id)->
219 return lmm_constraint_used(maxmin_system,
220 ((network_link_KCCFLN05_t) resource_id)->
225 static double share_resources(double now)
227 s_surf_action_workstation_KCCFLN05_t s_action;
228 surf_action_workstation_KCCFLN05_t action = NULL;
230 xbt_swag_t running_actions = surf_workstation_resource->common_public->states.running_action_set;
231 double min = generic_maxmin_share_resources(running_actions,
232 xbt_swag_offset(s_action, variable));
234 xbt_swag_foreach(action, running_actions) {
235 if(action->latency>0) {
237 min = action->latency;
238 DEBUG3("Updating min (value) with %p (start %f): %f",action,
239 action->generic_action.start, min);
241 else if (action->latency<min) {
242 min = action->latency;
243 DEBUG3("Updating min (latency) with %p (start %f): %f",action,
244 action->generic_action.start, min);
249 DEBUG1("min value : %f",min);
254 static void update_actions_state(double now, double delta)
257 surf_action_workstation_KCCFLN05_t action = NULL;
258 surf_action_workstation_KCCFLN05_t next_action = NULL;
259 xbt_swag_t running_actions =
260 surf_workstation_resource->common_public->states.running_action_set;
262 xbt_swag_foreach_safe(action, next_action, running_actions) {
264 if (action->latency > 0) {
265 if (action->latency > deltap) {
266 double_update(&(action->latency), deltap);
269 double_update(&(deltap), action->latency);
270 action->latency = 0.0;
272 if ((action->latency == 0.0) && (action->suspended==0)) {
273 if((action)->lat_current==0.0)
274 lmm_update_variable_weight(maxmin_system,action->variable, 1.0);
276 lmm_update_variable_weight(maxmin_system, action->variable,
277 action->lat_current);
280 DEBUG3("Action (%p) : remains (%g) updated by %g.",
281 action, action->generic_action.remains,
282 lmm_variable_getvalue(action->variable) * deltap);
283 double_update(&(action->generic_action.remains),
284 lmm_variable_getvalue(action->variable) * deltap);
286 if (action->generic_action.max_duration != NO_MAX_DURATION)
287 double_update(&(action->generic_action.max_duration), delta);
289 /* if(action->generic_action.remains<.00001) action->generic_action.remains=0; */
291 if ((action->generic_action.remains <= 0) &&
292 (lmm_get_variable_weight(action->variable)>0)) {
293 action->generic_action.finish = surf_get_clock();
294 surf_action_change_state((surf_action_t) action, SURF_ACTION_DONE);
295 } else if ((action->generic_action.max_duration != NO_MAX_DURATION) &&
296 (action->generic_action.max_duration <= 0)) {
297 action->generic_action.finish = surf_get_clock();
298 surf_action_change_state((surf_action_t) action, SURF_ACTION_DONE);
299 } else { /* Need to check that none of the resource has failed */
300 lmm_constraint_t cnst = NULL;
302 void *constraint_id = NULL;
305 lmm_get_cnst_from_var(maxmin_system, action->variable,
307 constraint_id = lmm_constraint_id(cnst);
308 if(((((network_link_KCCFLN05_t)constraint_id)->type==
309 SURF_WORKSTATION_RESOURCE_LINK) &&
310 (((network_link_KCCFLN05_t)constraint_id)->state_current==
311 SURF_NETWORK_LINK_OFF)) ||
312 ((((cpu_KCCFLN05_t)constraint_id)->type==
313 SURF_WORKSTATION_RESOURCE_CPU) &&
314 (((cpu_KCCFLN05_t)constraint_id)->state_current==
316 action->generic_action.finish = surf_get_clock();
317 surf_action_change_state((surf_action_t) action, SURF_ACTION_FAILED);
326 static void update_resource_state(void *id,
327 tmgr_trace_event_t event_type,
330 cpu_KCCFLN05_t cpu = id;
331 network_link_KCCFLN05_t nw_link = id ;
333 if(nw_link->type == SURF_WORKSTATION_RESOURCE_LINK) {
334 if (event_type == nw_link->bw_event) {
335 nw_link->bw_current = value;
336 lmm_update_constraint_bound(maxmin_system, nw_link->constraint,
337 nw_link->bw_current);
338 } else if (event_type == nw_link->lat_event) {
339 double delta = value - nw_link->lat_current;
340 lmm_variable_t var = NULL;
341 surf_action_workstation_KCCFLN05_t action = NULL;
343 nw_link->lat_current = value;
344 while (lmm_get_var_from_cnst(maxmin_system, nw_link->constraint, &var)) {
345 action = lmm_variable_id(var);
346 action->lat_current += delta;
348 lmm_update_variable_bound(maxmin_system, action->variable,
349 SG_TCP_CTE_GAMMA / (2.0 * action->lat_current));
351 lmm_update_variable_bound(maxmin_system, action->variable,
352 min(action->rate,SG_TCP_CTE_GAMMA / (2.0 * action->lat_current)));
353 if(action->suspended==0)
354 lmm_update_variable_weight(maxmin_system, action->variable,
355 action->lat_current);
356 lmm_update_variable_latency(maxmin_system, action->variable, delta);
360 } else if (event_type == nw_link->state_event) {
362 nw_link->state_current = SURF_NETWORK_LINK_ON;
364 nw_link->state_current = SURF_NETWORK_LINK_OFF;
366 CRITICAL0("Unknown event ! \n");
370 } else if(cpu->type == SURF_WORKSTATION_RESOURCE_CPU) {
371 if (event_type == cpu->power_event) {
372 cpu->power_current = value;
373 __update_cpu_usage(cpu);
374 } else if (event_type == cpu->state_event) {
376 cpu->state_current = SURF_CPU_ON;
378 cpu->state_current = SURF_CPU_OFF;
380 CRITICAL0("Unknown event ! \n");
390 static void finalize(void)
394 xbt_dict_free(&network_link_set);
395 xbt_dict_free(&workstation_set);
396 if (parallel_task_network_link_set != NULL) {
397 xbt_dict_free(¶llel_task_network_link_set);
399 xbt_swag_free(surf_workstation_resource->common_public->states.
401 xbt_swag_free(surf_workstation_resource->common_public->states.
403 xbt_swag_free(surf_workstation_resource->common_public->states.
405 xbt_swag_free(surf_workstation_resource->common_public->states.
408 free(surf_workstation_resource->common_public);
409 free(surf_workstation_resource->common_private);
410 free(surf_workstation_resource->extension_public);
412 free(surf_workstation_resource);
413 surf_workstation_resource = NULL;
415 for (i = 0; i < nb_workstation; i++)
416 for (j = 0; j < nb_workstation; j++)
417 free(ROUTE(i, j).links);
419 routing_table = NULL;
423 lmm_system_free(maxmin_system);
424 maxmin_system = NULL;
428 /**************************************/
429 /******* Resource Private **********/
430 /**************************************/
432 static surf_action_t execute(void *cpu, double size)
434 surf_action_workstation_KCCFLN05_t action = NULL;
435 cpu_KCCFLN05_t CPU = cpu;
437 XBT_IN2("(%s,%g)",CPU->name,size);
438 action = xbt_new0(s_surf_action_workstation_KCCFLN05_t, 1);
440 action->generic_action.using = 1;
441 action->generic_action.cost = size;
442 action->generic_action.remains = size;
443 action->generic_action.priority = 1.0;
444 action->generic_action.max_duration = NO_MAX_DURATION;
445 action->generic_action.start = surf_get_clock();
446 action->generic_action.finish = -1.0;
447 action->generic_action.resource_type =
448 (surf_resource_t) surf_workstation_resource;
449 action->suspended = 0;
451 if (CPU->state_current == SURF_CPU_ON)
452 action->generic_action.state_set =
453 surf_workstation_resource->common_public->states.running_action_set;
455 action->generic_action.state_set =
456 surf_workstation_resource->common_public->states.failed_action_set;
457 xbt_swag_insert(action, action->generic_action.state_set);
459 action->variable = lmm_variable_new(maxmin_system, action,
460 action->generic_action.priority, -1.0, 1);
461 lmm_expand(maxmin_system, CPU->constraint, action->variable,
464 return (surf_action_t) action;
467 static surf_action_t action_sleep(void *cpu, double duration)
469 surf_action_workstation_KCCFLN05_t action = NULL;
471 XBT_IN2("(%s,%g)",((cpu_KCCFLN05_t)cpu)->name,duration);
473 action = (surf_action_workstation_KCCFLN05_t) execute(cpu, 1.0);
474 action->generic_action.max_duration = duration;
475 action->suspended = 2;
476 lmm_update_variable_weight(maxmin_system, action->variable, 0.0);
479 return (surf_action_t) action;
482 static e_surf_cpu_state_t resource_get_state(void *cpu)
484 return ((cpu_KCCFLN05_t) cpu)->state_current;
487 static double get_speed(void *cpu, double load)
489 return load*(((cpu_KCCFLN05_t) cpu)->power_scale);
492 static double get_available_speed(void *cpu)
494 return ((cpu_KCCFLN05_t) cpu)->power_current;
498 static surf_action_t communicate(void *src, void *dst, double size, double rate)
500 surf_action_workstation_KCCFLN05_t action = NULL;
501 cpu_KCCFLN05_t card_src = src;
502 cpu_KCCFLN05_t card_dst = dst;
503 route_KCCFLN05_t route = &(ROUTE(card_src->id, card_dst->id));
504 int route_size = route->size;
507 XBT_IN4("(%s,%s,%g,%g)",card_src->name,card_dst->name,size,rate);
508 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);
510 action = xbt_new0(s_surf_action_workstation_KCCFLN05_t, 1);
512 action->generic_action.using = 1;
513 action->generic_action.cost = size;
514 action->generic_action.remains = size;
515 action->generic_action.max_duration = NO_MAX_DURATION;
516 action->generic_action.start = surf_get_clock();
517 action->generic_action.finish = -1.0;
520 action->generic_action.resource_type =
521 (surf_resource_t) surf_workstation_resource;
522 action->suspended = 0; /* Should be useless because of the
523 calloc but it seems to help valgrind... */
524 action->generic_action.state_set =
525 surf_workstation_resource->common_public->states.running_action_set;
527 xbt_dynar_push(card_src->outgoing_communications, &action);
528 xbt_dynar_push(card_dst->incomming_communications, &action);
530 xbt_swag_insert(action, action->generic_action.state_set);
533 action->latency = 0.0;
534 for (i = 0; i < route_size; i++)
535 action->latency += route->links[i]->lat_current;
536 action->lat_current = action->latency;
538 if(action->latency>0)
539 action->variable = lmm_variable_new(maxmin_system, action, 0.0, -1.0,
540 route_size+4); /* +1 for the src bus
543 +1 for the dst cpu */
545 action->variable = lmm_variable_new(maxmin_system, action, 1.0, -1.0,
549 if(action->lat_current>0)
550 lmm_update_variable_bound(maxmin_system, action->variable,
551 SG_TCP_CTE_GAMMA / (2.0 * action->lat_current));
553 lmm_update_variable_bound(maxmin_system, action->variable, -1.0);
555 if(action->lat_current>0)
556 lmm_update_variable_bound(maxmin_system, action->variable,
557 min(action->rate,SG_TCP_CTE_GAMMA / (2.0 * action->lat_current)));
559 lmm_update_variable_bound(maxmin_system, action->variable, action->rate);
562 lmm_update_variable_latency(maxmin_system, action->variable, action->latency);
564 for (i = 0; i < route_size; i++)
565 lmm_expand(maxmin_system, route->links[i]->constraint, action->variable, 1.0);
567 lmm_expand(maxmin_system, card_src->bus, action->variable, 1.0);
569 lmm_expand(maxmin_system, card_dst->bus, action->variable, 1.0);
570 lmm_expand(maxmin_system, card_src->constraint, action->variable, 0.0);
571 lmm_expand(maxmin_system, card_dst->constraint, action->variable, 0.0);
574 return (surf_action_t) action;
577 static surf_action_t execute_parallel_task(int workstation_nb,
578 void **workstation_list,
579 double *computation_amount,
580 double *communication_amount,
584 surf_action_workstation_KCCFLN05_t action = NULL;
589 if (parallel_task_network_link_set == NULL) {
590 parallel_task_network_link_set = xbt_dict_new_ext(workstation_nb * workstation_nb * 10);
593 /* Compute the number of affected resources... */
594 for(i=0; i< workstation_nb; i++) {
595 for(j=0; j< workstation_nb; j++) {
596 cpu_KCCFLN05_t card_src = workstation_list[i];
597 cpu_KCCFLN05_t card_dst = workstation_list[j];
598 int route_size = ROUTE(card_src->id, card_dst->id).size;
599 network_link_KCCFLN05_t *route = ROUTE(card_src->id, card_dst->id).links;
601 if(communication_amount[i*workstation_nb+j]>0)
602 for(k=0; k< route_size; k++) {
603 xbt_dict_set(parallel_task_network_link_set, route[k]->name, route[k], NULL);
607 nb_link = xbt_dict_length(parallel_task_network_link_set);
608 xbt_dict_reset(parallel_task_network_link_set);
611 for (i = 0; i<workstation_nb; i++)
612 if(computation_amount[i]>0) nb_host++;
615 if(nb_link + nb_host == 0) /* was workstation_nb... */
618 action = xbt_new0(s_surf_action_workstation_KCCFLN05_t, 1);
619 DEBUG3("Creating a parallel task (%p) with %d cpus and %d links.",
620 action, nb_host, nb_link);
621 action->generic_action.using = 1;
622 action->generic_action.cost = amount;
623 action->generic_action.remains = amount;
624 action->generic_action.max_duration = NO_MAX_DURATION;
625 action->generic_action.start = -1.0;
626 action->generic_action.finish = -1.0;
627 action->generic_action.resource_type =
628 (surf_resource_t) surf_workstation_resource;
629 action->suspended = 0; /* Should be useless because of the
630 calloc but it seems to help valgrind... */
631 action->generic_action.state_set =
632 surf_workstation_resource->common_public->states.running_action_set;
634 xbt_swag_insert(action, action->generic_action.state_set);
638 action->variable = lmm_variable_new(maxmin_system, action, 1.0, -1.0,
641 action->variable = lmm_variable_new(maxmin_system, action, 1.0, action->rate,
644 for (i = 0; i<workstation_nb; i++)
645 if(computation_amount[i]>0)
646 lmm_expand(maxmin_system, ((cpu_KCCFLN05_t) workstation_list[i])->constraint,
647 action->variable, computation_amount[i]);
649 for (i=0; i<workstation_nb; i++) {
650 for(j=0; j< workstation_nb; j++) {
651 cpu_KCCFLN05_t card_src = workstation_list[i];
652 cpu_KCCFLN05_t card_dst = workstation_list[j];
653 int route_size = ROUTE(card_src->id, card_dst->id).size;
654 network_link_KCCFLN05_t *route = ROUTE(card_src->id, card_dst->id).links;
656 for(k=0; k< route_size; k++) {
657 if(communication_amount[i*workstation_nb+j]>0) {
658 lmm_expand_add(maxmin_system, route[k]->constraint,
659 action->variable, communication_amount[i*workstation_nb+j]);
665 return (surf_action_t) action;
668 /* returns an array of network_link_KCCFLN05_t */
669 static const void** get_route(void *src, void *dst) {
670 cpu_KCCFLN05_t card_src = src;
671 cpu_KCCFLN05_t card_dst = dst;
672 route_KCCFLN05_t route = &(ROUTE(card_src->id, card_dst->id));
674 return (const void**) route->links;
677 static int get_route_size(void *src, void *dst) {
678 cpu_KCCFLN05_t card_src = src;
679 cpu_KCCFLN05_t card_dst = dst;
680 route_KCCFLN05_t route = &(ROUTE(card_src->id, card_dst->id));
684 static const char *get_link_name(const void *link) {
685 return ((network_link_KCCFLN05_t) link)->name;
688 static double get_link_bandwidth(const void *link) {
689 return ((network_link_KCCFLN05_t) link)->bw_current;
692 static double get_link_latency(const void *link) {
693 return ((network_link_KCCFLN05_t) link)->lat_current;
696 /**************************************/
697 /*** Resource Creation & Destruction **/
698 /**************************************/
700 static void cpu_free(void *cpu)
702 free(((cpu_KCCFLN05_t) cpu)->name);
703 xbt_dynar_free(&(((cpu_KCCFLN05_t) cpu)->incomming_communications));
704 xbt_dynar_free(&(((cpu_KCCFLN05_t) cpu)->outgoing_communications));
708 static cpu_KCCFLN05_t cpu_new(const char *name, double power_scale,
709 double power_initial,
710 tmgr_trace_t power_trace,
711 e_surf_cpu_state_t state_initial,
712 tmgr_trace_t state_trace,
713 double interference_send,
714 double interference_recv,
715 double interference_send_recv,
716 double max_outgoing_rate)
718 cpu_KCCFLN05_t cpu = xbt_new0(s_cpu_KCCFLN05_t, 1);
720 cpu->resource = (surf_resource_t) surf_workstation_resource;
721 cpu->type = SURF_WORKSTATION_RESOURCE_CPU;
722 cpu->name = xbt_strdup(name);
723 cpu->id = nb_workstation++;
725 cpu->power_scale = power_scale;
726 xbt_assert0(cpu->power_scale > 0, "Power has to be >0");
728 cpu->power_current = power_initial;
731 tmgr_history_add_trace(history, power_trace, 0.0, 0, cpu);
733 cpu->state_current = state_initial;
736 tmgr_history_add_trace(history, state_trace, 0.0, 0, cpu);
738 cpu->interference_send = interference_send;
739 cpu->interference_recv = interference_recv;
740 cpu->interference_send_recv = interference_send_recv;
743 lmm_constraint_new(maxmin_system, cpu,
744 cpu->power_current * cpu->power_scale);
745 if (max_outgoing_rate > 0)
746 cpu->bus = lmm_constraint_new(maxmin_system, cpu, max_outgoing_rate);
748 cpu->incomming_communications =
749 xbt_dynar_new(sizeof(surf_action_workstation_KCCFLN05_t), NULL);
750 cpu->outgoing_communications =
751 xbt_dynar_new(sizeof(surf_action_workstation_KCCFLN05_t), NULL);
753 xbt_dict_set(workstation_set, name, cpu, cpu_free);
758 static void parse_cpu(void)
760 double power_scale = 0.0;
761 double power_initial = 0.0;
762 tmgr_trace_t power_trace = NULL;
763 e_surf_cpu_state_t state_initial = SURF_CPU_OFF;
764 tmgr_trace_t state_trace = NULL;
765 double interference_send = 0.0;
766 double interference_recv = 0.0;
767 double interference_send_recv = 0.0;
768 double max_outgoing_rate = -1.0;
770 surf_parse_get_double(&power_scale, A_surfxml_cpu_power);
771 surf_parse_get_double(&power_initial, A_surfxml_cpu_availability);
772 surf_parse_get_trace(&power_trace, A_surfxml_cpu_availability_file);
774 xbt_assert0((A_surfxml_cpu_state == A_surfxml_cpu_state_ON) ||
775 (A_surfxml_cpu_state == A_surfxml_cpu_state_OFF),
777 if (A_surfxml_cpu_state == A_surfxml_cpu_state_ON)
778 state_initial = SURF_CPU_ON;
779 if (A_surfxml_cpu_state == A_surfxml_cpu_state_OFF)
780 state_initial = SURF_CPU_OFF;
781 surf_parse_get_trace(&state_trace, A_surfxml_cpu_state_file);
783 surf_parse_get_double(&interference_send,
784 A_surfxml_cpu_interference_send);
785 surf_parse_get_double(&interference_recv,
786 A_surfxml_cpu_interference_recv);
787 surf_parse_get_double(&interference_send_recv,
788 A_surfxml_cpu_interference_send_recv);
789 surf_parse_get_double(&max_outgoing_rate,
790 A_surfxml_cpu_max_outgoing_rate);
792 cpu_new(A_surfxml_cpu_name, power_scale, power_initial, power_trace,
793 state_initial, state_trace, interference_send, interference_recv,
794 interference_send_recv, max_outgoing_rate);
797 static void create_routing_table(void)
800 xbt_new0(s_route_KCCFLN05_t, nb_workstation * nb_workstation);
803 static void network_link_free(void *nw_link)
805 free(((network_link_KCCFLN05_t) nw_link)->name);
809 static network_link_KCCFLN05_t network_link_new(char *name,
811 tmgr_trace_t bw_trace,
813 tmgr_trace_t lat_trace,
814 e_surf_network_link_state_t
816 tmgr_trace_t state_trace,
817 e_surf_network_link_sharing_policy_t policy)
819 network_link_KCCFLN05_t nw_link = xbt_new0(s_network_link_KCCFLN05_t, 1);
822 nw_link->resource = (surf_resource_t) surf_workstation_resource;
823 nw_link->type = SURF_WORKSTATION_RESOURCE_LINK;
824 nw_link->name = name;
825 nw_link->bw_current = bw_initial;
828 tmgr_history_add_trace(history, bw_trace, 0.0, 0, nw_link);
829 nw_link->state_current = state_initial;
830 nw_link->lat_current = lat_initial;
833 tmgr_history_add_trace(history, lat_trace, 0.0, 0, nw_link);
835 nw_link->state_event =
836 tmgr_history_add_trace(history, state_trace, 0.0, 0, nw_link);
838 nw_link->constraint =
839 lmm_constraint_new(maxmin_system, nw_link, nw_link->bw_current);
841 if(policy == SURF_NETWORK_LINK_FATPIPE)
842 lmm_constraint_shared(nw_link->constraint);
844 xbt_dict_set(network_link_set, name, nw_link, network_link_free);
849 static void parse_network_link(void)
853 tmgr_trace_t bw_trace;
855 tmgr_trace_t lat_trace;
856 e_surf_network_link_state_t state_initial = SURF_NETWORK_LINK_ON;
857 e_surf_network_link_sharing_policy_t policy_initial = SURF_NETWORK_LINK_SHARED;
858 tmgr_trace_t state_trace;
860 name = xbt_strdup(A_surfxml_network_link_name);
861 surf_parse_get_double(&bw_initial,A_surfxml_network_link_bandwidth);
862 surf_parse_get_trace(&bw_trace, A_surfxml_network_link_bandwidth_file);
863 surf_parse_get_double(&lat_initial,A_surfxml_network_link_latency);
864 surf_parse_get_trace(&lat_trace, A_surfxml_network_link_latency_file);
866 xbt_assert0((A_surfxml_network_link_state==A_surfxml_network_link_state_ON)||
867 (A_surfxml_network_link_state==A_surfxml_network_link_state_OFF),
869 if (A_surfxml_network_link_state==A_surfxml_network_link_state_ON)
870 state_initial = SURF_NETWORK_LINK_ON;
871 else if (A_surfxml_network_link_state==A_surfxml_network_link_state_OFF)
872 state_initial = SURF_NETWORK_LINK_OFF;
874 if (A_surfxml_network_link_sharing_policy==A_surfxml_network_link_sharing_policy_SHARED)
875 policy_initial = SURF_NETWORK_LINK_SHARED;
876 else if (A_surfxml_network_link_sharing_policy==A_surfxml_network_link_sharing_policy_FATPIPE)
877 policy_initial = SURF_NETWORK_LINK_FATPIPE;
879 surf_parse_get_trace(&state_trace,A_surfxml_network_link_state_file);
881 network_link_new(name, bw_initial, bw_trace,
882 lat_initial, lat_trace, state_initial, state_trace,
886 static void route_new(int src_id, int dst_id, network_link_KCCFLN05_t *link_list, int nb_link,
887 double impact_on_src, double impact_on_dst,
888 double impact_on_src_with_other_recv,
889 double impact_on_dst_with_other_send)
891 route_KCCFLN05_t route = &(ROUTE(src_id, dst_id));
893 route->size = nb_link;
894 route->links = link_list = xbt_realloc(link_list, sizeof(network_link_KCCFLN05_t) * nb_link);
895 route->impact_on_src = impact_on_src;
896 route->impact_on_dst = impact_on_src;
897 route->impact_on_src_with_other_recv = impact_on_src_with_other_recv;
898 route->impact_on_dst_with_other_send = impact_on_dst_with_other_send;
902 static int link_list_capacity;
903 static network_link_KCCFLN05_t *link_list = NULL;
904 static int src_id = -1;
905 static int dst_id = -1;
906 static double impact_on_src;
907 static double impact_on_dst;
908 static double impact_on_src_with_other_recv;
909 static double impact_on_dst_with_other_send;
911 static void parse_route_set_endpoints(void)
913 src_id = ((cpu_KCCFLN05_t) name_service(A_surfxml_route_src))->id;
914 dst_id = ((cpu_KCCFLN05_t) name_service(A_surfxml_route_dst))->id;
915 surf_parse_get_double(&impact_on_src, A_surfxml_route_impact_on_src);
916 surf_parse_get_double(&impact_on_dst, A_surfxml_route_impact_on_dst);
917 surf_parse_get_double(&impact_on_src_with_other_recv,
918 A_surfxml_route_impact_on_src_with_other_recv);
919 surf_parse_get_double(&impact_on_dst_with_other_send,
920 A_surfxml_route_impact_on_dst_with_other_send);
923 link_list_capacity = 20;
924 link_list = xbt_new(network_link_KCCFLN05_t, link_list_capacity);
927 static void parse_route_elem(void)
929 if (nb_link == link_list_capacity) {
930 link_list_capacity *= 2;
931 link_list = xbt_realloc(link_list, (link_list_capacity) * sizeof(network_link_KCCFLN05_t));
933 link_list[nb_link++] = xbt_dict_get_or_null(network_link_set, A_surfxml_route_element_name);
936 static void parse_route_set_route(void)
938 route_new(src_id, dst_id, link_list, nb_link, impact_on_src,
939 impact_on_dst, impact_on_src_with_other_recv,
940 impact_on_dst_with_other_send);
943 static void parse_file(const char *file)
947 /* Figuring out the cpus */
948 surf_parse_reset_parser();
949 ETag_surfxml_cpu_fun = parse_cpu;
950 surf_parse_open(file);
951 xbt_assert1((!surf_parse()), "Parse error in %s", file);
954 create_routing_table();
956 /* Figuring out the network links */
957 surf_parse_reset_parser();
958 ETag_surfxml_network_link_fun = parse_network_link;
959 surf_parse_open(file);
960 xbt_assert1((!surf_parse()), "Parse error in %s", file);
963 /* Building the routes */
964 surf_parse_reset_parser();
965 STag_surfxml_route_fun = parse_route_set_endpoints;
966 ETag_surfxml_route_element_fun = parse_route_elem;
967 ETag_surfxml_route_fun = parse_route_set_route;
968 surf_parse_open(file);
969 xbt_assert1((!surf_parse()), "Parse error in %s", file);
972 /* Adding loopback if needed */
973 for (i = 0; i < nb_workstation; i++)
974 if(!ROUTE(i,i).size) {
976 loopback = network_link_new(xbt_strdup("__MSG_loopback__"),
977 498000000, NULL, 0.000015, NULL,
978 SURF_NETWORK_LINK_ON, NULL,
979 SURF_NETWORK_LINK_FATPIPE);
981 ROUTE(i,i).links = xbt_new0(network_link_KCCFLN05_t, 1);
982 ROUTE(i,i).links[0] = loopback;
987 /**************************************/
988 /********* Module creation ***********/
989 /**************************************/
991 static void resource_init_internal(void)
993 s_surf_action_t action;
995 surf_workstation_resource = xbt_new0(s_surf_workstation_resource_t, 1);
997 surf_workstation_resource->common_private =
998 xbt_new0(s_surf_resource_private_t, 1);
999 surf_workstation_resource->common_public =
1000 xbt_new0(s_surf_resource_public_t, 1);
1001 surf_workstation_resource->extension_public =
1002 xbt_new0(s_surf_workstation_resource_extension_public_t, 1);
1004 surf_workstation_resource->common_public->states.ready_action_set =
1005 xbt_swag_new(xbt_swag_offset(action, state_hookup));
1006 surf_workstation_resource->common_public->states.running_action_set =
1007 xbt_swag_new(xbt_swag_offset(action, state_hookup));
1008 surf_workstation_resource->common_public->states.failed_action_set =
1009 xbt_swag_new(xbt_swag_offset(action, state_hookup));
1010 surf_workstation_resource->common_public->states.done_action_set =
1011 xbt_swag_new(xbt_swag_offset(action, state_hookup));
1013 surf_workstation_resource->common_public->name_service = name_service;
1014 surf_workstation_resource->common_public->get_resource_name = get_resource_name;
1015 surf_workstation_resource->common_public->action_get_state = surf_action_get_state;
1016 surf_workstation_resource->common_public->action_get_start_time =
1017 surf_action_get_start_time;
1018 surf_workstation_resource->common_public->action_get_finish_time =
1019 surf_action_get_finish_time;
1020 surf_workstation_resource->common_public->action_use = action_use;
1021 surf_workstation_resource->common_public->action_free = action_free;
1022 surf_workstation_resource->common_public->action_cancel = action_cancel;
1023 surf_workstation_resource->common_public->action_recycle = action_recycle;
1024 surf_workstation_resource->common_public->action_change_state = surf_action_change_state;
1025 surf_workstation_resource->common_public->action_set_data = surf_action_set_data;
1026 surf_workstation_resource->common_public->suspend = action_suspend;
1027 surf_workstation_resource->common_public->resume = action_resume;
1028 surf_workstation_resource->common_public->is_suspended = action_is_suspended;
1029 surf_workstation_resource->common_public->set_max_duration = action_set_max_duration;
1030 surf_workstation_resource->common_public->set_priority = action_set_priority;
1031 surf_workstation_resource->common_public->name = "Workstation KCCFLN05";
1033 surf_workstation_resource->common_private->resource_used = resource_used;
1034 surf_workstation_resource->common_private->share_resources = share_resources;
1035 surf_workstation_resource->common_private->update_actions_state = update_actions_state;
1036 surf_workstation_resource->common_private->update_resource_state = update_resource_state;
1037 surf_workstation_resource->common_private->finalize = finalize;
1039 surf_workstation_resource->extension_public->execute = execute;
1040 surf_workstation_resource->extension_public->sleep = action_sleep;
1041 surf_workstation_resource->extension_public->get_state = resource_get_state;
1042 surf_workstation_resource->extension_public->get_speed = get_speed;
1043 surf_workstation_resource->extension_public->get_available_speed = get_available_speed;
1044 surf_workstation_resource->extension_public->communicate = communicate;
1045 surf_workstation_resource->extension_public->execute_parallel_task = execute_parallel_task;
1046 surf_workstation_resource->extension_public->get_route = get_route;
1047 surf_workstation_resource->extension_public->get_route_size = get_route_size;
1048 surf_workstation_resource->extension_public->get_link_name = get_link_name;
1049 surf_workstation_resource->extension_public->get_link_bandwidth = get_link_bandwidth;
1050 surf_workstation_resource->extension_public->get_link_latency = get_link_latency;
1052 workstation_set = xbt_dict_new();
1053 network_link_set = xbt_dict_new();
1055 xbt_assert0(maxmin_system, "surf_init has to be called first!");
1058 /**************************************/
1059 /*************** Generic **************/
1060 /**************************************/
1061 void surf_workstation_resource_init_KCCFLN05(const char *filename)
1063 xbt_assert0(!surf_cpu_resource, "CPU resource type already defined");
1064 xbt_assert0(!surf_network_resource, "network resource type already defined");
1065 resource_init_internal();
1066 parse_file(filename);
1068 xbt_dynar_push(resource_list, &surf_workstation_resource);
1071 void surf_workstation_resource_init_KCCFLN05_proportionnal(const char *filename)
1073 xbt_assert0(!surf_cpu_resource, "CPU resource type already defined");
1074 xbt_assert0(!surf_network_resource, "network resource type already defined");
1075 resource_init_internal();
1076 parse_file(filename);
1078 surf_workstation_resource->common_public->name = "Workstation KCCFLN05 (proportionnal)";
1080 xbt_dynar_push(resource_list, &surf_workstation_resource);