3 /* Copyright (c) 2005 Arnaud Legrand. All rights reserved. */
5 /* This program is free software; you can redistribute it and/or modify it
6 * under the terms of the license (GNU LGPL) which comes with this package. */
10 #include "workstation_KCCFLN05_private.h"
12 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_workstation, surf,
13 "Logging specific to the SURF workstation module (KCCFLN05)");
15 static int nb_workstation = 0;
16 static s_route_KCCFLN05_t *routing_table = NULL;
17 #define ROUTE(i,j) routing_table[(i)+(j)*nb_workstation]
18 static network_link_KCCFLN05_t loopback = NULL;
19 static xbt_dict_t parallel_task_network_link_set = NULL;
20 //added to work with GTNETS
21 static xbt_dict_t router_set = NULL;
23 /*xbt_dict_t network_link_set = NULL;*/
26 /* convenient function */
27 static void __update_cpu_usage(cpu_KCCFLN05_t cpu)
30 surf_action_workstation_KCCFLN05_t action = NULL;
31 if ((!xbt_dynar_length(cpu->incomming_communications)) &&
32 (!xbt_dynar_length(cpu->outgoing_communications))) {
33 /* No communications */
34 lmm_update_constraint_bound(maxmin_system, cpu->constraint,
35 cpu->power_current * cpu->power_scale);
36 } else if ((!xbt_dynar_length(cpu->incomming_communications))
37 && (xbt_dynar_length(cpu->outgoing_communications))) {
39 lmm_update_constraint_bound(maxmin_system, cpu->constraint,
40 cpu->power_current * cpu->power_scale *
41 cpu->interference_send);
42 xbt_dynar_foreach(cpu->outgoing_communications, cpt, action)
43 lmm_elem_set_value(maxmin_system,cpu->constraint,action->variable,
44 cpu->power_current * cpu->power_scale *
45 ROUTE(action->src->id, action->dst->id).impact_on_src
47 } else if ((xbt_dynar_length(cpu->incomming_communications)) &&
48 (!xbt_dynar_length(cpu->outgoing_communications))) {
50 lmm_update_constraint_bound(maxmin_system, cpu->constraint,
51 cpu->power_current * cpu->power_scale *
52 cpu->interference_recv);
53 xbt_dynar_foreach(cpu->incomming_communications, cpt, action)
54 lmm_elem_set_value(maxmin_system,cpu->constraint,action->variable,
55 cpu->power_current * cpu->power_scale *
56 ROUTE(action->src->id, action->dst->id).impact_on_dst
59 /* Emission & Reception */
60 lmm_update_constraint_bound(maxmin_system, cpu->constraint,
61 cpu->power_current * cpu->power_scale *
62 cpu->interference_send_recv);
63 xbt_dynar_foreach(cpu->outgoing_communications, cpt, action)
64 lmm_elem_set_value(maxmin_system,cpu->constraint,action->variable,
65 cpu->power_current * cpu->power_scale *
66 ROUTE(action->src->id, action->dst->id).impact_on_src_with_other_recv
68 xbt_dynar_foreach(cpu->incomming_communications, cpt, action)
69 lmm_elem_set_value(maxmin_system,cpu->constraint,action->variable,
70 cpu->power_current * cpu->power_scale *
71 ROUTE(action->src->id, action->dst->id).impact_on_dst_with_other_send
76 /**************************************/
77 /******* Resource Public **********/
78 /**************************************/
80 static void *name_service(const char *name)
86 res = xbt_dict_get_or_null(workstation_set, name);
88 if (e.category != not_found_error)
90 WARN1("Host '%s' not found, verifing if it is a router", name);
97 static const char *get_resource_name(void *resource_id)
99 /* We can freely cast as a cpu_KCCFLN05_t because it has the same
100 prefix as network_link_KCCFLN05_t. However, only cpu_KCCFLN05_t
101 will theoretically be given as an argument here. */
102 return ((cpu_KCCFLN05_t) resource_id)->name;
105 /* action_get_state is inherited from the surf module */
107 static void action_use(surf_action_t action)
113 static int action_free(surf_action_t action)
116 surf_action_t act = NULL;
117 cpu_KCCFLN05_t src = ((surf_action_workstation_KCCFLN05_t) action)->src;
118 cpu_KCCFLN05_t dst = ((surf_action_workstation_KCCFLN05_t) action)->dst;
121 if (!action->using) {
122 xbt_swag_remove(action, action->state_set);
123 if (((surf_action_workstation_KCCFLN05_t) action)->variable)
124 lmm_variable_free(maxmin_system,
125 ((surf_action_workstation_KCCFLN05_t) action)->
128 xbt_dynar_foreach(src->outgoing_communications, cpt, act)
130 xbt_dynar_remove_at(src->outgoing_communications, cpt, &act);
135 xbt_dynar_foreach(dst->incomming_communications, cpt, act)
137 xbt_dynar_remove_at(dst->incomming_communications, cpt, &act);
141 if(src && (!xbt_dynar_length(src->outgoing_communications)))
142 __update_cpu_usage(src);
143 if(dst && (!xbt_dynar_length(dst->incomming_communications)))
144 __update_cpu_usage(dst);
152 static void action_cancel(surf_action_t action)
154 surf_action_change_state(action, SURF_ACTION_FAILED);
158 static void action_recycle(surf_action_t action)
164 /* action_change_state is inherited from the surf module */
165 /* action_set_data is inherited from the surf module */
167 static void action_suspend(surf_action_t action)
169 XBT_IN1("(%p))",action);
170 if(((surf_action_workstation_KCCFLN05_t) action)->suspended != 2) {
171 ((surf_action_workstation_KCCFLN05_t) action)->suspended = 1;
172 lmm_update_variable_weight(maxmin_system,
173 ((surf_action_workstation_KCCFLN05_t)
174 action)->variable, 0.0);
179 static void action_resume(surf_action_t action)
181 XBT_IN1("(%p)",action);
182 if(((surf_action_workstation_KCCFLN05_t) action)->suspended !=2) {
183 if(((surf_action_workstation_KCCFLN05_t)action)->lat_current==0.0)
184 lmm_update_variable_weight(maxmin_system,
185 ((surf_action_workstation_KCCFLN05_t)
186 action)->variable, 1.0);
188 lmm_update_variable_weight(maxmin_system,
189 ((surf_action_workstation_KCCFLN05_t) action)->variable,
190 ((surf_action_workstation_KCCFLN05_t) action)->lat_current);
192 ((surf_action_workstation_KCCFLN05_t) action)->suspended = 0;
197 static int action_is_suspended(surf_action_t action)
199 return (((surf_action_workstation_KCCFLN05_t) action)->suspended==1);
202 static void action_set_max_duration(surf_action_t action, double duration)
203 { /* FIXME: should inherit */
204 XBT_IN2("(%p,%g)",action,duration);
205 action->max_duration = duration;
210 static void action_set_priority(surf_action_t action, double priority)
211 { /* FIXME: should inherit */
212 XBT_IN2("(%p,%g)",action,priority);
213 action->priority = priority;
217 /**************************************/
218 /******* Resource Private **********/
219 /**************************************/
221 static int resource_used(void *resource_id)
223 /* We can freely cast as a network_link_KCCFLN05_t because it has
224 the same prefix as cpu_KCCFLN05_t */
225 if(((cpu_KCCFLN05_t) resource_id)->type == SURF_WORKSTATION_RESOURCE_CPU)
226 return (lmm_constraint_used(maxmin_system,
227 ((cpu_KCCFLN05_t) resource_id)->
229 ((((cpu_KCCFLN05_t) resource_id)->bus)?
230 lmm_constraint_used(maxmin_system,
231 ((cpu_KCCFLN05_t) resource_id)->
234 return lmm_constraint_used(maxmin_system,
235 ((network_link_KCCFLN05_t) resource_id)->
240 static double share_resources(double now)
242 s_surf_action_workstation_KCCFLN05_t s_action;
243 surf_action_workstation_KCCFLN05_t action = NULL;
245 xbt_swag_t running_actions = surf_workstation_resource->common_public->states.running_action_set;
246 double min = generic_maxmin_share_resources(running_actions,
247 xbt_swag_offset(s_action, variable));
249 xbt_swag_foreach(action, running_actions) {
250 if(action->latency>0) {
252 min = action->latency;
253 DEBUG3("Updating min (value) with %p (start %f): %f",action,
254 action->generic_action.start, min);
256 else if (action->latency<min) {
257 min = action->latency;
258 DEBUG3("Updating min (latency) with %p (start %f): %f",action,
259 action->generic_action.start, min);
264 DEBUG1("min value : %f",min);
269 static void update_actions_state(double now, double delta)
272 surf_action_workstation_KCCFLN05_t action = NULL;
273 surf_action_workstation_KCCFLN05_t next_action = NULL;
274 xbt_swag_t running_actions =
275 surf_workstation_resource->common_public->states.running_action_set;
277 xbt_swag_foreach_safe(action, next_action, running_actions) {
279 if (action->latency > 0) {
280 if (action->latency > deltap) {
281 double_update(&(action->latency), deltap);
284 double_update(&(deltap), action->latency);
285 action->latency = 0.0;
287 if ((action->latency == 0.0) && (action->suspended==0)) {
288 if((action)->lat_current==0.0)
289 lmm_update_variable_weight(maxmin_system,action->variable, 1.0);
291 lmm_update_variable_weight(maxmin_system, action->variable,
292 action->lat_current);
295 DEBUG3("Action (%p) : remains (%g) updated by %g.",
296 action, action->generic_action.remains,
297 lmm_variable_getvalue(action->variable) * deltap);
298 double_update(&(action->generic_action.remains),
299 lmm_variable_getvalue(action->variable) * deltap);
301 if (action->generic_action.max_duration != NO_MAX_DURATION)
302 double_update(&(action->generic_action.max_duration), delta);
304 /* if(action->generic_action.remains<.00001) action->generic_action.remains=0; */
306 if ((action->generic_action.remains <= 0) &&
307 (lmm_get_variable_weight(action->variable)>0)) {
308 action->generic_action.finish = surf_get_clock();
309 surf_action_change_state((surf_action_t) action, SURF_ACTION_DONE);
310 } else if ((action->generic_action.max_duration != NO_MAX_DURATION) &&
311 (action->generic_action.max_duration <= 0)) {
312 action->generic_action.finish = surf_get_clock();
313 surf_action_change_state((surf_action_t) action, SURF_ACTION_DONE);
314 } else { /* 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);
323 if(((((network_link_KCCFLN05_t)constraint_id)->type==
324 SURF_WORKSTATION_RESOURCE_LINK) &&
325 (((network_link_KCCFLN05_t)constraint_id)->state_current==
326 SURF_NETWORK_LINK_OFF)) ||
327 ((((cpu_KCCFLN05_t)constraint_id)->type==
328 SURF_WORKSTATION_RESOURCE_CPU) &&
329 (((cpu_KCCFLN05_t)constraint_id)->state_current==
331 action->generic_action.finish = surf_get_clock();
332 surf_action_change_state((surf_action_t) action, SURF_ACTION_FAILED);
341 static void update_resource_state(void *id,
342 tmgr_trace_event_t event_type,
345 cpu_KCCFLN05_t cpu = id;
346 network_link_KCCFLN05_t nw_link = id ;
348 if(nw_link->type == SURF_WORKSTATION_RESOURCE_LINK) {
349 if (event_type == nw_link->bw_event) {
350 nw_link->bw_current = value;
351 lmm_update_constraint_bound(maxmin_system, nw_link->constraint,
352 nw_link->bw_current);
353 } else if (event_type == nw_link->lat_event) {
354 double delta = value - nw_link->lat_current;
355 lmm_variable_t var = NULL;
356 surf_action_workstation_KCCFLN05_t action = NULL;
358 nw_link->lat_current = value;
359 while (lmm_get_var_from_cnst(maxmin_system, nw_link->constraint, &var)) {
360 action = lmm_variable_id(var);
361 action->lat_current += delta;
363 lmm_update_variable_bound(maxmin_system, action->variable,
364 SG_TCP_CTE_GAMMA / (2.0 * action->lat_current));
366 lmm_update_variable_bound(maxmin_system, action->variable,
367 min(action->rate,SG_TCP_CTE_GAMMA / (2.0 * action->lat_current)));
368 if(action->suspended==0)
369 lmm_update_variable_weight(maxmin_system, action->variable,
370 action->lat_current);
371 lmm_update_variable_latency(maxmin_system, action->variable, delta);
375 } else if (event_type == nw_link->state_event) {
377 nw_link->state_current = SURF_NETWORK_LINK_ON;
379 nw_link->state_current = SURF_NETWORK_LINK_OFF;
381 CRITICAL0("Unknown event ! \n");
385 } else if(cpu->type == SURF_WORKSTATION_RESOURCE_CPU) {
386 if (event_type == cpu->power_event) {
387 cpu->power_current = value;
388 __update_cpu_usage(cpu);
389 } else if (event_type == cpu->state_event) {
391 cpu->state_current = SURF_CPU_ON;
393 cpu->state_current = SURF_CPU_OFF;
395 CRITICAL0("Unknown event ! \n");
405 static void finalize(void)
409 xbt_dict_free(&network_link_set);
410 xbt_dict_free(&workstation_set);
411 xbt_dict_free(&router_set);
412 if (parallel_task_network_link_set != NULL) {
413 xbt_dict_free(¶llel_task_network_link_set);
415 xbt_swag_free(surf_workstation_resource->common_public->states.
417 xbt_swag_free(surf_workstation_resource->common_public->states.
419 xbt_swag_free(surf_workstation_resource->common_public->states.
421 xbt_swag_free(surf_workstation_resource->common_public->states.
424 free(surf_workstation_resource->common_public);
425 free(surf_workstation_resource->common_private);
426 free(surf_workstation_resource->extension_public);
428 free(surf_workstation_resource);
429 surf_workstation_resource = NULL;
431 for (i = 0; i < nb_workstation; i++)
432 for (j = 0; j < nb_workstation; j++)
433 free(ROUTE(i, j).links);
435 routing_table = NULL;
439 lmm_system_free(maxmin_system);
440 maxmin_system = NULL;
444 /**************************************/
445 /******* Resource Private **********/
446 /**************************************/
448 static surf_action_t execute(void *cpu, double size)
450 surf_action_workstation_KCCFLN05_t action = NULL;
451 cpu_KCCFLN05_t CPU = cpu;
453 XBT_IN2("(%s,%g)",CPU->name,size);
454 action = xbt_new0(s_surf_action_workstation_KCCFLN05_t, 1);
456 action->generic_action.using = 1;
457 action->generic_action.cost = size;
458 action->generic_action.remains = size;
459 action->generic_action.priority = 1.0;
460 action->generic_action.max_duration = NO_MAX_DURATION;
461 action->generic_action.start = surf_get_clock();
462 action->generic_action.finish = -1.0;
463 action->generic_action.resource_type =
464 (surf_resource_t) surf_workstation_resource;
465 action->suspended = 0;
467 if (CPU->state_current == SURF_CPU_ON)
468 action->generic_action.state_set =
469 surf_workstation_resource->common_public->states.running_action_set;
471 action->generic_action.state_set =
472 surf_workstation_resource->common_public->states.failed_action_set;
473 xbt_swag_insert(action, action->generic_action.state_set);
475 action->variable = lmm_variable_new(maxmin_system, action,
476 action->generic_action.priority, -1.0, 1);
477 lmm_expand(maxmin_system, CPU->constraint, action->variable,
480 return (surf_action_t) action;
483 static surf_action_t action_sleep(void *cpu, double duration)
485 surf_action_workstation_KCCFLN05_t action = NULL;
487 XBT_IN2("(%s,%g)",((cpu_KCCFLN05_t)cpu)->name,duration);
489 action = (surf_action_workstation_KCCFLN05_t) execute(cpu, 1.0);
490 action->generic_action.max_duration = duration;
491 action->suspended = 2;
492 lmm_update_variable_weight(maxmin_system, action->variable, 0.0);
495 return (surf_action_t) action;
498 static e_surf_cpu_state_t resource_get_state(void *cpu)
500 return ((cpu_KCCFLN05_t) cpu)->state_current;
503 static double get_speed(void *cpu, double load)
505 return load*(((cpu_KCCFLN05_t) cpu)->power_scale);
508 static double get_available_speed(void *cpu)
510 return ((cpu_KCCFLN05_t) cpu)->power_current;
514 static surf_action_t communicate(void *src, void *dst, double size, double rate)
516 surf_action_workstation_KCCFLN05_t action = NULL;
517 cpu_KCCFLN05_t card_src = src;
518 cpu_KCCFLN05_t card_dst = dst;
519 route_KCCFLN05_t route = &(ROUTE(card_src->id, card_dst->id));
520 int route_size = route->size;
523 XBT_IN4("(%s,%s,%g,%g)",card_src->name,card_dst->name,size,rate);
524 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);
526 action = xbt_new0(s_surf_action_workstation_KCCFLN05_t, 1);
528 action->generic_action.using = 1;
529 action->generic_action.cost = size;
530 action->generic_action.remains = size;
531 action->generic_action.max_duration = NO_MAX_DURATION;
532 action->generic_action.start = surf_get_clock();
533 action->generic_action.finish = -1.0;
536 action->generic_action.resource_type =
537 (surf_resource_t) surf_workstation_resource;
538 action->suspended = 0; /* Should be useless because of the
539 calloc but it seems to help valgrind... */
540 action->generic_action.state_set =
541 surf_workstation_resource->common_public->states.running_action_set;
543 xbt_dynar_push(card_src->outgoing_communications, &action);
544 xbt_dynar_push(card_dst->incomming_communications, &action);
546 xbt_swag_insert(action, action->generic_action.state_set);
549 action->latency = 0.0;
550 for (i = 0; i < route_size; i++)
551 action->latency += route->links[i]->lat_current;
552 action->lat_current = action->latency;
554 if(action->latency>0)
555 action->variable = lmm_variable_new(maxmin_system, action, 0.0, -1.0,
556 route_size+4); /* +1 for the src bus
559 +1 for the dst cpu */
561 action->variable = lmm_variable_new(maxmin_system, action, 1.0, -1.0,
565 if(action->lat_current>0)
566 lmm_update_variable_bound(maxmin_system, action->variable,
567 SG_TCP_CTE_GAMMA / (2.0 * action->lat_current));
569 lmm_update_variable_bound(maxmin_system, action->variable, -1.0);
571 if(action->lat_current>0)
572 lmm_update_variable_bound(maxmin_system, action->variable,
573 min(action->rate,SG_TCP_CTE_GAMMA / (2.0 * action->lat_current)));
575 lmm_update_variable_bound(maxmin_system, action->variable, action->rate);
578 lmm_update_variable_latency(maxmin_system, action->variable, action->latency);
580 for (i = 0; i < route_size; i++)
581 lmm_expand(maxmin_system, route->links[i]->constraint, action->variable, 1.0);
583 lmm_expand(maxmin_system, card_src->bus, action->variable, 1.0);
585 lmm_expand(maxmin_system, card_dst->bus, action->variable, 1.0);
586 lmm_expand(maxmin_system, card_src->constraint, action->variable, 0.0);
587 lmm_expand(maxmin_system, card_dst->constraint, action->variable, 0.0);
590 return (surf_action_t) action;
593 static surf_action_t execute_parallel_task(int workstation_nb,
594 void **workstation_list,
595 double *computation_amount,
596 double *communication_amount,
600 surf_action_workstation_KCCFLN05_t action = NULL;
605 if (parallel_task_network_link_set == NULL) {
606 parallel_task_network_link_set = xbt_dict_new_ext(workstation_nb * workstation_nb * 10);
609 /* Compute the number of affected resources... */
610 for(i=0; i< workstation_nb; i++) {
611 for(j=0; j< workstation_nb; j++) {
612 cpu_KCCFLN05_t card_src = workstation_list[i];
613 cpu_KCCFLN05_t card_dst = workstation_list[j];
614 int route_size = ROUTE(card_src->id, card_dst->id).size;
615 network_link_KCCFLN05_t *route = ROUTE(card_src->id, card_dst->id).links;
617 if(communication_amount[i*workstation_nb+j]>0)
618 for(k=0; k< route_size; k++) {
619 xbt_dict_set(parallel_task_network_link_set, route[k]->name, route[k], NULL);
623 nb_link = xbt_dict_length(parallel_task_network_link_set);
624 xbt_dict_reset(parallel_task_network_link_set);
627 for (i = 0; i<workstation_nb; i++)
628 if(computation_amount[i]>0) nb_host++;
631 if(nb_link + nb_host == 0) /* was workstation_nb... */
634 action = xbt_new0(s_surf_action_workstation_KCCFLN05_t, 1);
635 DEBUG3("Creating a parallel task (%p) with %d cpus and %d links.",
636 action, nb_host, nb_link);
637 action->generic_action.using = 1;
638 action->generic_action.cost = amount;
639 action->generic_action.remains = amount;
640 action->generic_action.max_duration = NO_MAX_DURATION;
641 action->generic_action.start = -1.0;
642 action->generic_action.finish = -1.0;
643 action->generic_action.resource_type =
644 (surf_resource_t) surf_workstation_resource;
645 action->suspended = 0; /* Should be useless because of the
646 calloc but it seems to help valgrind... */
647 action->generic_action.state_set =
648 surf_workstation_resource->common_public->states.running_action_set;
650 xbt_swag_insert(action, action->generic_action.state_set);
654 action->variable = lmm_variable_new(maxmin_system, action, 1.0, -1.0,
657 action->variable = lmm_variable_new(maxmin_system, action, 1.0, action->rate,
660 for (i = 0; i<workstation_nb; i++)
661 if(computation_amount[i]>0)
662 lmm_expand(maxmin_system, ((cpu_KCCFLN05_t) workstation_list[i])->constraint,
663 action->variable, computation_amount[i]);
665 for (i=0; i<workstation_nb; i++) {
666 for(j=0; j< workstation_nb; j++) {
667 cpu_KCCFLN05_t card_src = workstation_list[i];
668 cpu_KCCFLN05_t card_dst = workstation_list[j];
669 int route_size = ROUTE(card_src->id, card_dst->id).size;
670 network_link_KCCFLN05_t *route = ROUTE(card_src->id, card_dst->id).links;
672 for(k=0; k< route_size; k++) {
673 if(communication_amount[i*workstation_nb+j]>0) {
674 lmm_expand_add(maxmin_system, route[k]->constraint,
675 action->variable, communication_amount[i*workstation_nb+j]);
681 return (surf_action_t) action;
684 /* returns an array of network_link_KCCFLN05_t */
685 static const void** get_route(void *src, void *dst) {
686 cpu_KCCFLN05_t card_src = src;
687 cpu_KCCFLN05_t card_dst = dst;
688 route_KCCFLN05_t route = &(ROUTE(card_src->id, card_dst->id));
690 return (const void**) route->links;
693 static int get_route_size(void *src, void *dst) {
694 cpu_KCCFLN05_t card_src = src;
695 cpu_KCCFLN05_t card_dst = dst;
696 route_KCCFLN05_t route = &(ROUTE(card_src->id, card_dst->id));
700 static const char *get_link_name(const void *link) {
701 return ((network_link_KCCFLN05_t) link)->name;
704 static double get_link_bandwidth(const void *link) {
705 return ((network_link_KCCFLN05_t) link)->bw_current;
708 static double get_link_latency(const void *link) {
709 return ((network_link_KCCFLN05_t) link)->lat_current;
712 /**************************************/
713 /*** Resource Creation & Destruction **/
714 /**************************************/
717 static void router_free(void *router)
719 free( ((router_KCCFLN05_t) router)->name );
722 static void router_new(const char *name)
724 static unsigned int nb_routers = 0;
726 INFO1("Creating a router %s", name);
728 router_KCCFLN05_t router;
729 router = xbt_new0(s_router_KCCFLN05_t, 1);
731 router->name = xbt_strdup(name);
732 router->id = nb_routers++;
733 xbt_dict_set(router_set, name, router, router_free);
736 static void parse_routers(void)
738 //add a dumb router just to be GTNETS compatible
739 router_new(A_surfxml_router_name);
742 static void cpu_free(void *cpu)
744 free(((cpu_KCCFLN05_t) cpu)->name);
745 xbt_dynar_free(&(((cpu_KCCFLN05_t) cpu)->incomming_communications));
746 xbt_dynar_free(&(((cpu_KCCFLN05_t) cpu)->outgoing_communications));
750 static cpu_KCCFLN05_t cpu_new(const char *name, double power_scale,
751 double power_initial,
752 tmgr_trace_t power_trace,
753 e_surf_cpu_state_t state_initial,
754 tmgr_trace_t state_trace,
755 double interference_send,
756 double interference_recv,
757 double interference_send_recv,
758 double max_outgoing_rate)
760 cpu_KCCFLN05_t cpu = xbt_new0(s_cpu_KCCFLN05_t, 1);
762 cpu->resource = (surf_resource_t) surf_workstation_resource;
763 cpu->type = SURF_WORKSTATION_RESOURCE_CPU;
764 cpu->name = xbt_strdup(name);
765 cpu->id = nb_workstation++;
767 cpu->power_scale = power_scale;
768 xbt_assert0(cpu->power_scale > 0, "Power has to be >0");
770 cpu->power_current = power_initial;
773 tmgr_history_add_trace(history, power_trace, 0.0, 0, cpu);
775 cpu->state_current = state_initial;
778 tmgr_history_add_trace(history, state_trace, 0.0, 0, cpu);
780 cpu->interference_send = interference_send;
781 cpu->interference_recv = interference_recv;
782 cpu->interference_send_recv = interference_send_recv;
785 lmm_constraint_new(maxmin_system, cpu,
786 cpu->power_current * cpu->power_scale);
787 if (max_outgoing_rate > 0)
788 cpu->bus = lmm_constraint_new(maxmin_system, cpu, max_outgoing_rate);
790 cpu->incomming_communications =
791 xbt_dynar_new(sizeof(surf_action_workstation_KCCFLN05_t), NULL);
792 cpu->outgoing_communications =
793 xbt_dynar_new(sizeof(surf_action_workstation_KCCFLN05_t), NULL);
795 xbt_dict_set(workstation_set, name, cpu, cpu_free);
800 static void parse_cpu(void)
802 double power_scale = 0.0;
803 double power_initial = 0.0;
804 tmgr_trace_t power_trace = NULL;
805 e_surf_cpu_state_t state_initial = SURF_CPU_OFF;
806 tmgr_trace_t state_trace = NULL;
807 double interference_send = 0.0;
808 double interference_recv = 0.0;
809 double interference_send_recv = 0.0;
810 double max_outgoing_rate = -1.0;
812 surf_parse_get_double(&power_scale, A_surfxml_cpu_power);
813 surf_parse_get_double(&power_initial, A_surfxml_cpu_availability);
814 surf_parse_get_trace(&power_trace, A_surfxml_cpu_availability_file);
816 xbt_assert0((A_surfxml_cpu_state == A_surfxml_cpu_state_ON) ||
817 (A_surfxml_cpu_state == A_surfxml_cpu_state_OFF),
819 if (A_surfxml_cpu_state == A_surfxml_cpu_state_ON)
820 state_initial = SURF_CPU_ON;
821 if (A_surfxml_cpu_state == A_surfxml_cpu_state_OFF)
822 state_initial = SURF_CPU_OFF;
823 surf_parse_get_trace(&state_trace, A_surfxml_cpu_state_file);
825 surf_parse_get_double(&interference_send,
826 A_surfxml_cpu_interference_send);
827 surf_parse_get_double(&interference_recv,
828 A_surfxml_cpu_interference_recv);
829 surf_parse_get_double(&interference_send_recv,
830 A_surfxml_cpu_interference_send_recv);
831 surf_parse_get_double(&max_outgoing_rate,
832 A_surfxml_cpu_max_outgoing_rate);
834 cpu_new(A_surfxml_cpu_name, power_scale, power_initial, power_trace,
835 state_initial, state_trace, interference_send, interference_recv,
836 interference_send_recv, max_outgoing_rate);
839 static void create_routing_table(void)
842 xbt_new0(s_route_KCCFLN05_t, nb_workstation * nb_workstation);
845 static void network_link_free(void *nw_link)
847 free(((network_link_KCCFLN05_t) nw_link)->name);
851 static network_link_KCCFLN05_t network_link_new(char *name,
853 tmgr_trace_t bw_trace,
855 tmgr_trace_t lat_trace,
856 e_surf_network_link_state_t
858 tmgr_trace_t state_trace,
859 e_surf_network_link_sharing_policy_t policy)
861 network_link_KCCFLN05_t nw_link = xbt_new0(s_network_link_KCCFLN05_t, 1);
864 nw_link->resource = (surf_resource_t) surf_workstation_resource;
865 nw_link->type = SURF_WORKSTATION_RESOURCE_LINK;
866 nw_link->name = name;
867 nw_link->bw_current = bw_initial;
870 tmgr_history_add_trace(history, bw_trace, 0.0, 0, nw_link);
871 nw_link->state_current = state_initial;
872 nw_link->lat_current = lat_initial;
875 tmgr_history_add_trace(history, lat_trace, 0.0, 0, nw_link);
877 nw_link->state_event =
878 tmgr_history_add_trace(history, state_trace, 0.0, 0, nw_link);
880 nw_link->constraint =
881 lmm_constraint_new(maxmin_system, nw_link, nw_link->bw_current);
883 if(policy == SURF_NETWORK_LINK_FATPIPE)
884 lmm_constraint_shared(nw_link->constraint);
886 xbt_dict_set(network_link_set, name, nw_link, network_link_free);
891 static void parse_network_link(void)
895 tmgr_trace_t bw_trace;
897 tmgr_trace_t lat_trace;
898 e_surf_network_link_state_t state_initial = SURF_NETWORK_LINK_ON;
899 e_surf_network_link_sharing_policy_t policy_initial = SURF_NETWORK_LINK_SHARED;
900 tmgr_trace_t state_trace;
902 name = xbt_strdup(A_surfxml_network_link_name);
903 surf_parse_get_double(&bw_initial,A_surfxml_network_link_bandwidth);
904 surf_parse_get_trace(&bw_trace, A_surfxml_network_link_bandwidth_file);
905 surf_parse_get_double(&lat_initial,A_surfxml_network_link_latency);
906 surf_parse_get_trace(&lat_trace, A_surfxml_network_link_latency_file);
908 xbt_assert0((A_surfxml_network_link_state==A_surfxml_network_link_state_ON)||
909 (A_surfxml_network_link_state==A_surfxml_network_link_state_OFF),
911 if (A_surfxml_network_link_state==A_surfxml_network_link_state_ON)
912 state_initial = SURF_NETWORK_LINK_ON;
913 else if (A_surfxml_network_link_state==A_surfxml_network_link_state_OFF)
914 state_initial = SURF_NETWORK_LINK_OFF;
916 if (A_surfxml_network_link_sharing_policy==A_surfxml_network_link_sharing_policy_SHARED)
917 policy_initial = SURF_NETWORK_LINK_SHARED;
918 else if (A_surfxml_network_link_sharing_policy==A_surfxml_network_link_sharing_policy_FATPIPE)
919 policy_initial = SURF_NETWORK_LINK_FATPIPE;
921 surf_parse_get_trace(&state_trace,A_surfxml_network_link_state_file);
923 network_link_new(name, bw_initial, bw_trace,
924 lat_initial, lat_trace, state_initial, state_trace,
928 static void route_new(int src_id, int dst_id, network_link_KCCFLN05_t *link_list, int nb_link,
929 double impact_on_src, double impact_on_dst,
930 double impact_on_src_with_other_recv,
931 double impact_on_dst_with_other_send)
933 route_KCCFLN05_t route = &(ROUTE(src_id, dst_id));
935 route->size = nb_link;
936 route->links = link_list = xbt_realloc(link_list, sizeof(network_link_KCCFLN05_t) * nb_link);
937 route->impact_on_src = impact_on_src;
938 route->impact_on_dst = impact_on_src;
939 route->impact_on_src_with_other_recv = impact_on_src_with_other_recv;
940 route->impact_on_dst_with_other_send = impact_on_dst_with_other_send;
944 static int link_list_capacity;
945 static network_link_KCCFLN05_t *link_list = NULL;
946 static int src_id = -1;
947 static int dst_id = -1;
948 static double impact_on_src;
949 static double impact_on_dst;
950 static double impact_on_src_with_other_recv;
951 static double impact_on_dst_with_other_send;
953 static void parse_route_set_endpoints(void)
955 cpu_KCCFLN05_t cpu_tmp = NULL;
957 cpu_tmp = (cpu_KCCFLN05_t) name_service(A_surfxml_route_src);
958 if(cpu_tmp != NULL) {
959 src_id = cpu_tmp->id;
961 xbt_assert1(xbt_dict_get_or_null(router_set, A_surfxml_route_src),
962 "Invalid name '%s': neither a cpu nor a router!",
963 A_surfxml_route_src);
968 cpu_tmp = (cpu_KCCFLN05_t) name_service(A_surfxml_route_dst);
969 if(cpu_tmp != NULL) {
970 dst_id = cpu_tmp->id;
972 xbt_assert1(xbt_dict_get_or_null(router_set, A_surfxml_route_dst),
973 "Invalid name '%s': neither a cpu nor a router!",
974 A_surfxml_route_dst);
979 surf_parse_get_double(&impact_on_src, A_surfxml_route_impact_on_src);
980 surf_parse_get_double(&impact_on_dst, A_surfxml_route_impact_on_dst);
981 surf_parse_get_double(&impact_on_src_with_other_recv,
982 A_surfxml_route_impact_on_src_with_other_recv);
983 surf_parse_get_double(&impact_on_dst_with_other_send,
984 A_surfxml_route_impact_on_dst_with_other_send);
987 link_list_capacity = 1;
988 link_list = xbt_new(network_link_KCCFLN05_t, link_list_capacity);
992 static void parse_route_elem(void)
995 if (nb_link == link_list_capacity) {
996 link_list_capacity *= 2;
997 link_list = xbt_realloc(link_list, (link_list_capacity) * sizeof(network_link_KCCFLN05_t));
1000 link_list[nb_link++] = xbt_dict_get(network_link_set, A_surfxml_route_element_name);
1002 RETHROW1("Link %s not found (dict raised this exception: %s)",A_surfxml_route_element_name);
1006 static void parse_route_set_route(void)
1008 if( src_id != -1 && dst_id != -1 )
1009 route_new(src_id, dst_id, link_list, nb_link, impact_on_src,
1010 impact_on_dst, impact_on_src_with_other_recv,
1011 impact_on_dst_with_other_send);
1014 static void parse_file(const char *file)
1018 /* Figuring out the cpus */
1019 surf_parse_reset_parser();
1020 ETag_surfxml_cpu_fun = parse_cpu;
1021 surf_parse_open(file);
1022 xbt_assert1((!surf_parse()), "Parse error in %s", file);
1025 create_routing_table();
1027 /* Figuring out the router (added after GTNETS) */
1028 surf_parse_reset_parser();
1029 STag_surfxml_router_fun=parse_routers;
1030 surf_parse_open(file);
1031 xbt_assert1((!surf_parse()),"Parse error in %s",file);
1034 /* Figuring out the network links */
1035 surf_parse_reset_parser();
1036 ETag_surfxml_network_link_fun = parse_network_link;
1037 surf_parse_open(file);
1038 xbt_assert1((!surf_parse()), "Parse error in %s", file);
1041 /* Building the routes */
1042 surf_parse_reset_parser();
1043 STag_surfxml_route_fun = parse_route_set_endpoints;
1044 ETag_surfxml_route_element_fun = parse_route_elem;
1045 ETag_surfxml_route_fun = parse_route_set_route;
1046 surf_parse_open(file);
1047 xbt_assert1((!surf_parse()), "Parse error in %s", file);
1050 /* Adding loopback if needed */
1051 for (i = 0; i < nb_workstation; i++)
1052 if(!ROUTE(i,i).size) {
1054 loopback = network_link_new(xbt_strdup("__MSG_loopback__"),
1055 498000000, NULL, 0.000015, NULL,
1056 SURF_NETWORK_LINK_ON, NULL,
1057 SURF_NETWORK_LINK_FATPIPE);
1059 ROUTE(i,i).links = xbt_new0(network_link_KCCFLN05_t, 1);
1060 ROUTE(i,i).links[0] = loopback;
1065 /**************************************/
1066 /********* Module creation ***********/
1067 /**************************************/
1069 static void resource_init_internal(void)
1071 s_surf_action_t action;
1073 surf_workstation_resource = xbt_new0(s_surf_workstation_resource_t, 1);
1075 surf_workstation_resource->common_private =
1076 xbt_new0(s_surf_resource_private_t, 1);
1077 surf_workstation_resource->common_public =
1078 xbt_new0(s_surf_resource_public_t, 1);
1079 surf_workstation_resource->extension_public =
1080 xbt_new0(s_surf_workstation_resource_extension_public_t, 1);
1082 surf_workstation_resource->common_public->states.ready_action_set =
1083 xbt_swag_new(xbt_swag_offset(action, state_hookup));
1084 surf_workstation_resource->common_public->states.running_action_set =
1085 xbt_swag_new(xbt_swag_offset(action, state_hookup));
1086 surf_workstation_resource->common_public->states.failed_action_set =
1087 xbt_swag_new(xbt_swag_offset(action, state_hookup));
1088 surf_workstation_resource->common_public->states.done_action_set =
1089 xbt_swag_new(xbt_swag_offset(action, state_hookup));
1091 surf_workstation_resource->common_public->name_service = name_service;
1092 surf_workstation_resource->common_public->get_resource_name = get_resource_name;
1093 surf_workstation_resource->common_public->action_get_state = surf_action_get_state;
1094 surf_workstation_resource->common_public->action_get_start_time =
1095 surf_action_get_start_time;
1096 surf_workstation_resource->common_public->action_get_finish_time =
1097 surf_action_get_finish_time;
1098 surf_workstation_resource->common_public->action_use = action_use;
1099 surf_workstation_resource->common_public->action_free = action_free;
1100 surf_workstation_resource->common_public->action_cancel = action_cancel;
1101 surf_workstation_resource->common_public->action_recycle = action_recycle;
1102 surf_workstation_resource->common_public->action_change_state = surf_action_change_state;
1103 surf_workstation_resource->common_public->action_set_data = surf_action_set_data;
1104 surf_workstation_resource->common_public->suspend = action_suspend;
1105 surf_workstation_resource->common_public->resume = action_resume;
1106 surf_workstation_resource->common_public->is_suspended = action_is_suspended;
1107 surf_workstation_resource->common_public->set_max_duration = action_set_max_duration;
1108 surf_workstation_resource->common_public->set_priority = action_set_priority;
1109 surf_workstation_resource->common_public->name = "Workstation KCCFLN05";
1111 surf_workstation_resource->common_private->resource_used = resource_used;
1112 surf_workstation_resource->common_private->share_resources = share_resources;
1113 surf_workstation_resource->common_private->update_actions_state = update_actions_state;
1114 surf_workstation_resource->common_private->update_resource_state = update_resource_state;
1115 surf_workstation_resource->common_private->finalize = finalize;
1117 surf_workstation_resource->extension_public->execute = execute;
1118 surf_workstation_resource->extension_public->sleep = action_sleep;
1119 surf_workstation_resource->extension_public->get_state = resource_get_state;
1120 surf_workstation_resource->extension_public->get_speed = get_speed;
1121 surf_workstation_resource->extension_public->get_available_speed = get_available_speed;
1122 surf_workstation_resource->extension_public->communicate = communicate;
1123 surf_workstation_resource->extension_public->execute_parallel_task = execute_parallel_task;
1124 surf_workstation_resource->extension_public->get_route = get_route;
1125 surf_workstation_resource->extension_public->get_route_size = get_route_size;
1126 surf_workstation_resource->extension_public->get_link_name = get_link_name;
1127 surf_workstation_resource->extension_public->get_link_bandwidth = get_link_bandwidth;
1128 surf_workstation_resource->extension_public->get_link_latency = get_link_latency;
1130 workstation_set = xbt_dict_new();
1131 router_set = xbt_dict_new();
1132 network_link_set = xbt_dict_new();
1134 xbt_assert0(maxmin_system, "surf_init has to be called first!");
1137 /**************************************/
1138 /*************** Generic **************/
1139 /**************************************/
1140 void surf_workstation_resource_init_KCCFLN05(const char *filename)
1142 xbt_assert0(!surf_cpu_resource, "CPU resource type already defined");
1143 xbt_assert0(!surf_network_resource, "network resource type already defined");
1144 resource_init_internal();
1145 parse_file(filename);
1147 xbt_dynar_push(resource_list, &surf_workstation_resource);
1150 void surf_workstation_resource_init_KCCFLN05_proportional(const char *filename)
1152 xbt_assert0(!surf_cpu_resource, "CPU resource type already defined");
1153 xbt_assert0(!surf_network_resource, "network resource type already defined");
1154 resource_init_internal();
1155 parse_file(filename);
1157 surf_workstation_resource->common_public->name = "Workstation KCCFLN05 (proportional)";
1159 xbt_dynar_push(resource_list, &surf_workstation_resource);
1162 void surf_workstation_resource_init_KCCFLN05_Vegas(const char *filename)
1164 xbt_assert0(!surf_cpu_resource, "CPU resource type already defined");
1165 xbt_assert0(!surf_network_resource, "network resource type already defined");
1166 resource_init_internal();
1167 parse_file(filename);
1169 lmm_set_default_protocol_function(func_vegas_f, func_vegas_fp, func_vegas_fpi);
1171 surf_workstation_resource->common_public->name = "Workstation KCCFLN05 (Vegas)";
1172 use_lagrange_solver=1;
1173 xbt_dynar_push(resource_list, &surf_workstation_resource);
1176 void surf_workstation_resource_init_KCCFLN05_Reno(const char *filename)
1178 xbt_assert0(!surf_cpu_resource, "CPU resource type already defined");
1179 xbt_assert0(!surf_network_resource, "network resource type already defined");
1180 resource_init_internal();
1181 parse_file(filename);
1183 lmm_set_default_protocol_function(func_reno_f, func_reno_fp, func_reno_fpi);
1185 surf_workstation_resource->common_public->name = "Workstation KCCFLN05 (Reno)";
1186 use_lagrange_solver=1;
1187 xbt_dynar_push(resource_list, &surf_workstation_resource);