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 "surf_private.h"
12 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_workstation, surf,
13 "Logging specific to the SURF workstation module (KCCFLN05)");
14 XBT_LOG_EXTERNAL_CATEGORY(surf_parse);
17 SURF_WORKSTATION_RESOURCE_CPU,
18 SURF_WORKSTATION_RESOURCE_LINK,
19 } e_surf_workstation_model_type_t;
22 /**************************************/
23 /********* router object **************/
24 /**************************************/
25 typedef struct router_KCCFLN05 {
28 } s_router_KCCFLN05_t, *router_KCCFLN05_t;
31 /**************************************/
32 /********* cpu object *****************/
33 /**************************************/
34 typedef struct cpu_KCCFLN05 {
35 surf_model_t model; /* Do not move this field: must match model_obj_t */
36 xbt_dict_t properties; /* Do not move this field: must match link_KCCFLN05_t */
37 e_surf_workstation_model_type_t type; /* Do not move this field: must match link_KCCFLN05_t */
38 char *name; /* Do not move this field: must match link_KCCFLN05_t */
39 lmm_constraint_t constraint;
43 double interference_send;
44 double interference_recv;
45 double interference_send_recv;
46 tmgr_trace_event_t power_event;
47 e_surf_cpu_state_t state_current;
48 tmgr_trace_event_t state_event;
49 int id; /* cpu and network card are a single object... */
50 xbt_dynar_t incomming_communications;
51 xbt_dynar_t outgoing_communications;
52 } s_cpu_KCCFLN05_t, *cpu_KCCFLN05_t;
54 /**************************************/
55 /*********** network object ***********/
56 /**************************************/
58 typedef struct link_KCCFLN05 {
59 surf_model_t model; /* Do not move this field: must match model_obj_t */
60 xbt_dict_t properties; /* Do not move this field: must match cpu_KCCFLN05_t */
61 e_surf_workstation_model_type_t type; /* Do not move this field: must match cpu_KCCFLN05_t */
62 char *name; /* Do not move this field: must match cpu_KCCFLN05_t */
63 lmm_constraint_t constraint;
65 tmgr_trace_event_t lat_event;
67 tmgr_trace_event_t bw_event;
68 e_surf_link_state_t state_current;
69 tmgr_trace_event_t state_event;
70 } s_link_KCCFLN05_t, *link_KCCFLN05_t;
73 typedef struct s_route_KCCFLN05 {
76 double impact_on_src_with_other_recv;
77 double impact_on_dst_with_other_send;
78 link_KCCFLN05_t *links;
80 } s_route_KCCFLN05_t, *route_KCCFLN05_t;
82 /**************************************/
83 /*************** actions **************/
84 /**************************************/
85 typedef struct surf_action_workstation_KCCFLN05 {
86 s_surf_action_t generic_action;
89 lmm_variable_t variable;
92 cpu_KCCFLN05_t src; /* could be avoided */
93 cpu_KCCFLN05_t dst; /* could be avoided */
94 } s_surf_action_workstation_KCCFLN05_t,
95 *surf_action_workstation_KCCFLN05_t;
99 static int nb_workstation = 0;
100 static s_route_KCCFLN05_t *routing_table = NULL;
101 #define ROUTE(i,j) routing_table[(i)+(j)*nb_workstation]
102 static link_KCCFLN05_t loopback = NULL;
103 static xbt_dict_t parallel_task_link_set = NULL;
104 //added to work with GTNETS
105 static xbt_dict_t router_set = NULL;
106 static lmm_system_t maxmin_system = NULL;
109 /* convenient function */
110 static void __update_cpu_usage(cpu_KCCFLN05_t cpu)
113 surf_action_workstation_KCCFLN05_t action = NULL;
114 if ((!xbt_dynar_length(cpu->incomming_communications)) &&
115 (!xbt_dynar_length(cpu->outgoing_communications))) {
116 /* No communications */
117 lmm_update_constraint_bound(maxmin_system, cpu->constraint,
118 cpu->power_current * cpu->power_scale);
119 } else if ((!xbt_dynar_length(cpu->incomming_communications))
120 && (xbt_dynar_length(cpu->outgoing_communications))) {
122 lmm_update_constraint_bound(maxmin_system, cpu->constraint,
123 cpu->power_current * cpu->power_scale *
124 cpu->interference_send);
125 xbt_dynar_foreach(cpu->outgoing_communications, cpt, action)
126 lmm_elem_set_value(maxmin_system, cpu->constraint,
128 cpu->power_current * cpu->power_scale *
129 ROUTE(action->src->id,
130 action->dst->id).impact_on_src);
131 } else if ((xbt_dynar_length(cpu->incomming_communications))
132 && (!xbt_dynar_length(cpu->outgoing_communications))) {
134 lmm_update_constraint_bound(maxmin_system, cpu->constraint,
135 cpu->power_current * cpu->power_scale *
136 cpu->interference_recv);
137 xbt_dynar_foreach(cpu->incomming_communications, cpt, action)
138 lmm_elem_set_value(maxmin_system, cpu->constraint,
140 cpu->power_current * cpu->power_scale *
141 ROUTE(action->src->id,
142 action->dst->id).impact_on_dst);
144 /* Emission & Reception */
145 lmm_update_constraint_bound(maxmin_system, cpu->constraint,
146 cpu->power_current * cpu->power_scale *
147 cpu->interference_send_recv);
148 xbt_dynar_foreach(cpu->outgoing_communications, cpt, action)
149 lmm_elem_set_value(maxmin_system, cpu->constraint,
151 cpu->power_current * cpu->power_scale *
152 ROUTE(action->src->id,
154 impact_on_src_with_other_recv);
155 xbt_dynar_foreach(cpu->incomming_communications, cpt, action)
156 lmm_elem_set_value(maxmin_system, cpu->constraint,
158 cpu->power_current * cpu->power_scale *
159 ROUTE(action->src->id,
161 impact_on_dst_with_other_send);
165 /**************************************/
166 /******* Resource Public **********/
167 /**************************************/
169 static void *name_service(const char *name)
175 res = xbt_dict_get(workstation_set, name);
177 if (e.category != not_found_error)
179 WARN1("Host '%s' not found, verifing if it is a router", name);
187 static const char *get_resource_name(void *resource_id)
189 /* We can freely cast as a cpu_KCCFLN05_t because it has the same
190 prefix as link_KCCFLN05_t. However, only cpu_KCCFLN05_t
191 will theoretically be given as an argument here. */
192 return ((cpu_KCCFLN05_t) resource_id)->name;
195 static xbt_dict_t get_properties(void *resource)
197 /* We can freely cast as a cpu_KCCFLN05_t because it has the same
198 prefix as link_KCCFLN05_t. */
199 return ((cpu_KCCFLN05_t) resource)->properties;
202 /* action_get_state is inherited from the surf module */
204 static void action_use(surf_action_t action)
210 static int action_free(surf_action_t action)
213 surf_action_t act = NULL;
214 cpu_KCCFLN05_t src = ((surf_action_workstation_KCCFLN05_t) action)->src;
215 cpu_KCCFLN05_t dst = ((surf_action_workstation_KCCFLN05_t) action)->dst;
218 if (!action->using) {
219 xbt_swag_remove(action, action->state_set);
220 if (((surf_action_workstation_KCCFLN05_t) action)->variable)
221 lmm_variable_free(maxmin_system,
222 ((surf_action_workstation_KCCFLN05_t) action)->
225 xbt_dynar_foreach(src->outgoing_communications, cpt, act)
227 xbt_dynar_remove_at(src->outgoing_communications, cpt, &act);
232 xbt_dynar_foreach(dst->incomming_communications, cpt, act)
234 xbt_dynar_remove_at(dst->incomming_communications, cpt, &act);
238 if (src && (!xbt_dynar_length(src->outgoing_communications)))
239 __update_cpu_usage(src);
240 if (dst && (!xbt_dynar_length(dst->incomming_communications)))
241 __update_cpu_usage(dst);
249 static void action_cancel(surf_action_t action)
251 surf_action_change_state(action, SURF_ACTION_FAILED);
255 static void action_recycle(surf_action_t action)
261 /* action_change_state is inherited from the surf module */
262 /* action_set_data is inherited from the surf module */
264 static void action_suspend(surf_action_t action)
266 XBT_IN1("(%p))", action);
267 if (((surf_action_workstation_KCCFLN05_t) action)->suspended != 2) {
268 ((surf_action_workstation_KCCFLN05_t) action)->suspended = 1;
269 lmm_update_variable_weight(maxmin_system,
270 ((surf_action_workstation_KCCFLN05_t)
271 action)->variable, 0.0);
276 static void action_resume(surf_action_t action)
278 XBT_IN1("(%p)", action);
279 if (((surf_action_workstation_KCCFLN05_t) action)->suspended != 2) {
280 if (((surf_action_workstation_KCCFLN05_t) action)->lat_current == 0.0)
281 lmm_update_variable_weight(maxmin_system,
282 ((surf_action_workstation_KCCFLN05_t)
283 action)->variable, action->priority);
285 lmm_update_variable_weight(maxmin_system,
286 ((surf_action_workstation_KCCFLN05_t)
288 ((surf_action_workstation_KCCFLN05_t)
289 action)->lat_current);
291 ((surf_action_workstation_KCCFLN05_t) action)->suspended = 0;
296 static int action_is_suspended(surf_action_t action)
298 return (((surf_action_workstation_KCCFLN05_t) action)->suspended == 1);
301 static void action_set_max_duration(surf_action_t action, double duration)
302 { /* FIXME: should inherit */
303 XBT_IN2("(%p,%g)", action, duration);
304 action->max_duration = duration;
309 static void action_set_priority(surf_action_t action, double priority)
311 XBT_IN2("(%p,%g)", action, priority);
312 action->priority = priority;
313 lmm_update_variable_weight(maxmin_system, ((surf_action_workstation_KCCFLN05_t) action)->variable, priority);
318 /**************************************/
319 /******* Resource Private **********/
320 /**************************************/
322 static int resource_used(void *resource_id)
324 /* We can freely cast as a link_KCCFLN05_t because it has
325 the same prefix as cpu_KCCFLN05_t */
326 if (((cpu_KCCFLN05_t) resource_id)->type ==
327 SURF_WORKSTATION_RESOURCE_CPU)
328 return (lmm_constraint_used
329 (maxmin_system, ((cpu_KCCFLN05_t) resource_id)->constraint)
330 || ((((cpu_KCCFLN05_t) resource_id)->bus) ?
331 lmm_constraint_used(maxmin_system,
332 ((cpu_KCCFLN05_t) resource_id)->
335 return lmm_constraint_used(maxmin_system,
336 ((link_KCCFLN05_t) resource_id)->
341 static double share_resources(double now)
343 s_surf_action_workstation_KCCFLN05_t s_action;
344 surf_action_workstation_KCCFLN05_t action = NULL;
346 xbt_swag_t running_actions =
347 surf_workstation_model->common_public->states.running_action_set;
348 double min = generic_maxmin_share_resources(running_actions,
349 xbt_swag_offset(s_action,
354 xbt_swag_foreach(action, running_actions) {
355 if (action->latency > 0) {
357 min = action->latency;
358 DEBUG3("Updating min (value) with %p (start %f): %f", action,
359 action->generic_action.start, min);
360 } else if (action->latency < min) {
361 min = action->latency;
362 DEBUG3("Updating min (latency) with %p (start %f): %f", action,
363 action->generic_action.start, min);
368 DEBUG1("min value : %f", min);
373 static void update_actions_state(double now, double delta)
376 surf_action_workstation_KCCFLN05_t action = NULL;
377 surf_action_workstation_KCCFLN05_t next_action = NULL;
378 xbt_swag_t running_actions =
379 surf_workstation_model->common_public->states.running_action_set;
381 xbt_swag_foreach_safe(action, next_action, running_actions) {
383 if (action->latency > 0) {
384 if (action->latency > deltap) {
385 double_update(&(action->latency), deltap);
388 double_update(&(deltap), action->latency);
389 action->latency = 0.0;
391 if ((action->latency == 0.0) && (action->suspended == 0)) {
392 if ((action)->lat_current == 0.0)
393 lmm_update_variable_weight(maxmin_system, action->variable, 1.0);
395 lmm_update_variable_weight(maxmin_system, action->variable,
396 action->lat_current);
399 DEBUG3("Action (%p) : remains (%g) updated by %g.",
400 action, action->generic_action.remains,
401 lmm_variable_getvalue(action->variable) * deltap);
402 double_update(&(action->generic_action.remains),
403 lmm_variable_getvalue(action->variable) * deltap);
405 if (action->generic_action.max_duration != NO_MAX_DURATION)
406 double_update(&(action->generic_action.max_duration), delta);
408 if ((action->generic_action.remains <= 0) &&
409 (lmm_get_variable_weight(action->variable) > 0)) {
410 action->generic_action.finish = surf_get_clock();
411 surf_action_change_state((surf_action_t) action, SURF_ACTION_DONE);
412 } else if ((action->generic_action.max_duration != NO_MAX_DURATION) &&
413 (action->generic_action.max_duration <= 0)) {
414 action->generic_action.finish = surf_get_clock();
415 surf_action_change_state((surf_action_t) action, SURF_ACTION_DONE);
417 /* Need to check that none of the resource has failed */
418 lmm_constraint_t cnst = NULL;
420 void *constraint_id = NULL;
423 lmm_get_cnst_from_var(maxmin_system, action->variable,
425 constraint_id = lmm_constraint_id(cnst);
427 /* if(((link_KCCFLN05_t)constraint_id)->type== */
428 /* SURF_WORKSTATION_RESOURCE_LINK) { */
429 /* DEBUG2("Checking for link %s (%p)", */
430 /* ((link_KCCFLN05_t)constraint_id)->name, */
431 /* ((link_KCCFLN05_t)constraint_id)); */
433 /* if(((cpu_KCCFLN05_t)constraint_id)->type== */
434 /* SURF_WORKSTATION_RESOURCE_CPU) { */
435 /* DEBUG3("Checking for cpu %s (%p) : %s", */
436 /* ((cpu_KCCFLN05_t)constraint_id)->name, */
437 /* ((cpu_KCCFLN05_t)constraint_id), */
438 /* ((cpu_KCCFLN05_t)constraint_id)->state_current==SURF_CPU_OFF?"Off":"On"); */
441 if (((((link_KCCFLN05_t) constraint_id)->type ==
442 SURF_WORKSTATION_RESOURCE_LINK) &&
443 (((link_KCCFLN05_t) constraint_id)->state_current ==
445 ((((cpu_KCCFLN05_t) constraint_id)->type ==
446 SURF_WORKSTATION_RESOURCE_CPU) &&
447 (((cpu_KCCFLN05_t) constraint_id)->state_current ==
449 DEBUG1("Action (%p) Failed!!", action);
450 action->generic_action.finish = surf_get_clock();
451 surf_action_change_state((surf_action_t) action,
461 static void update_resource_state(void *id,
462 tmgr_trace_event_t event_type,
465 cpu_KCCFLN05_t cpu = id;
466 link_KCCFLN05_t nw_link = id;
468 if (nw_link->type == SURF_WORKSTATION_RESOURCE_LINK) {
469 DEBUG2("Updating link %s (%p)", nw_link->name, nw_link);
470 if (event_type == nw_link->bw_event) {
471 nw_link->bw_current = value;
472 lmm_update_constraint_bound(maxmin_system, nw_link->constraint,
473 nw_link->bw_current);
474 } else if (event_type == nw_link->lat_event) {
475 double delta = value - nw_link->lat_current;
476 lmm_variable_t var = NULL;
477 surf_action_workstation_KCCFLN05_t action = NULL;
479 nw_link->lat_current = value;
480 while (lmm_get_var_from_cnst
481 (maxmin_system, nw_link->constraint, &var)) {
482 action = lmm_variable_id(var);
483 action->lat_current += delta;
484 if (action->rate < 0)
485 lmm_update_variable_bound(maxmin_system, action->variable,
486 SG_TCP_CTE_GAMMA / (2.0 *
490 lmm_update_variable_bound(maxmin_system, action->variable,
492 SG_TCP_CTE_GAMMA / (2.0 *
495 if (action->suspended == 0)
496 lmm_update_variable_weight(maxmin_system, action->variable,
497 action->lat_current);
498 lmm_update_variable_latency(maxmin_system, action->variable,
503 } else if (event_type == nw_link->state_event) {
505 nw_link->state_current = SURF_LINK_ON;
507 nw_link->state_current = SURF_LINK_OFF;
509 CRITICAL0("Unknown event ! \n");
513 } else if (cpu->type == SURF_WORKSTATION_RESOURCE_CPU) {
514 DEBUG3("Updating cpu %s (%p) with value %g", cpu->name, cpu, value);
515 if (event_type == cpu->power_event) {
516 cpu->power_current = value;
517 __update_cpu_usage(cpu);
518 } else if (event_type == cpu->state_event) {
520 cpu->state_current = SURF_CPU_ON;
522 cpu->state_current = SURF_CPU_OFF;
524 CRITICAL0("Unknown event ! \n");
534 static void finalize(void)
538 xbt_dict_free(&link_set);
539 xbt_dict_free(&workstation_set);
540 xbt_dict_free(&router_set);
541 if (parallel_task_link_set != NULL) {
542 xbt_dict_free(¶llel_task_link_set);
544 xbt_swag_free(surf_workstation_model->common_public->states.
546 xbt_swag_free(surf_workstation_model->common_public->states.
548 xbt_swag_free(surf_workstation_model->common_public->states.
550 xbt_swag_free(surf_workstation_model->common_public->states.
553 free(surf_workstation_model->common_public);
554 free(surf_workstation_model->common_private);
555 free(surf_workstation_model->extension_public);
557 free(surf_workstation_model);
558 surf_workstation_model = NULL;
560 for (i = 0; i < nb_workstation; i++)
561 for (j = 0; j < nb_workstation; j++)
562 free(ROUTE(i, j).links);
564 routing_table = NULL;
568 lmm_system_free(maxmin_system);
569 maxmin_system = NULL;
573 /**************************************/
574 /******* Resource Private **********/
575 /**************************************/
577 static surf_action_t execute(void *cpu, double size)
579 surf_action_workstation_KCCFLN05_t action = NULL;
580 cpu_KCCFLN05_t CPU = cpu;
582 XBT_IN2("(%s,%g)", CPU->name, size);
583 action = xbt_new0(s_surf_action_workstation_KCCFLN05_t, 1);
585 action->generic_action.using = 1;
586 action->generic_action.cost = size;
587 action->generic_action.remains = size;
588 action->generic_action.priority = 1.0;
589 action->generic_action.max_duration = NO_MAX_DURATION;
590 action->generic_action.start = surf_get_clock();
591 action->generic_action.finish = -1.0;
592 action->generic_action.model_type =
593 (surf_model_t) surf_workstation_model;
594 action->suspended = 0;
596 if (CPU->state_current == SURF_CPU_ON)
597 action->generic_action.state_set =
598 surf_workstation_model->common_public->states.
601 action->generic_action.state_set =
602 surf_workstation_model->common_public->states.failed_action_set;
603 xbt_swag_insert(action, action->generic_action.state_set);
605 action->variable = lmm_variable_new(maxmin_system, action,
606 action->generic_action.priority,
608 lmm_expand(maxmin_system, CPU->constraint, action->variable, 1.0);
610 return (surf_action_t) action;
613 static surf_action_t action_sleep(void *cpu, double duration)
615 surf_action_workstation_KCCFLN05_t action = NULL;
617 XBT_IN2("(%s,%g)", ((cpu_KCCFLN05_t) cpu)->name, duration);
619 action = (surf_action_workstation_KCCFLN05_t) execute(cpu, 1.0);
620 action->generic_action.max_duration = duration;
621 action->suspended = 2;
622 lmm_update_variable_weight(maxmin_system, action->variable, 0.0);
625 return (surf_action_t) action;
628 static e_surf_cpu_state_t resource_get_state(void *cpu)
630 return ((cpu_KCCFLN05_t) cpu)->state_current;
633 static double get_speed(void *cpu, double load)
635 return load * (((cpu_KCCFLN05_t) cpu)->power_scale);
638 static double get_available_speed(void *cpu)
640 return ((cpu_KCCFLN05_t) cpu)->power_current;
643 static surf_action_t communicate(void *src, void *dst, double size,
646 surf_action_workstation_KCCFLN05_t action = NULL;
647 cpu_KCCFLN05_t card_src = src;
648 cpu_KCCFLN05_t card_dst = dst;
649 route_KCCFLN05_t route = &(ROUTE(card_src->id, card_dst->id));
650 int route_size = route->size;
653 XBT_IN4("(%s,%s,%g,%g)", card_src->name, card_dst->name, size, rate);
654 xbt_assert2(route_size,
655 "You're trying to send data from %s to %s but there is no connexion between these two cards.",
656 card_src->name, card_dst->name);
658 action = xbt_new0(s_surf_action_workstation_KCCFLN05_t, 1);
660 action->generic_action.using = 1;
661 action->generic_action.cost = size;
662 action->generic_action.remains = size;
663 action->generic_action.max_duration = NO_MAX_DURATION;
664 action->generic_action.start = surf_get_clock();
665 action->generic_action.finish = -1.0;
668 action->generic_action.model_type =
669 (surf_model_t) surf_workstation_model;
670 action->suspended = 0; /* Should be useless because of the
671 calloc but it seems to help valgrind... */
672 action->generic_action.state_set =
673 surf_workstation_model->common_public->states.running_action_set;
675 xbt_dynar_push(card_src->outgoing_communications, &action);
676 xbt_dynar_push(card_dst->incomming_communications, &action);
678 xbt_swag_insert(action, action->generic_action.state_set);
681 action->latency = 0.0;
682 for (i = 0; i < route_size; i++)
683 action->latency += route->links[i]->lat_current;
684 action->lat_current = action->latency;
686 if (action->latency > 0)
687 action->variable = lmm_variable_new(maxmin_system, action, 0.0, -1.0, route_size + 4); /* +1 for the src bus
690 +1 for the dst cpu */
692 action->variable = lmm_variable_new(maxmin_system, action, 1.0, -1.0,
695 if (action->rate < 0) {
696 if (action->lat_current > 0)
697 lmm_update_variable_bound(maxmin_system, action->variable,
698 SG_TCP_CTE_GAMMA / (2.0 *
699 action->lat_current));
701 lmm_update_variable_bound(maxmin_system, action->variable, -1.0);
703 if (action->lat_current > 0)
704 lmm_update_variable_bound(maxmin_system, action->variable,
706 SG_TCP_CTE_GAMMA / (2.0 *
710 lmm_update_variable_bound(maxmin_system, action->variable,
714 lmm_update_variable_latency(maxmin_system, action->variable,
715 action->latency); /* Should be useless */
717 for (i = 0; i < route_size; i++)
718 lmm_expand(maxmin_system, route->links[i]->constraint,
719 action->variable, 1.0);
721 lmm_expand(maxmin_system, card_src->bus, action->variable, 1.0);
723 lmm_expand(maxmin_system, card_dst->bus, action->variable, 1.0);
724 lmm_expand(maxmin_system, card_src->constraint, action->variable, 0.0);
725 lmm_expand(maxmin_system, card_dst->constraint, action->variable, 0.0);
728 return (surf_action_t) action;
731 static surf_action_t execute_parallel_task(int workstation_nb,
732 void **workstation_list,
733 double *computation_amount,
734 double *communication_amount,
735 double amount, double rate)
737 surf_action_workstation_KCCFLN05_t action = NULL;
742 if (parallel_task_link_set == NULL) {
743 parallel_task_link_set =
744 xbt_dict_new_ext(workstation_nb * workstation_nb * 10);
747 /* Compute the number of affected resources... */
748 for (i = 0; i < workstation_nb; i++) {
749 for (j = 0; j < workstation_nb; j++) {
750 cpu_KCCFLN05_t card_src = workstation_list[i];
751 cpu_KCCFLN05_t card_dst = workstation_list[j];
752 int route_size = ROUTE(card_src->id, card_dst->id).size;
753 link_KCCFLN05_t *route =
754 ROUTE(card_src->id, card_dst->id).links;
756 if (communication_amount[i * workstation_nb + j] > 0)
757 for (k = 0; k < route_size; k++) {
758 xbt_dict_set(parallel_task_link_set, route[k]->name,
763 nb_link = xbt_dict_length(parallel_task_link_set);
764 xbt_dict_reset(parallel_task_link_set);
767 for (i = 0; i < workstation_nb; i++)
768 if (computation_amount[i] > 0)
771 action = xbt_new0(s_surf_action_workstation_KCCFLN05_t, 1);
772 DEBUG3("Creating a parallel task (%p) with %d cpus and %d links.",
773 action, nb_host, nb_link);
774 action->generic_action.using = 1;
775 action->generic_action.cost = amount;
776 action->generic_action.remains = amount;
777 action->generic_action.max_duration = NO_MAX_DURATION;
778 action->generic_action.start = surf_get_clock();
779 action->generic_action.finish = -1.0;
780 action->generic_action.model_type =
781 (surf_model_t) surf_workstation_model;
782 action->suspended = 0; /* Should be useless because of the
783 calloc but it seems to help valgrind... */
784 action->generic_action.state_set =
785 surf_workstation_model->common_public->states.running_action_set;
787 xbt_swag_insert(action, action->generic_action.state_set);
790 if (action->rate > 0)
791 action->variable = lmm_variable_new(maxmin_system, action, 1.0, -1.0,
795 lmm_variable_new(maxmin_system, action, 1.0, action->rate,
798 for (i = 0; i < workstation_nb; i++)
799 if (computation_amount[i] > 0)
800 lmm_expand(maxmin_system,
801 ((cpu_KCCFLN05_t) workstation_list[i])->constraint,
802 action->variable, computation_amount[i]);
804 for (i = 0; i < workstation_nb; i++) {
805 for (j = 0; j < workstation_nb; j++) {
806 cpu_KCCFLN05_t card_src = workstation_list[i];
807 cpu_KCCFLN05_t card_dst = workstation_list[j];
808 int route_size = ROUTE(card_src->id, card_dst->id).size;
809 link_KCCFLN05_t *route =
810 ROUTE(card_src->id, card_dst->id).links;
812 for (k = 0; k < route_size; k++) {
813 if (communication_amount[i * workstation_nb + j] > 0) {
814 lmm_expand_add(maxmin_system, route[k]->constraint,
816 communication_amount[i * workstation_nb + j]);
822 if (nb_link + nb_host == 0) {
823 action->generic_action.cost = 1.0;
824 action->generic_action.remains = 0.0;
827 return (surf_action_t) action;
830 /* returns an array of link_KCCFLN05_t */
831 static const void **get_route(void *src, void *dst)
833 cpu_KCCFLN05_t card_src = src;
834 cpu_KCCFLN05_t card_dst = dst;
835 route_KCCFLN05_t route = &(ROUTE(card_src->id, card_dst->id));
837 return (const void **) route->links;
840 static int get_route_size(void *src, void *dst)
842 cpu_KCCFLN05_t card_src = src;
843 cpu_KCCFLN05_t card_dst = dst;
844 route_KCCFLN05_t route = &(ROUTE(card_src->id, card_dst->id));
848 static const char *get_link_name(const void *link)
850 return ((link_KCCFLN05_t) link)->name;
853 static double get_link_bandwidth(const void *link)
855 return ((link_KCCFLN05_t) link)->bw_current;
858 static double get_link_latency(const void *link)
860 return ((link_KCCFLN05_t) link)->lat_current;
863 /**************************************/
864 /*** Resource Creation & Destruction **/
865 /**************************************/
868 static void router_free(void *router)
870 free(((router_KCCFLN05_t) router)->name);
873 static void router_new(const char *name)
875 static unsigned int nb_routers = 0;
876 router_KCCFLN05_t router;
878 INFO1("Creating a router %s", name);
880 router = xbt_new0(s_router_KCCFLN05_t, 1);
882 router->name = xbt_strdup(name);
883 router->id = nb_routers++;
884 xbt_dict_set(router_set, name, router, router_free);
887 static void parse_routers(void)
889 //add a dumb router just to be GTNETS compatible
890 router_new(A_surfxml_router_id);
893 static void cpu_free(void *cpu)
895 free(((cpu_KCCFLN05_t) cpu)->name);
896 xbt_dynar_free(&(((cpu_KCCFLN05_t) cpu)->incomming_communications));
897 xbt_dynar_free(&(((cpu_KCCFLN05_t) cpu)->outgoing_communications));
901 static cpu_KCCFLN05_t cpu_new(const char *name, double power_scale,
902 double power_initial,
903 tmgr_trace_t power_trace,
904 e_surf_cpu_state_t state_initial,
905 tmgr_trace_t state_trace,
906 double interference_send,
907 double interference_recv,
908 double interference_send_recv,
909 double max_outgoing_rate,
910 xbt_dict_t cpu_properties_k)
912 cpu_KCCFLN05_t cpu = xbt_new0(s_cpu_KCCFLN05_t, 1);
913 xbt_assert1(! xbt_dict_get_or_null(workstation_set, name),
914 "Host '%s' declared several times in the platform file.",name);
916 CDEBUG8(surf_parse, "cpu_new(%s,power_scale=%.2f,power_initial=%.2f,state_init=%d,isend=%.2f,irecv=%.2f,isendrev=%.2f) -> %p",
917 name,power_scale,power_initial,state_initial,interference_send,interference_recv,interference_send_recv,cpu);
919 cpu->model = (surf_model_t) surf_workstation_model;
920 cpu->type = SURF_WORKSTATION_RESOURCE_CPU;
921 cpu->name = xbt_strdup(name);
922 cpu->id = nb_workstation++;
924 cpu->power_scale = power_scale;
925 xbt_assert0(cpu->power_scale > 0, "Power has to be >0");
927 cpu->power_current = power_initial;
930 tmgr_history_add_trace(history, power_trace, 0.0, 0, cpu);
932 cpu->state_current = state_initial;
935 tmgr_history_add_trace(history, state_trace, 0.0, 0, cpu);
937 cpu->interference_send = interference_send;
938 cpu->interference_recv = interference_recv;
939 cpu->interference_send_recv = interference_send_recv;
942 lmm_constraint_new(maxmin_system, cpu,
943 cpu->power_current * cpu->power_scale);
944 if (max_outgoing_rate > 0)
945 cpu->bus = lmm_constraint_new(maxmin_system, cpu, max_outgoing_rate);
947 cpu->incomming_communications =
948 xbt_dynar_new(sizeof(surf_action_workstation_KCCFLN05_t), NULL);
949 cpu->outgoing_communications =
950 xbt_dynar_new(sizeof(surf_action_workstation_KCCFLN05_t), NULL);
952 /*add the property set*/
953 cpu->properties = current_property_set;
955 xbt_dict_set(workstation_set, name, cpu, cpu_free);
960 static void create_routing_table(void)
962 routing_table = xbt_new0(s_route_KCCFLN05_t, nb_workstation * nb_workstation);
965 static void parse_cpu_init(void)
967 double power_scale = 0.0;
968 double power_initial = 0.0;
969 tmgr_trace_t power_trace = NULL;
970 e_surf_cpu_state_t state_initial = SURF_CPU_OFF;
971 tmgr_trace_t state_trace = NULL;
972 double interference_send = 0.0;
973 double interference_recv = 0.0;
974 double interference_send_recv = 0.0;
975 double max_outgoing_rate = -1.0;
977 surf_parse_get_double(&power_scale, A_surfxml_host_power);
978 surf_parse_get_double(&power_initial, A_surfxml_host_availability);
979 surf_parse_get_trace(&power_trace, A_surfxml_host_availability_file);
981 xbt_assert0((A_surfxml_host_state == A_surfxml_host_state_ON) ||
982 (A_surfxml_host_state == A_surfxml_host_state_OFF),
984 if (A_surfxml_host_state == A_surfxml_host_state_ON)
985 state_initial = SURF_CPU_ON;
986 if (A_surfxml_host_state == A_surfxml_host_state_OFF)
987 state_initial = SURF_CPU_OFF;
988 surf_parse_get_trace(&state_trace, A_surfxml_host_state_file);
990 surf_parse_get_double(&interference_send,
991 A_surfxml_host_interference_send);
992 surf_parse_get_double(&interference_recv,
993 A_surfxml_host_interference_recv);
994 surf_parse_get_double(&interference_send_recv,
995 A_surfxml_host_interference_send_recv);
996 surf_parse_get_double(&max_outgoing_rate,
997 A_surfxml_host_max_outgoing_rate);
998 current_property_set = xbt_dict_new();
999 cpu_new(A_surfxml_host_id, power_scale, power_initial, power_trace,
1000 state_initial, state_trace, interference_send, interference_recv,
1001 interference_send_recv, max_outgoing_rate,current_property_set);
1004 static void link_free(void *nw_link)
1006 free(((link_KCCFLN05_t) nw_link)->name);
1010 static link_KCCFLN05_t link_new(char *name,
1012 tmgr_trace_t bw_trace,
1014 tmgr_trace_t lat_trace,
1017 tmgr_trace_t state_trace,
1018 e_surf_link_sharing_policy_t
1019 policy, xbt_dict_t properties_args)
1021 link_KCCFLN05_t nw_link = xbt_new0(s_link_KCCFLN05_t, 1);
1024 nw_link->model = (surf_model_t) surf_workstation_model;
1025 nw_link->type = SURF_WORKSTATION_RESOURCE_LINK;
1026 nw_link->name = name;
1027 nw_link->bw_current = bw_initial;
1030 tmgr_history_add_trace(history, bw_trace, 0.0, 0, nw_link);
1031 nw_link->state_current = state_initial;
1032 nw_link->lat_current = lat_initial;
1034 nw_link->lat_event =
1035 tmgr_history_add_trace(history, lat_trace, 0.0, 0, nw_link);
1037 nw_link->state_event =
1038 tmgr_history_add_trace(history, state_trace, 0.0, 0, nw_link);
1040 nw_link->constraint =
1041 lmm_constraint_new(maxmin_system, nw_link, nw_link->bw_current);
1043 if (policy == SURF_LINK_FATPIPE)
1044 lmm_constraint_shared(nw_link->constraint);
1046 /*add the property set*/
1047 nw_link->properties = properties_args;
1049 xbt_dict_set(link_set, name, nw_link, link_free);
1054 static void parse_link_init(void)
1058 tmgr_trace_t bw_trace;
1060 tmgr_trace_t lat_trace;
1061 e_surf_link_state_t state_initial_link = SURF_LINK_ON;
1062 e_surf_link_sharing_policy_t policy_initial_link = SURF_LINK_SHARED;
1063 tmgr_trace_t state_trace;
1065 name_link = xbt_strdup(A_surfxml_link_id);
1066 surf_parse_get_double(&bw_initial, A_surfxml_link_bandwidth);
1067 surf_parse_get_trace(&bw_trace, A_surfxml_link_bandwidth_file);
1068 surf_parse_get_double(&lat_initial, A_surfxml_link_latency);
1069 surf_parse_get_trace(&lat_trace, A_surfxml_link_latency_file);
1071 xbt_assert0((A_surfxml_link_state ==
1072 A_surfxml_link_state_ON)
1073 || (A_surfxml_link_state ==
1074 A_surfxml_link_state_OFF), "Invalid state");
1075 if (A_surfxml_link_state == A_surfxml_link_state_ON)
1076 state_initial_link = SURF_LINK_ON;
1077 else if (A_surfxml_link_state ==
1078 A_surfxml_link_state_OFF)
1079 state_initial_link = SURF_LINK_OFF;
1081 if (A_surfxml_link_sharing_policy ==
1082 A_surfxml_link_sharing_policy_SHARED)
1083 policy_initial_link = SURF_LINK_SHARED;
1084 else if (A_surfxml_link_sharing_policy ==
1085 A_surfxml_link_sharing_policy_FATPIPE)
1086 policy_initial_link = SURF_LINK_FATPIPE;
1088 surf_parse_get_trace(&state_trace, A_surfxml_link_state_file);
1090 current_property_set = xbt_dict_new();
1091 link_new(name_link, bw_initial, bw_trace,
1092 lat_initial, lat_trace, state_initial_link, state_trace,
1093 policy_initial_link,/*add properties*/current_property_set);
1096 static void route_new(int src_id, int dst_id,
1097 link_KCCFLN05_t * link_list, int nb_link,
1098 double impact_on_src, double impact_on_dst,
1099 double impact_on_src_with_other_recv,
1100 double impact_on_dst_with_other_send)
1102 route_KCCFLN05_t route = &(ROUTE(src_id, dst_id));
1104 route->size = nb_link;
1105 route->links = link_list = xbt_realloc(link_list, sizeof(link_KCCFLN05_t) * nb_link);
1106 route->impact_on_src = impact_on_src;
1107 route->impact_on_dst = impact_on_dst;
1108 route->impact_on_src_with_other_recv = impact_on_src_with_other_recv;
1109 route->impact_on_dst_with_other_send = impact_on_dst_with_other_send;
1114 static int link_list_capacity;
1115 static link_KCCFLN05_t *link_list = NULL;
1116 static int src_id = -1;
1117 static int dst_id = -1;
1118 static double impact_on_src;
1119 static double impact_on_dst;
1120 static double impact_on_src_with_other_recv;
1121 static double impact_on_dst_with_other_send;
1122 static int is_first = 1;
1124 static void parse_route_set_endpoints(void)
1126 cpu_KCCFLN05_t cpu_tmp = NULL;
1128 if (is_first) create_routing_table();
1131 cpu_tmp = (cpu_KCCFLN05_t) name_service(A_surfxml_route_src);
1132 if (cpu_tmp != NULL) {
1133 src_id = cpu_tmp->id;
1135 xbt_assert1(xbt_dict_get_or_null(router_set, A_surfxml_route_src),
1136 "Invalid name '%s': neither a cpu nor a router!",
1137 A_surfxml_route_src);
1142 cpu_tmp = (cpu_KCCFLN05_t) name_service(A_surfxml_route_dst);
1143 if (cpu_tmp != NULL) {
1144 dst_id = cpu_tmp->id;
1146 xbt_assert1(xbt_dict_get_or_null(router_set, A_surfxml_route_dst),
1147 "Invalid name '%s': neither a cpu nor a router!",
1148 A_surfxml_route_dst);
1153 surf_parse_get_double(&impact_on_src, A_surfxml_route_impact_on_src);
1154 surf_parse_get_double(&impact_on_dst, A_surfxml_route_impact_on_dst);
1155 surf_parse_get_double(&impact_on_src_with_other_recv,
1156 A_surfxml_route_impact_on_src_with_other_recv);
1157 surf_parse_get_double(&impact_on_dst_with_other_send,
1158 A_surfxml_route_impact_on_dst_with_other_send);
1161 link_list_capacity = 1;
1162 link_list = xbt_new(link_KCCFLN05_t, link_list_capacity);
1166 static void parse_route_elem(void)
1169 if (nb_link == link_list_capacity) {
1170 link_list_capacity *= 2;
1172 xbt_realloc(link_list,
1173 (link_list_capacity) *
1174 sizeof(link_KCCFLN05_t));
1177 link_list[nb_link++] =
1178 xbt_dict_get(link_set, A_surfxml_link_c_ctn_id);
1181 RETHROW1("Link %s not found (dict raised this exception: %s)",
1182 A_surfxml_link_c_ctn_id);
1186 static void parse_route_set_route(void)
1188 if (src_id != -1 && dst_id != -1)
1189 route_new(src_id, dst_id, link_list, nb_link, impact_on_src,
1190 impact_on_dst, impact_on_src_with_other_recv,
1191 impact_on_dst_with_other_send);
1196 static void parse_file(const char *file)
1200 CDEBUG0(surf_parse, "Use the KCCFKN05 model");
1202 /* Adding callback functions */
1203 surf_parse_reset_parser();
1204 surfxml_add_callback(STag_surfxml_host_cb_list, &parse_cpu_init);
1205 surfxml_add_callback(STag_surfxml_prop_cb_list, &parse_properties);
1206 surfxml_add_callback(STag_surfxml_router_cb_list, &parse_routers);
1207 surfxml_add_callback(STag_surfxml_link_cb_list, &parse_link_init);
1208 surfxml_add_callback(STag_surfxml_route_cb_list, &parse_route_set_endpoints);
1209 surfxml_add_callback(ETag_surfxml_link_c_ctn_cb_list, &parse_route_elem);
1210 surfxml_add_callback(ETag_surfxml_route_cb_list, &parse_route_set_route);
1212 /* Parse the file */
1213 surf_parse_open(file);
1214 xbt_assert1((!surf_parse()), "Parse error in %s", file);
1217 /* Adding loopback if needed */
1218 for (i = 0; i < nb_workstation; i++)
1219 if (!ROUTE(i, i).size) {
1221 loopback = link_new(xbt_strdup("__MSG_loopback__"),
1222 498000000, NULL, 0.000015, NULL,
1224 SURF_LINK_FATPIPE, NULL);
1225 ROUTE(i, i).size = 1;
1226 ROUTE(i, i).links = xbt_new0(link_KCCFLN05_t, 1);
1227 ROUTE(i, i).links[0] = loopback;
1232 /**************************************/
1233 /********* Module creation ***********/
1234 /**************************************/
1236 static void model_init_internal(void)
1238 s_surf_action_t action;
1240 surf_workstation_model = xbt_new0(s_surf_workstation_model_t, 1);
1242 surf_workstation_model->common_private =
1243 xbt_new0(s_surf_model_private_t, 1);
1244 surf_workstation_model->common_public =
1245 xbt_new0(s_surf_model_public_t, 1);
1246 surf_workstation_model->extension_public =
1247 xbt_new0(s_surf_workstation_model_extension_public_t, 1);
1249 surf_workstation_model->common_public->states.ready_action_set =
1250 xbt_swag_new(xbt_swag_offset(action, state_hookup));
1251 surf_workstation_model->common_public->states.running_action_set =
1252 xbt_swag_new(xbt_swag_offset(action, state_hookup));
1253 surf_workstation_model->common_public->states.failed_action_set =
1254 xbt_swag_new(xbt_swag_offset(action, state_hookup));
1255 surf_workstation_model->common_public->states.done_action_set =
1256 xbt_swag_new(xbt_swag_offset(action, state_hookup));
1258 surf_workstation_model->common_public->name_service = name_service;
1259 surf_workstation_model->common_public->get_resource_name =
1261 surf_workstation_model->common_public->action_get_state =
1262 surf_action_get_state;
1263 surf_workstation_model->common_public->action_get_start_time =
1264 surf_action_get_start_time;
1265 surf_workstation_model->common_public->action_get_finish_time =
1266 surf_action_get_finish_time;
1267 surf_workstation_model->common_public->action_use = action_use;
1268 surf_workstation_model->common_public->action_free = action_free;
1269 surf_workstation_model->common_public->action_cancel = action_cancel;
1270 surf_workstation_model->common_public->action_recycle =
1272 surf_workstation_model->common_public->action_change_state =
1273 surf_action_change_state;
1274 surf_workstation_model->common_public->action_set_data =
1275 surf_action_set_data;
1276 surf_workstation_model->common_public->suspend = action_suspend;
1277 surf_workstation_model->common_public->resume = action_resume;
1278 surf_workstation_model->common_public->is_suspended =
1279 action_is_suspended;
1280 surf_workstation_model->common_public->set_max_duration =
1281 action_set_max_duration;
1282 surf_workstation_model->common_public->set_priority =
1283 action_set_priority;
1284 surf_workstation_model->common_public->name = "Workstation KCCFLN05";
1286 surf_workstation_model->common_private->resource_used = resource_used;
1287 surf_workstation_model->common_private->share_resources =
1289 surf_workstation_model->common_private->update_actions_state =
1290 update_actions_state;
1291 surf_workstation_model->common_private->update_resource_state =
1292 update_resource_state;
1293 surf_workstation_model->common_private->finalize = finalize;
1295 surf_workstation_model->extension_public->execute = execute;
1296 surf_workstation_model->extension_public->sleep = action_sleep;
1297 surf_workstation_model->extension_public->get_state =
1299 surf_workstation_model->extension_public->get_speed = get_speed;
1300 surf_workstation_model->extension_public->get_available_speed =
1301 get_available_speed;
1303 surf_workstation_model->common_public->get_properties = get_properties;
1305 surf_workstation_model->extension_public->communicate = communicate;
1306 surf_workstation_model->extension_public->execute_parallel_task =
1307 execute_parallel_task;
1308 surf_workstation_model->extension_public->get_route = get_route;
1309 surf_workstation_model->extension_public->get_route_size =
1311 surf_workstation_model->extension_public->get_link_name =
1313 surf_workstation_model->extension_public->get_link_bandwidth =
1315 surf_workstation_model->extension_public->get_link_latency =
1318 workstation_set = xbt_dict_new();
1319 router_set = xbt_dict_new();
1320 link_set = xbt_dict_new();
1322 maxmin_system = lmm_system_new();
1325 /**************************************/
1326 /*************** Generic **************/
1327 /**************************************/
1328 void surf_workstation_model_init_KCCFLN05(const char *filename)
1330 xbt_assert0(!surf_cpu_model, "CPU model type already defined");
1331 xbt_assert0(!surf_network_model,
1332 "network model type already defined");
1333 model_init_internal();
1334 parse_file(filename);
1336 xbt_dynar_push(model_list, &surf_workstation_model);