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)
82 res = xbt_dict_get(workstation_set, name);
84 RETHROW1("Host '%s' not found (dict raised this exception: %s)",name);
89 static const char *get_resource_name(void *resource_id)
91 /* We can freely cast as a cpu_KCCFLN05_t because it has the same
92 prefix as network_link_KCCFLN05_t. However, only cpu_KCCFLN05_t
93 will theoretically be given as an argument here. */
94 return ((cpu_KCCFLN05_t) resource_id)->name;
97 /* action_get_state is inherited from the surf module */
99 static void action_use(surf_action_t action)
105 static int action_free(surf_action_t action)
108 surf_action_t act = NULL;
109 cpu_KCCFLN05_t src = ((surf_action_workstation_KCCFLN05_t) action)->src;
110 cpu_KCCFLN05_t dst = ((surf_action_workstation_KCCFLN05_t) action)->dst;
113 if (!action->using) {
114 xbt_swag_remove(action, action->state_set);
115 if (((surf_action_workstation_KCCFLN05_t) action)->variable)
116 lmm_variable_free(maxmin_system,
117 ((surf_action_workstation_KCCFLN05_t) action)->
120 xbt_dynar_foreach(src->outgoing_communications, cpt, act)
122 xbt_dynar_remove_at(src->outgoing_communications, cpt, &act);
127 xbt_dynar_foreach(dst->incomming_communications, cpt, act)
129 xbt_dynar_remove_at(dst->incomming_communications, cpt, &act);
133 if(src && (!xbt_dynar_length(src->outgoing_communications)))
134 __update_cpu_usage(src);
135 if(dst && (!xbt_dynar_length(dst->incomming_communications)))
136 __update_cpu_usage(dst);
144 static void action_cancel(surf_action_t action)
146 surf_action_change_state(action, SURF_ACTION_FAILED);
150 static void action_recycle(surf_action_t action)
156 /* action_change_state is inherited from the surf module */
157 /* action_set_data is inherited from the surf module */
159 static void action_suspend(surf_action_t action)
161 XBT_IN1("(%p))",action);
162 if(((surf_action_workstation_KCCFLN05_t) action)->suspended != 2) {
163 ((surf_action_workstation_KCCFLN05_t) action)->suspended = 1;
164 lmm_update_variable_weight(maxmin_system,
165 ((surf_action_workstation_KCCFLN05_t)
166 action)->variable, 0.0);
171 static void action_resume(surf_action_t action)
173 XBT_IN1("(%p)",action);
174 if(((surf_action_workstation_KCCFLN05_t) action)->suspended !=2) {
175 if(((surf_action_workstation_KCCFLN05_t)action)->lat_current==0.0)
176 lmm_update_variable_weight(maxmin_system,
177 ((surf_action_workstation_KCCFLN05_t)
178 action)->variable, 1.0);
180 lmm_update_variable_weight(maxmin_system,
181 ((surf_action_workstation_KCCFLN05_t) action)->variable,
182 ((surf_action_workstation_KCCFLN05_t) action)->lat_current);
184 ((surf_action_workstation_KCCFLN05_t) action)->suspended = 0;
189 static int action_is_suspended(surf_action_t action)
191 return (((surf_action_workstation_KCCFLN05_t) action)->suspended==1);
194 static void action_set_max_duration(surf_action_t action, double duration)
195 { /* FIXME: should inherit */
196 XBT_IN2("(%p,%g)",action,duration);
197 action->max_duration = duration;
202 static void action_set_priority(surf_action_t action, double priority)
203 { /* FIXME: should inherit */
204 XBT_IN2("(%p,%g)",action,priority);
205 action->priority = priority;
209 /**************************************/
210 /******* Resource Private **********/
211 /**************************************/
213 static int resource_used(void *resource_id)
215 /* We can freely cast as a network_link_KCCFLN05_t because it has
216 the same prefix as cpu_KCCFLN05_t */
217 if(((cpu_KCCFLN05_t) resource_id)->type == SURF_WORKSTATION_RESOURCE_CPU)
218 return (lmm_constraint_used(maxmin_system,
219 ((cpu_KCCFLN05_t) resource_id)->
221 ((((cpu_KCCFLN05_t) resource_id)->bus)?
222 lmm_constraint_used(maxmin_system,
223 ((cpu_KCCFLN05_t) resource_id)->
226 return lmm_constraint_used(maxmin_system,
227 ((network_link_KCCFLN05_t) resource_id)->
232 static double share_resources(double now)
234 s_surf_action_workstation_KCCFLN05_t s_action;
235 surf_action_workstation_KCCFLN05_t action = NULL;
237 xbt_swag_t running_actions = surf_workstation_resource->common_public->states.running_action_set;
238 double min = generic_maxmin_share_resources(running_actions,
239 xbt_swag_offset(s_action, variable));
241 xbt_swag_foreach(action, running_actions) {
242 if(action->latency>0) {
244 min = action->latency;
245 DEBUG3("Updating min (value) with %p (start %f): %f",action,
246 action->generic_action.start, min);
248 else if (action->latency<min) {
249 min = action->latency;
250 DEBUG3("Updating min (latency) with %p (start %f): %f",action,
251 action->generic_action.start, min);
256 DEBUG1("min value : %f",min);
261 static void update_actions_state(double now, double delta)
264 surf_action_workstation_KCCFLN05_t action = NULL;
265 surf_action_workstation_KCCFLN05_t next_action = NULL;
266 xbt_swag_t running_actions =
267 surf_workstation_resource->common_public->states.running_action_set;
269 xbt_swag_foreach_safe(action, next_action, running_actions) {
271 if (action->latency > 0) {
272 if (action->latency > deltap) {
273 double_update(&(action->latency), deltap);
276 double_update(&(deltap), action->latency);
277 action->latency = 0.0;
279 if ((action->latency == 0.0) && (action->suspended==0)) {
280 if((action)->lat_current==0.0)
281 lmm_update_variable_weight(maxmin_system,action->variable, 1.0);
283 lmm_update_variable_weight(maxmin_system, action->variable,
284 action->lat_current);
287 DEBUG3("Action (%p) : remains (%g) updated by %g.",
288 action, action->generic_action.remains,
289 lmm_variable_getvalue(action->variable) * deltap);
290 double_update(&(action->generic_action.remains),
291 lmm_variable_getvalue(action->variable) * deltap);
293 if (action->generic_action.max_duration != NO_MAX_DURATION)
294 double_update(&(action->generic_action.max_duration), delta);
296 /* if(action->generic_action.remains<.00001) action->generic_action.remains=0; */
298 if ((action->generic_action.remains <= 0) &&
299 (lmm_get_variable_weight(action->variable)>0)) {
300 action->generic_action.finish = surf_get_clock();
301 surf_action_change_state((surf_action_t) action, SURF_ACTION_DONE);
302 } else if ((action->generic_action.max_duration != NO_MAX_DURATION) &&
303 (action->generic_action.max_duration <= 0)) {
304 action->generic_action.finish = surf_get_clock();
305 surf_action_change_state((surf_action_t) action, SURF_ACTION_DONE);
306 } else { /* Need to check that none of the resource has failed */
307 lmm_constraint_t cnst = NULL;
309 void *constraint_id = NULL;
312 lmm_get_cnst_from_var(maxmin_system, action->variable,
314 constraint_id = lmm_constraint_id(cnst);
315 if(((((network_link_KCCFLN05_t)constraint_id)->type==
316 SURF_WORKSTATION_RESOURCE_LINK) &&
317 (((network_link_KCCFLN05_t)constraint_id)->state_current==
318 SURF_NETWORK_LINK_OFF)) ||
319 ((((cpu_KCCFLN05_t)constraint_id)->type==
320 SURF_WORKSTATION_RESOURCE_CPU) &&
321 (((cpu_KCCFLN05_t)constraint_id)->state_current==
323 action->generic_action.finish = surf_get_clock();
324 surf_action_change_state((surf_action_t) action, SURF_ACTION_FAILED);
333 static void update_resource_state(void *id,
334 tmgr_trace_event_t event_type,
337 cpu_KCCFLN05_t cpu = id;
338 network_link_KCCFLN05_t nw_link = id ;
340 if(nw_link->type == SURF_WORKSTATION_RESOURCE_LINK) {
341 if (event_type == nw_link->bw_event) {
342 nw_link->bw_current = value;
343 lmm_update_constraint_bound(maxmin_system, nw_link->constraint,
344 nw_link->bw_current);
345 } else if (event_type == nw_link->lat_event) {
346 double delta = value - nw_link->lat_current;
347 lmm_variable_t var = NULL;
348 surf_action_workstation_KCCFLN05_t action = NULL;
350 nw_link->lat_current = value;
351 while (lmm_get_var_from_cnst(maxmin_system, nw_link->constraint, &var)) {
352 action = lmm_variable_id(var);
353 action->lat_current += delta;
355 lmm_update_variable_bound(maxmin_system, action->variable,
356 SG_TCP_CTE_GAMMA / (2.0 * action->lat_current));
358 lmm_update_variable_bound(maxmin_system, action->variable,
359 min(action->rate,SG_TCP_CTE_GAMMA / (2.0 * action->lat_current)));
360 if(action->suspended==0)
361 lmm_update_variable_weight(maxmin_system, action->variable,
362 action->lat_current);
363 lmm_update_variable_latency(maxmin_system, action->variable, delta);
367 } else if (event_type == nw_link->state_event) {
369 nw_link->state_current = SURF_NETWORK_LINK_ON;
371 nw_link->state_current = SURF_NETWORK_LINK_OFF;
373 CRITICAL0("Unknown event ! \n");
377 } else if(cpu->type == SURF_WORKSTATION_RESOURCE_CPU) {
378 if (event_type == cpu->power_event) {
379 cpu->power_current = value;
380 __update_cpu_usage(cpu);
381 } else if (event_type == cpu->state_event) {
383 cpu->state_current = SURF_CPU_ON;
385 cpu->state_current = SURF_CPU_OFF;
387 CRITICAL0("Unknown event ! \n");
397 static void finalize(void)
401 xbt_dict_free(&network_link_set);
402 xbt_dict_free(&workstation_set);
403 if (parallel_task_network_link_set != NULL) {
404 xbt_dict_free(¶llel_task_network_link_set);
406 xbt_swag_free(surf_workstation_resource->common_public->states.
408 xbt_swag_free(surf_workstation_resource->common_public->states.
410 xbt_swag_free(surf_workstation_resource->common_public->states.
412 xbt_swag_free(surf_workstation_resource->common_public->states.
415 free(surf_workstation_resource->common_public);
416 free(surf_workstation_resource->common_private);
417 free(surf_workstation_resource->extension_public);
419 free(surf_workstation_resource);
420 surf_workstation_resource = NULL;
422 for (i = 0; i < nb_workstation; i++)
423 for (j = 0; j < nb_workstation; j++)
424 free(ROUTE(i, j).links);
426 routing_table = NULL;
430 lmm_system_free(maxmin_system);
431 maxmin_system = NULL;
435 /**************************************/
436 /******* Resource Private **********/
437 /**************************************/
439 static surf_action_t execute(void *cpu, double size)
441 surf_action_workstation_KCCFLN05_t action = NULL;
442 cpu_KCCFLN05_t CPU = cpu;
444 XBT_IN2("(%s,%g)",CPU->name,size);
445 action = xbt_new0(s_surf_action_workstation_KCCFLN05_t, 1);
447 action->generic_action.using = 1;
448 action->generic_action.cost = size;
449 action->generic_action.remains = size;
450 action->generic_action.priority = 1.0;
451 action->generic_action.max_duration = NO_MAX_DURATION;
452 action->generic_action.start = surf_get_clock();
453 action->generic_action.finish = -1.0;
454 action->generic_action.resource_type =
455 (surf_resource_t) surf_workstation_resource;
456 action->suspended = 0;
458 if (CPU->state_current == SURF_CPU_ON)
459 action->generic_action.state_set =
460 surf_workstation_resource->common_public->states.running_action_set;
462 action->generic_action.state_set =
463 surf_workstation_resource->common_public->states.failed_action_set;
464 xbt_swag_insert(action, action->generic_action.state_set);
466 action->variable = lmm_variable_new(maxmin_system, action,
467 action->generic_action.priority, -1.0, 1);
468 lmm_expand(maxmin_system, CPU->constraint, action->variable,
471 return (surf_action_t) action;
474 static surf_action_t action_sleep(void *cpu, double duration)
476 surf_action_workstation_KCCFLN05_t action = NULL;
478 XBT_IN2("(%s,%g)",((cpu_KCCFLN05_t)cpu)->name,duration);
480 action = (surf_action_workstation_KCCFLN05_t) execute(cpu, 1.0);
481 action->generic_action.max_duration = duration;
482 action->suspended = 2;
483 lmm_update_variable_weight(maxmin_system, action->variable, 0.0);
486 return (surf_action_t) action;
489 static e_surf_cpu_state_t resource_get_state(void *cpu)
491 return ((cpu_KCCFLN05_t) cpu)->state_current;
494 static double get_speed(void *cpu, double load)
496 return load*(((cpu_KCCFLN05_t) cpu)->power_scale);
499 static double get_available_speed(void *cpu)
501 return ((cpu_KCCFLN05_t) cpu)->power_current;
505 static surf_action_t communicate(void *src, void *dst, double size, double rate)
507 surf_action_workstation_KCCFLN05_t action = NULL;
508 cpu_KCCFLN05_t card_src = src;
509 cpu_KCCFLN05_t card_dst = dst;
510 route_KCCFLN05_t route = &(ROUTE(card_src->id, card_dst->id));
511 int route_size = route->size;
514 XBT_IN4("(%s,%s,%g,%g)",card_src->name,card_dst->name,size,rate);
515 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);
517 action = xbt_new0(s_surf_action_workstation_KCCFLN05_t, 1);
519 action->generic_action.using = 1;
520 action->generic_action.cost = size;
521 action->generic_action.remains = size;
522 action->generic_action.max_duration = NO_MAX_DURATION;
523 action->generic_action.start = surf_get_clock();
524 action->generic_action.finish = -1.0;
527 action->generic_action.resource_type =
528 (surf_resource_t) surf_workstation_resource;
529 action->suspended = 0; /* Should be useless because of the
530 calloc but it seems to help valgrind... */
531 action->generic_action.state_set =
532 surf_workstation_resource->common_public->states.running_action_set;
534 xbt_dynar_push(card_src->outgoing_communications, &action);
535 xbt_dynar_push(card_dst->incomming_communications, &action);
537 xbt_swag_insert(action, action->generic_action.state_set);
540 action->latency = 0.0;
541 for (i = 0; i < route_size; i++)
542 action->latency += route->links[i]->lat_current;
543 action->lat_current = action->latency;
545 if(action->latency>0)
546 action->variable = lmm_variable_new(maxmin_system, action, 0.0, -1.0,
547 route_size+4); /* +1 for the src bus
550 +1 for the dst cpu */
552 action->variable = lmm_variable_new(maxmin_system, action, 1.0, -1.0,
556 if(action->lat_current>0)
557 lmm_update_variable_bound(maxmin_system, action->variable,
558 SG_TCP_CTE_GAMMA / (2.0 * action->lat_current));
560 lmm_update_variable_bound(maxmin_system, action->variable, -1.0);
562 if(action->lat_current>0)
563 lmm_update_variable_bound(maxmin_system, action->variable,
564 min(action->rate,SG_TCP_CTE_GAMMA / (2.0 * action->lat_current)));
566 lmm_update_variable_bound(maxmin_system, action->variable, action->rate);
569 lmm_update_variable_latency(maxmin_system, action->variable, action->latency);
571 for (i = 0; i < route_size; i++)
572 lmm_expand(maxmin_system, route->links[i]->constraint, action->variable, 1.0);
574 lmm_expand(maxmin_system, card_src->bus, action->variable, 1.0);
576 lmm_expand(maxmin_system, card_dst->bus, action->variable, 1.0);
577 lmm_expand(maxmin_system, card_src->constraint, action->variable, 0.0);
578 lmm_expand(maxmin_system, card_dst->constraint, action->variable, 0.0);
581 return (surf_action_t) action;
584 static surf_action_t execute_parallel_task(int workstation_nb,
585 void **workstation_list,
586 double *computation_amount,
587 double *communication_amount,
591 surf_action_workstation_KCCFLN05_t action = NULL;
596 if (parallel_task_network_link_set == NULL) {
597 parallel_task_network_link_set = xbt_dict_new_ext(workstation_nb * workstation_nb * 10);
600 /* Compute the number of affected resources... */
601 for(i=0; i< workstation_nb; i++) {
602 for(j=0; j< workstation_nb; j++) {
603 cpu_KCCFLN05_t card_src = workstation_list[i];
604 cpu_KCCFLN05_t card_dst = workstation_list[j];
605 int route_size = ROUTE(card_src->id, card_dst->id).size;
606 network_link_KCCFLN05_t *route = ROUTE(card_src->id, card_dst->id).links;
608 if(communication_amount[i*workstation_nb+j]>0)
609 for(k=0; k< route_size; k++) {
610 xbt_dict_set(parallel_task_network_link_set, route[k]->name, route[k], NULL);
614 nb_link = xbt_dict_length(parallel_task_network_link_set);
615 xbt_dict_reset(parallel_task_network_link_set);
618 for (i = 0; i<workstation_nb; i++)
619 if(computation_amount[i]>0) nb_host++;
622 if(nb_link + nb_host == 0) /* was workstation_nb... */
625 action = xbt_new0(s_surf_action_workstation_KCCFLN05_t, 1);
626 DEBUG3("Creating a parallel task (%p) with %d cpus and %d links.",
627 action, nb_host, nb_link);
628 action->generic_action.using = 1;
629 action->generic_action.cost = amount;
630 action->generic_action.remains = amount;
631 action->generic_action.max_duration = NO_MAX_DURATION;
632 action->generic_action.start = -1.0;
633 action->generic_action.finish = -1.0;
634 action->generic_action.resource_type =
635 (surf_resource_t) surf_workstation_resource;
636 action->suspended = 0; /* Should be useless because of the
637 calloc but it seems to help valgrind... */
638 action->generic_action.state_set =
639 surf_workstation_resource->common_public->states.running_action_set;
641 xbt_swag_insert(action, action->generic_action.state_set);
645 action->variable = lmm_variable_new(maxmin_system, action, 1.0, -1.0,
648 action->variable = lmm_variable_new(maxmin_system, action, 1.0, action->rate,
651 for (i = 0; i<workstation_nb; i++)
652 if(computation_amount[i]>0)
653 lmm_expand(maxmin_system, ((cpu_KCCFLN05_t) workstation_list[i])->constraint,
654 action->variable, computation_amount[i]);
656 for (i=0; i<workstation_nb; i++) {
657 for(j=0; j< workstation_nb; j++) {
658 cpu_KCCFLN05_t card_src = workstation_list[i];
659 cpu_KCCFLN05_t card_dst = workstation_list[j];
660 int route_size = ROUTE(card_src->id, card_dst->id).size;
661 network_link_KCCFLN05_t *route = ROUTE(card_src->id, card_dst->id).links;
663 for(k=0; k< route_size; k++) {
664 if(communication_amount[i*workstation_nb+j]>0) {
665 lmm_expand_add(maxmin_system, route[k]->constraint,
666 action->variable, communication_amount[i*workstation_nb+j]);
672 return (surf_action_t) action;
675 /* returns an array of network_link_KCCFLN05_t */
676 static const void** get_route(void *src, void *dst) {
677 cpu_KCCFLN05_t card_src = src;
678 cpu_KCCFLN05_t card_dst = dst;
679 route_KCCFLN05_t route = &(ROUTE(card_src->id, card_dst->id));
681 return (const void**) route->links;
684 static int get_route_size(void *src, void *dst) {
685 cpu_KCCFLN05_t card_src = src;
686 cpu_KCCFLN05_t card_dst = dst;
687 route_KCCFLN05_t route = &(ROUTE(card_src->id, card_dst->id));
691 static const char *get_link_name(const void *link) {
692 return ((network_link_KCCFLN05_t) link)->name;
695 static double get_link_bandwidth(const void *link) {
696 return ((network_link_KCCFLN05_t) link)->bw_current;
699 static double get_link_latency(const void *link) {
700 return ((network_link_KCCFLN05_t) link)->lat_current;
703 /**************************************/
704 /*** Resource Creation & Destruction **/
705 /**************************************/
707 static void cpu_free(void *cpu)
709 free(((cpu_KCCFLN05_t) cpu)->name);
710 xbt_dynar_free(&(((cpu_KCCFLN05_t) cpu)->incomming_communications));
711 xbt_dynar_free(&(((cpu_KCCFLN05_t) cpu)->outgoing_communications));
715 static cpu_KCCFLN05_t cpu_new(const char *name, double power_scale,
716 double power_initial,
717 tmgr_trace_t power_trace,
718 e_surf_cpu_state_t state_initial,
719 tmgr_trace_t state_trace,
720 double interference_send,
721 double interference_recv,
722 double interference_send_recv,
723 double max_outgoing_rate)
725 cpu_KCCFLN05_t cpu = xbt_new0(s_cpu_KCCFLN05_t, 1);
727 cpu->resource = (surf_resource_t) surf_workstation_resource;
728 cpu->type = SURF_WORKSTATION_RESOURCE_CPU;
729 cpu->name = xbt_strdup(name);
730 cpu->id = nb_workstation++;
732 cpu->power_scale = power_scale;
733 xbt_assert0(cpu->power_scale > 0, "Power has to be >0");
735 cpu->power_current = power_initial;
738 tmgr_history_add_trace(history, power_trace, 0.0, 0, cpu);
740 cpu->state_current = state_initial;
743 tmgr_history_add_trace(history, state_trace, 0.0, 0, cpu);
745 cpu->interference_send = interference_send;
746 cpu->interference_recv = interference_recv;
747 cpu->interference_send_recv = interference_send_recv;
750 lmm_constraint_new(maxmin_system, cpu,
751 cpu->power_current * cpu->power_scale);
752 if (max_outgoing_rate > 0)
753 cpu->bus = lmm_constraint_new(maxmin_system, cpu, max_outgoing_rate);
755 cpu->incomming_communications =
756 xbt_dynar_new(sizeof(surf_action_workstation_KCCFLN05_t), NULL);
757 cpu->outgoing_communications =
758 xbt_dynar_new(sizeof(surf_action_workstation_KCCFLN05_t), NULL);
760 xbt_dict_set(workstation_set, name, cpu, cpu_free);
765 static void parse_cpu(void)
767 double power_scale = 0.0;
768 double power_initial = 0.0;
769 tmgr_trace_t power_trace = NULL;
770 e_surf_cpu_state_t state_initial = SURF_CPU_OFF;
771 tmgr_trace_t state_trace = NULL;
772 double interference_send = 0.0;
773 double interference_recv = 0.0;
774 double interference_send_recv = 0.0;
775 double max_outgoing_rate = -1.0;
777 surf_parse_get_double(&power_scale, A_surfxml_cpu_power);
778 surf_parse_get_double(&power_initial, A_surfxml_cpu_availability);
779 surf_parse_get_trace(&power_trace, A_surfxml_cpu_availability_file);
781 xbt_assert0((A_surfxml_cpu_state == A_surfxml_cpu_state_ON) ||
782 (A_surfxml_cpu_state == A_surfxml_cpu_state_OFF),
784 if (A_surfxml_cpu_state == A_surfxml_cpu_state_ON)
785 state_initial = SURF_CPU_ON;
786 if (A_surfxml_cpu_state == A_surfxml_cpu_state_OFF)
787 state_initial = SURF_CPU_OFF;
788 surf_parse_get_trace(&state_trace, A_surfxml_cpu_state_file);
790 surf_parse_get_double(&interference_send,
791 A_surfxml_cpu_interference_send);
792 surf_parse_get_double(&interference_recv,
793 A_surfxml_cpu_interference_recv);
794 surf_parse_get_double(&interference_send_recv,
795 A_surfxml_cpu_interference_send_recv);
796 surf_parse_get_double(&max_outgoing_rate,
797 A_surfxml_cpu_max_outgoing_rate);
799 cpu_new(A_surfxml_cpu_name, power_scale, power_initial, power_trace,
800 state_initial, state_trace, interference_send, interference_recv,
801 interference_send_recv, max_outgoing_rate);
804 static void create_routing_table(void)
807 xbt_new0(s_route_KCCFLN05_t, nb_workstation * nb_workstation);
810 static void network_link_free(void *nw_link)
812 free(((network_link_KCCFLN05_t) nw_link)->name);
816 static network_link_KCCFLN05_t network_link_new(char *name,
818 tmgr_trace_t bw_trace,
820 tmgr_trace_t lat_trace,
821 e_surf_network_link_state_t
823 tmgr_trace_t state_trace,
824 e_surf_network_link_sharing_policy_t policy)
826 network_link_KCCFLN05_t nw_link = xbt_new0(s_network_link_KCCFLN05_t, 1);
829 nw_link->resource = (surf_resource_t) surf_workstation_resource;
830 nw_link->type = SURF_WORKSTATION_RESOURCE_LINK;
831 nw_link->name = name;
832 nw_link->bw_current = bw_initial;
835 tmgr_history_add_trace(history, bw_trace, 0.0, 0, nw_link);
836 nw_link->state_current = state_initial;
837 nw_link->lat_current = lat_initial;
840 tmgr_history_add_trace(history, lat_trace, 0.0, 0, nw_link);
842 nw_link->state_event =
843 tmgr_history_add_trace(history, state_trace, 0.0, 0, nw_link);
845 nw_link->constraint =
846 lmm_constraint_new(maxmin_system, nw_link, nw_link->bw_current);
848 if(policy == SURF_NETWORK_LINK_FATPIPE)
849 lmm_constraint_shared(nw_link->constraint);
851 xbt_dict_set(network_link_set, name, nw_link, network_link_free);
856 static void parse_network_link(void)
860 tmgr_trace_t bw_trace;
862 tmgr_trace_t lat_trace;
863 e_surf_network_link_state_t state_initial = SURF_NETWORK_LINK_ON;
864 e_surf_network_link_sharing_policy_t policy_initial = SURF_NETWORK_LINK_SHARED;
865 tmgr_trace_t state_trace;
867 name = xbt_strdup(A_surfxml_network_link_name);
868 surf_parse_get_double(&bw_initial,A_surfxml_network_link_bandwidth);
869 surf_parse_get_trace(&bw_trace, A_surfxml_network_link_bandwidth_file);
870 surf_parse_get_double(&lat_initial,A_surfxml_network_link_latency);
871 surf_parse_get_trace(&lat_trace, A_surfxml_network_link_latency_file);
873 xbt_assert0((A_surfxml_network_link_state==A_surfxml_network_link_state_ON)||
874 (A_surfxml_network_link_state==A_surfxml_network_link_state_OFF),
876 if (A_surfxml_network_link_state==A_surfxml_network_link_state_ON)
877 state_initial = SURF_NETWORK_LINK_ON;
878 else if (A_surfxml_network_link_state==A_surfxml_network_link_state_OFF)
879 state_initial = SURF_NETWORK_LINK_OFF;
881 if (A_surfxml_network_link_sharing_policy==A_surfxml_network_link_sharing_policy_SHARED)
882 policy_initial = SURF_NETWORK_LINK_SHARED;
883 else if (A_surfxml_network_link_sharing_policy==A_surfxml_network_link_sharing_policy_FATPIPE)
884 policy_initial = SURF_NETWORK_LINK_FATPIPE;
886 surf_parse_get_trace(&state_trace,A_surfxml_network_link_state_file);
888 network_link_new(name, bw_initial, bw_trace,
889 lat_initial, lat_trace, state_initial, state_trace,
893 static void route_new(int src_id, int dst_id, network_link_KCCFLN05_t *link_list, int nb_link,
894 double impact_on_src, double impact_on_dst,
895 double impact_on_src_with_other_recv,
896 double impact_on_dst_with_other_send)
898 route_KCCFLN05_t route = &(ROUTE(src_id, dst_id));
900 route->size = nb_link;
901 route->links = link_list = xbt_realloc(link_list, sizeof(network_link_KCCFLN05_t) * nb_link);
902 route->impact_on_src = impact_on_src;
903 route->impact_on_dst = impact_on_src;
904 route->impact_on_src_with_other_recv = impact_on_src_with_other_recv;
905 route->impact_on_dst_with_other_send = impact_on_dst_with_other_send;
909 static int link_list_capacity;
910 static network_link_KCCFLN05_t *link_list = NULL;
911 static int src_id = -1;
912 static int dst_id = -1;
913 static double impact_on_src;
914 static double impact_on_dst;
915 static double impact_on_src_with_other_recv;
916 static double impact_on_dst_with_other_send;
918 static void parse_route_set_endpoints(void)
920 src_id = ((cpu_KCCFLN05_t) name_service(A_surfxml_route_src))->id;
921 dst_id = ((cpu_KCCFLN05_t) name_service(A_surfxml_route_dst))->id;
922 surf_parse_get_double(&impact_on_src, A_surfxml_route_impact_on_src);
923 surf_parse_get_double(&impact_on_dst, A_surfxml_route_impact_on_dst);
924 surf_parse_get_double(&impact_on_src_with_other_recv,
925 A_surfxml_route_impact_on_src_with_other_recv);
926 surf_parse_get_double(&impact_on_dst_with_other_send,
927 A_surfxml_route_impact_on_dst_with_other_send);
930 link_list_capacity = 20;
931 link_list = xbt_new(network_link_KCCFLN05_t, link_list_capacity);
934 static void parse_route_elem(void)
937 if (nb_link == link_list_capacity) {
938 link_list_capacity *= 2;
939 link_list = xbt_realloc(link_list, (link_list_capacity) * sizeof(network_link_KCCFLN05_t));
942 link_list[nb_link++] = xbt_dict_get(network_link_set, A_surfxml_route_element_name);
944 RETHROW1("Link %s not found (dict raised this exception: %s)",A_surfxml_route_element_name);
948 static void parse_route_set_route(void)
950 route_new(src_id, dst_id, link_list, nb_link, impact_on_src,
951 impact_on_dst, impact_on_src_with_other_recv,
952 impact_on_dst_with_other_send);
955 static void parse_file(const char *file)
959 /* Figuring out the cpus */
960 surf_parse_reset_parser();
961 ETag_surfxml_cpu_fun = parse_cpu;
962 surf_parse_open(file);
963 xbt_assert1((!surf_parse()), "Parse error in %s", file);
966 create_routing_table();
968 /* Figuring out the network links */
969 surf_parse_reset_parser();
970 ETag_surfxml_network_link_fun = parse_network_link;
971 surf_parse_open(file);
972 xbt_assert1((!surf_parse()), "Parse error in %s", file);
975 /* Building the routes */
976 surf_parse_reset_parser();
977 STag_surfxml_route_fun = parse_route_set_endpoints;
978 ETag_surfxml_route_element_fun = parse_route_elem;
979 ETag_surfxml_route_fun = parse_route_set_route;
980 surf_parse_open(file);
981 xbt_assert1((!surf_parse()), "Parse error in %s", file);
984 /* Adding loopback if needed */
985 for (i = 0; i < nb_workstation; i++)
986 if(!ROUTE(i,i).size) {
988 loopback = network_link_new(xbt_strdup("__MSG_loopback__"),
989 498000000, NULL, 0.000015, NULL,
990 SURF_NETWORK_LINK_ON, NULL,
991 SURF_NETWORK_LINK_FATPIPE);
993 ROUTE(i,i).links = xbt_new0(network_link_KCCFLN05_t, 1);
994 ROUTE(i,i).links[0] = loopback;
999 /**************************************/
1000 /********* Module creation ***********/
1001 /**************************************/
1003 static void resource_init_internal(void)
1005 s_surf_action_t action;
1007 surf_workstation_resource = xbt_new0(s_surf_workstation_resource_t, 1);
1009 surf_workstation_resource->common_private =
1010 xbt_new0(s_surf_resource_private_t, 1);
1011 surf_workstation_resource->common_public =
1012 xbt_new0(s_surf_resource_public_t, 1);
1013 surf_workstation_resource->extension_public =
1014 xbt_new0(s_surf_workstation_resource_extension_public_t, 1);
1016 surf_workstation_resource->common_public->states.ready_action_set =
1017 xbt_swag_new(xbt_swag_offset(action, state_hookup));
1018 surf_workstation_resource->common_public->states.running_action_set =
1019 xbt_swag_new(xbt_swag_offset(action, state_hookup));
1020 surf_workstation_resource->common_public->states.failed_action_set =
1021 xbt_swag_new(xbt_swag_offset(action, state_hookup));
1022 surf_workstation_resource->common_public->states.done_action_set =
1023 xbt_swag_new(xbt_swag_offset(action, state_hookup));
1025 surf_workstation_resource->common_public->name_service = name_service;
1026 surf_workstation_resource->common_public->get_resource_name = get_resource_name;
1027 surf_workstation_resource->common_public->action_get_state = surf_action_get_state;
1028 surf_workstation_resource->common_public->action_get_start_time =
1029 surf_action_get_start_time;
1030 surf_workstation_resource->common_public->action_get_finish_time =
1031 surf_action_get_finish_time;
1032 surf_workstation_resource->common_public->action_use = action_use;
1033 surf_workstation_resource->common_public->action_free = action_free;
1034 surf_workstation_resource->common_public->action_cancel = action_cancel;
1035 surf_workstation_resource->common_public->action_recycle = action_recycle;
1036 surf_workstation_resource->common_public->action_change_state = surf_action_change_state;
1037 surf_workstation_resource->common_public->action_set_data = surf_action_set_data;
1038 surf_workstation_resource->common_public->suspend = action_suspend;
1039 surf_workstation_resource->common_public->resume = action_resume;
1040 surf_workstation_resource->common_public->is_suspended = action_is_suspended;
1041 surf_workstation_resource->common_public->set_max_duration = action_set_max_duration;
1042 surf_workstation_resource->common_public->set_priority = action_set_priority;
1043 surf_workstation_resource->common_public->name = "Workstation KCCFLN05";
1045 surf_workstation_resource->common_private->resource_used = resource_used;
1046 surf_workstation_resource->common_private->share_resources = share_resources;
1047 surf_workstation_resource->common_private->update_actions_state = update_actions_state;
1048 surf_workstation_resource->common_private->update_resource_state = update_resource_state;
1049 surf_workstation_resource->common_private->finalize = finalize;
1051 surf_workstation_resource->extension_public->execute = execute;
1052 surf_workstation_resource->extension_public->sleep = action_sleep;
1053 surf_workstation_resource->extension_public->get_state = resource_get_state;
1054 surf_workstation_resource->extension_public->get_speed = get_speed;
1055 surf_workstation_resource->extension_public->get_available_speed = get_available_speed;
1056 surf_workstation_resource->extension_public->communicate = communicate;
1057 surf_workstation_resource->extension_public->execute_parallel_task = execute_parallel_task;
1058 surf_workstation_resource->extension_public->get_route = get_route;
1059 surf_workstation_resource->extension_public->get_route_size = get_route_size;
1060 surf_workstation_resource->extension_public->get_link_name = get_link_name;
1061 surf_workstation_resource->extension_public->get_link_bandwidth = get_link_bandwidth;
1062 surf_workstation_resource->extension_public->get_link_latency = get_link_latency;
1064 workstation_set = xbt_dict_new();
1065 network_link_set = xbt_dict_new();
1067 xbt_assert0(maxmin_system, "surf_init has to be called first!");
1070 /**************************************/
1071 /*************** Generic **************/
1072 /**************************************/
1073 void surf_workstation_resource_init_KCCFLN05(const char *filename)
1075 xbt_assert0(!surf_cpu_resource, "CPU resource type already defined");
1076 xbt_assert0(!surf_network_resource, "network resource type already defined");
1077 resource_init_internal();
1078 parse_file(filename);
1080 xbt_dynar_push(resource_list, &surf_workstation_resource);
1083 void surf_workstation_resource_init_KCCFLN05_proportional(const char *filename)
1085 xbt_assert0(!surf_cpu_resource, "CPU resource type already defined");
1086 xbt_assert0(!surf_network_resource, "network resource type already defined");
1087 resource_init_internal();
1088 parse_file(filename);
1090 surf_workstation_resource->common_public->name = "Workstation KCCFLN05 (proportional)";
1092 xbt_dynar_push(resource_list, &surf_workstation_resource);
1095 void surf_workstation_resource_init_KCCFLN05_Vegas(const char *filename)
1097 xbt_assert0(!surf_cpu_resource, "CPU resource type already defined");
1098 xbt_assert0(!surf_network_resource, "network resource type already defined");
1099 resource_init_internal();
1100 parse_file(filename);
1102 lmm_set_default_protocol_functions(func_vegas_f, func_vegas_fp, func_vegas_fpi, func_vegas_fpip);
1104 surf_workstation_resource->common_public->name = "Workstation KCCFLN05 (Vegas)";
1105 use_lagrange_solver=1;
1106 xbt_dynar_push(resource_list, &surf_workstation_resource);
1109 void surf_workstation_resource_init_KCCFLN05_Reno(const char *filename)
1111 xbt_assert0(!surf_cpu_resource, "CPU resource type already defined");
1112 xbt_assert0(!surf_network_resource, "network resource type already defined");
1113 resource_init_internal();
1114 parse_file(filename);
1116 lmm_set_default_protocol_functions(func_reno_f, func_reno_fp, func_reno_fpi, func_reno_fpip);
1118 surf_workstation_resource->common_public->name = "Workstation KCCFLN05 (Reno)";
1119 use_lagrange_solver=1;
1120 xbt_dynar_push(resource_list, &surf_workstation_resource);