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)");
16 SURF_WORKSTATION_RESOURCE_CPU,
17 SURF_WORKSTATION_RESOURCE_LINK,
18 } e_surf_workstation_model_type_t;
21 /**************************************/
22 /********* router object **************/
23 /**************************************/
24 typedef struct router_KCCFLN05 {
27 } s_router_KCCFLN05_t, *router_KCCFLN05_t;
30 /**************************************/
31 /********* cpu object *****************/
32 /**************************************/
33 typedef struct cpu_KCCFLN05 {
35 e_surf_workstation_model_type_t type; /* Do not move this field */
36 char *name; /* Do not move this field */
37 lmm_constraint_t constraint;
41 double interference_send;
42 double interference_recv;
43 double interference_send_recv;
44 tmgr_trace_event_t power_event;
45 e_surf_cpu_state_t state_current;
46 tmgr_trace_event_t state_event;
47 int id; /* cpu and network card are a single object... */
48 xbt_dynar_t incomming_communications;
49 xbt_dynar_t outgoing_communications;
50 } s_cpu_KCCFLN05_t, *cpu_KCCFLN05_t;
52 /**************************************/
53 /*********** network object ***********/
54 /**************************************/
56 typedef struct network_link_KCCFLN05 {
58 e_surf_workstation_model_type_t type; /* Do not move this field */
59 char *name; /* Do not move this field */
60 lmm_constraint_t constraint;
62 tmgr_trace_event_t lat_event;
64 tmgr_trace_event_t bw_event;
65 e_surf_network_link_state_t state_current;
66 tmgr_trace_event_t state_event;
67 } s_network_link_KCCFLN05_t, *network_link_KCCFLN05_t;
70 typedef struct s_route_KCCFLN05 {
73 double impact_on_src_with_other_recv;
74 double impact_on_dst_with_other_send;
75 network_link_KCCFLN05_t *links;
77 } s_route_KCCFLN05_t, *route_KCCFLN05_t;
79 /**************************************/
80 /*************** actions **************/
81 /**************************************/
82 typedef struct surf_action_workstation_KCCFLN05 {
83 s_surf_action_t generic_action;
86 lmm_variable_t variable;
89 cpu_KCCFLN05_t src; /* could be avoided */
90 cpu_KCCFLN05_t dst; /* could be avoided */
91 } s_surf_action_workstation_KCCFLN05_t,
92 *surf_action_workstation_KCCFLN05_t;
96 static int nb_workstation = 0;
97 static s_route_KCCFLN05_t *routing_table = NULL;
98 #define ROUTE(i,j) routing_table[(i)+(j)*nb_workstation]
99 static network_link_KCCFLN05_t loopback = NULL;
100 static xbt_dict_t parallel_task_network_link_set = NULL;
101 //added to work with GTNETS
102 static xbt_dict_t router_set = NULL;
103 static lmm_system_t maxmin_system = NULL;
104 /*xbt_dict_t network_link_set = NULL;*/
107 /* convenient function */
108 static void __update_cpu_usage(cpu_KCCFLN05_t cpu)
111 surf_action_workstation_KCCFLN05_t action = NULL;
112 if ((!xbt_dynar_length(cpu->incomming_communications)) &&
113 (!xbt_dynar_length(cpu->outgoing_communications))) {
114 /* No communications */
115 lmm_update_constraint_bound(maxmin_system, cpu->constraint,
116 cpu->power_current * cpu->power_scale);
117 } else if ((!xbt_dynar_length(cpu->incomming_communications))
118 && (xbt_dynar_length(cpu->outgoing_communications))) {
120 lmm_update_constraint_bound(maxmin_system, cpu->constraint,
121 cpu->power_current * cpu->power_scale *
122 cpu->interference_send);
123 xbt_dynar_foreach(cpu->outgoing_communications, cpt, action)
124 lmm_elem_set_value(maxmin_system, cpu->constraint,
126 cpu->power_current * cpu->power_scale *
127 ROUTE(action->src->id,
128 action->dst->id).impact_on_src);
129 } else if ((xbt_dynar_length(cpu->incomming_communications))
130 && (!xbt_dynar_length(cpu->outgoing_communications))) {
132 lmm_update_constraint_bound(maxmin_system, cpu->constraint,
133 cpu->power_current * cpu->power_scale *
134 cpu->interference_recv);
135 xbt_dynar_foreach(cpu->incomming_communications, cpt, action)
136 lmm_elem_set_value(maxmin_system, cpu->constraint,
138 cpu->power_current * cpu->power_scale *
139 ROUTE(action->src->id,
140 action->dst->id).impact_on_dst);
142 /* Emission & Reception */
143 lmm_update_constraint_bound(maxmin_system, cpu->constraint,
144 cpu->power_current * cpu->power_scale *
145 cpu->interference_send_recv);
146 xbt_dynar_foreach(cpu->outgoing_communications, cpt, action)
147 lmm_elem_set_value(maxmin_system, cpu->constraint,
149 cpu->power_current * cpu->power_scale *
150 ROUTE(action->src->id,
152 impact_on_src_with_other_recv);
153 xbt_dynar_foreach(cpu->incomming_communications, cpt, action)
154 lmm_elem_set_value(maxmin_system, cpu->constraint,
156 cpu->power_current * cpu->power_scale *
157 ROUTE(action->src->id,
159 impact_on_dst_with_other_send);
163 /**************************************/
164 /******* Resource Public **********/
165 /**************************************/
167 static void *name_service(const char *name)
173 res = xbt_dict_get(workstation_set, name);
175 if (e.category != not_found_error)
177 WARN1("Host '%s' not found, verifing if it is a router", name);
185 static const char *get_resource_name(void *resource_id)
187 /* We can freely cast as a cpu_KCCFLN05_t because it has the same
188 prefix as network_link_KCCFLN05_t. However, only cpu_KCCFLN05_t
189 will theoretically be given as an argument here. */
190 return ((cpu_KCCFLN05_t) resource_id)->name;
193 /* action_get_state is inherited from the surf module */
195 static void action_use(surf_action_t action)
201 static int action_free(surf_action_t action)
204 surf_action_t act = NULL;
205 cpu_KCCFLN05_t src = ((surf_action_workstation_KCCFLN05_t) action)->src;
206 cpu_KCCFLN05_t dst = ((surf_action_workstation_KCCFLN05_t) action)->dst;
209 if (!action->using) {
210 xbt_swag_remove(action, action->state_set);
211 if (((surf_action_workstation_KCCFLN05_t) action)->variable)
212 lmm_variable_free(maxmin_system,
213 ((surf_action_workstation_KCCFLN05_t) action)->
216 xbt_dynar_foreach(src->outgoing_communications, cpt, act)
218 xbt_dynar_remove_at(src->outgoing_communications, cpt, &act);
223 xbt_dynar_foreach(dst->incomming_communications, cpt, act)
225 xbt_dynar_remove_at(dst->incomming_communications, cpt, &act);
229 if (src && (!xbt_dynar_length(src->outgoing_communications)))
230 __update_cpu_usage(src);
231 if (dst && (!xbt_dynar_length(dst->incomming_communications)))
232 __update_cpu_usage(dst);
240 static void action_cancel(surf_action_t action)
242 surf_action_change_state(action, SURF_ACTION_FAILED);
246 static void action_recycle(surf_action_t action)
252 /* action_change_state is inherited from the surf module */
253 /* action_set_data is inherited from the surf module */
255 static void action_suspend(surf_action_t action)
257 XBT_IN1("(%p))", action);
258 if (((surf_action_workstation_KCCFLN05_t) action)->suspended != 2) {
259 ((surf_action_workstation_KCCFLN05_t) action)->suspended = 1;
260 lmm_update_variable_weight(maxmin_system,
261 ((surf_action_workstation_KCCFLN05_t)
262 action)->variable, 0.0);
267 static void action_resume(surf_action_t action)
269 XBT_IN1("(%p)", action);
270 if (((surf_action_workstation_KCCFLN05_t) action)->suspended != 2) {
271 if (((surf_action_workstation_KCCFLN05_t) action)->lat_current == 0.0)
272 lmm_update_variable_weight(maxmin_system,
273 ((surf_action_workstation_KCCFLN05_t)
274 action)->variable, action->priority);
276 lmm_update_variable_weight(maxmin_system,
277 ((surf_action_workstation_KCCFLN05_t)
279 ((surf_action_workstation_KCCFLN05_t)
280 action)->lat_current);
282 ((surf_action_workstation_KCCFLN05_t) action)->suspended = 0;
287 static int action_is_suspended(surf_action_t action)
289 return (((surf_action_workstation_KCCFLN05_t) action)->suspended == 1);
292 static void action_set_max_duration(surf_action_t action, double duration)
293 { /* FIXME: should inherit */
294 XBT_IN2("(%p,%g)", action, duration);
295 action->max_duration = duration;
300 static void action_set_priority(surf_action_t action, double priority)
302 XBT_IN2("(%p,%g)", action, priority);
303 action->priority = priority;
304 lmm_update_variable_weight(maxmin_system, ((surf_action_workstation_KCCFLN05_t) action)->variable, priority);
309 /**************************************/
310 /******* Resource Private **********/
311 /**************************************/
313 static int resource_used(void *resource_id)
315 /* We can freely cast as a network_link_KCCFLN05_t because it has
316 the same prefix as cpu_KCCFLN05_t */
317 if (((cpu_KCCFLN05_t) resource_id)->type ==
318 SURF_WORKSTATION_RESOURCE_CPU)
319 return (lmm_constraint_used
320 (maxmin_system, ((cpu_KCCFLN05_t) resource_id)->constraint)
321 || ((((cpu_KCCFLN05_t) resource_id)->bus) ?
322 lmm_constraint_used(maxmin_system,
323 ((cpu_KCCFLN05_t) resource_id)->
326 return lmm_constraint_used(maxmin_system,
327 ((network_link_KCCFLN05_t) resource_id)->
332 static double share_resources(double now)
334 s_surf_action_workstation_KCCFLN05_t s_action;
335 surf_action_workstation_KCCFLN05_t action = NULL;
337 xbt_swag_t running_actions =
338 surf_workstation_model->common_public->states.running_action_set;
339 double min = generic_maxmin_share_resources2(running_actions,
340 xbt_swag_offset(s_action,
345 xbt_swag_foreach(action, running_actions) {
346 if (action->latency > 0) {
348 min = action->latency;
349 DEBUG3("Updating min (value) with %p (start %f): %f", action,
350 action->generic_action.start, min);
351 } else if (action->latency < min) {
352 min = action->latency;
353 DEBUG3("Updating min (latency) with %p (start %f): %f", action,
354 action->generic_action.start, min);
359 DEBUG1("min value : %f", min);
364 static void update_actions_state(double now, double delta)
367 surf_action_workstation_KCCFLN05_t action = NULL;
368 surf_action_workstation_KCCFLN05_t next_action = NULL;
369 xbt_swag_t running_actions =
370 surf_workstation_model->common_public->states.running_action_set;
372 xbt_swag_foreach_safe(action, next_action, running_actions) {
374 if (action->latency > 0) {
375 if (action->latency > deltap) {
376 double_update(&(action->latency), deltap);
379 double_update(&(deltap), action->latency);
380 action->latency = 0.0;
382 if ((action->latency == 0.0) && (action->suspended == 0)) {
383 if ((action)->lat_current == 0.0)
384 lmm_update_variable_weight(maxmin_system, action->variable, 1.0);
386 lmm_update_variable_weight(maxmin_system, action->variable,
387 action->lat_current);
390 DEBUG3("Action (%p) : remains (%g) updated by %g.",
391 action, action->generic_action.remains,
392 lmm_variable_getvalue(action->variable) * deltap);
393 double_update(&(action->generic_action.remains),
394 lmm_variable_getvalue(action->variable) * deltap);
396 if (action->generic_action.max_duration != NO_MAX_DURATION)
397 double_update(&(action->generic_action.max_duration), delta);
399 if ((action->generic_action.remains <= 0) &&
400 (lmm_get_variable_weight(action->variable) > 0)) {
401 action->generic_action.finish = surf_get_clock();
402 surf_action_change_state((surf_action_t) action, SURF_ACTION_DONE);
403 } else if ((action->generic_action.max_duration != NO_MAX_DURATION) &&
404 (action->generic_action.max_duration <= 0)) {
405 action->generic_action.finish = surf_get_clock();
406 surf_action_change_state((surf_action_t) action, SURF_ACTION_DONE);
408 /* Need to check that none of the resource has failed */
409 lmm_constraint_t cnst = NULL;
411 void *constraint_id = NULL;
414 lmm_get_cnst_from_var(maxmin_system, action->variable,
416 constraint_id = lmm_constraint_id(cnst);
418 /* if(((network_link_KCCFLN05_t)constraint_id)->type== */
419 /* SURF_WORKSTATION_RESOURCE_LINK) { */
420 /* DEBUG2("Checking for link %s (%p)", */
421 /* ((network_link_KCCFLN05_t)constraint_id)->name, */
422 /* ((network_link_KCCFLN05_t)constraint_id)); */
424 /* if(((cpu_KCCFLN05_t)constraint_id)->type== */
425 /* SURF_WORKSTATION_RESOURCE_CPU) { */
426 /* DEBUG3("Checking for cpu %s (%p) : %s", */
427 /* ((cpu_KCCFLN05_t)constraint_id)->name, */
428 /* ((cpu_KCCFLN05_t)constraint_id), */
429 /* ((cpu_KCCFLN05_t)constraint_id)->state_current==SURF_CPU_OFF?"Off":"On"); */
432 if (((((network_link_KCCFLN05_t) constraint_id)->type ==
433 SURF_WORKSTATION_RESOURCE_LINK) &&
434 (((network_link_KCCFLN05_t) constraint_id)->state_current ==
435 SURF_NETWORK_LINK_OFF)) ||
436 ((((cpu_KCCFLN05_t) constraint_id)->type ==
437 SURF_WORKSTATION_RESOURCE_CPU) &&
438 (((cpu_KCCFLN05_t) constraint_id)->state_current ==
440 DEBUG1("Action (%p) Failed!!", action);
441 action->generic_action.finish = surf_get_clock();
442 surf_action_change_state((surf_action_t) action,
452 static void update_resource_state(void *id,
453 tmgr_trace_event_t event_type,
456 cpu_KCCFLN05_t cpu = id;
457 network_link_KCCFLN05_t nw_link = id;
459 if (nw_link->type == SURF_WORKSTATION_RESOURCE_LINK) {
460 DEBUG2("Updating link %s (%p)", nw_link->name, nw_link);
461 if (event_type == nw_link->bw_event) {
462 nw_link->bw_current = value;
463 lmm_update_constraint_bound(maxmin_system, nw_link->constraint,
464 nw_link->bw_current);
465 } else if (event_type == nw_link->lat_event) {
466 double delta = value - nw_link->lat_current;
467 lmm_variable_t var = NULL;
468 surf_action_workstation_KCCFLN05_t action = NULL;
470 nw_link->lat_current = value;
471 while (lmm_get_var_from_cnst
472 (maxmin_system, nw_link->constraint, &var)) {
473 action = lmm_variable_id(var);
474 action->lat_current += delta;
475 if (action->rate < 0)
476 lmm_update_variable_bound(maxmin_system, action->variable,
477 SG_TCP_CTE_GAMMA / (2.0 *
481 lmm_update_variable_bound(maxmin_system, action->variable,
483 SG_TCP_CTE_GAMMA / (2.0 *
486 if (action->suspended == 0)
487 lmm_update_variable_weight(maxmin_system, action->variable,
488 action->lat_current);
489 lmm_update_variable_latency(maxmin_system, action->variable,
494 } else if (event_type == nw_link->state_event) {
496 nw_link->state_current = SURF_NETWORK_LINK_ON;
498 nw_link->state_current = SURF_NETWORK_LINK_OFF;
500 CRITICAL0("Unknown event ! \n");
504 } else if (cpu->type == SURF_WORKSTATION_RESOURCE_CPU) {
505 DEBUG3("Updating cpu %s (%p) with value %g", cpu->name, cpu, value);
506 if (event_type == cpu->power_event) {
507 cpu->power_current = value;
508 __update_cpu_usage(cpu);
509 } else if (event_type == cpu->state_event) {
511 cpu->state_current = SURF_CPU_ON;
513 cpu->state_current = SURF_CPU_OFF;
515 CRITICAL0("Unknown event ! \n");
525 static void finalize(void)
529 xbt_dict_free(&network_link_set);
530 xbt_dict_free(&workstation_set);
531 xbt_dict_free(&router_set);
532 if (parallel_task_network_link_set != NULL) {
533 xbt_dict_free(¶llel_task_network_link_set);
535 xbt_swag_free(surf_workstation_model->common_public->states.
537 xbt_swag_free(surf_workstation_model->common_public->states.
539 xbt_swag_free(surf_workstation_model->common_public->states.
541 xbt_swag_free(surf_workstation_model->common_public->states.
544 free(surf_workstation_model->common_public);
545 free(surf_workstation_model->common_private);
546 free(surf_workstation_model->extension_public);
548 free(surf_workstation_model);
549 surf_workstation_model = NULL;
551 for (i = 0; i < nb_workstation; i++)
552 for (j = 0; j < nb_workstation; j++)
553 free(ROUTE(i, j).links);
555 routing_table = NULL;
559 lmm_system_free(maxmin_system);
560 maxmin_system = NULL;
564 /**************************************/
565 /******* Resource Private **********/
566 /**************************************/
568 static surf_action_t execute(void *cpu, double size)
570 surf_action_workstation_KCCFLN05_t action = NULL;
571 cpu_KCCFLN05_t CPU = cpu;
573 XBT_IN2("(%s,%g)", CPU->name, size);
574 action = xbt_new0(s_surf_action_workstation_KCCFLN05_t, 1);
576 action->generic_action.using = 1;
577 action->generic_action.cost = size;
578 action->generic_action.remains = size;
579 action->generic_action.priority = 1.0;
580 action->generic_action.max_duration = NO_MAX_DURATION;
581 action->generic_action.start = surf_get_clock();
582 action->generic_action.finish = -1.0;
583 action->generic_action.model_type =
584 (surf_model_t) surf_workstation_model;
585 action->suspended = 0;
587 if (CPU->state_current == SURF_CPU_ON)
588 action->generic_action.state_set =
589 surf_workstation_model->common_public->states.
592 action->generic_action.state_set =
593 surf_workstation_model->common_public->states.failed_action_set;
594 xbt_swag_insert(action, action->generic_action.state_set);
596 action->variable = lmm_variable_new(maxmin_system, action,
597 action->generic_action.priority,
599 lmm_expand(maxmin_system, CPU->constraint, action->variable, 1.0);
601 return (surf_action_t) action;
604 static surf_action_t action_sleep(void *cpu, double duration)
606 surf_action_workstation_KCCFLN05_t action = NULL;
608 XBT_IN2("(%s,%g)", ((cpu_KCCFLN05_t) cpu)->name, duration);
610 action = (surf_action_workstation_KCCFLN05_t) execute(cpu, 1.0);
611 action->generic_action.max_duration = duration;
612 action->suspended = 2;
613 lmm_update_variable_weight(maxmin_system, action->variable, 0.0);
616 return (surf_action_t) action;
619 static e_surf_cpu_state_t resource_get_state(void *cpu)
621 return ((cpu_KCCFLN05_t) cpu)->state_current;
624 static double get_speed(void *cpu, double load)
626 return load * (((cpu_KCCFLN05_t) cpu)->power_scale);
629 static double get_available_speed(void *cpu)
631 return ((cpu_KCCFLN05_t) cpu)->power_current;
635 static surf_action_t communicate(void *src, void *dst, double size,
638 surf_action_workstation_KCCFLN05_t action = NULL;
639 cpu_KCCFLN05_t card_src = src;
640 cpu_KCCFLN05_t card_dst = dst;
641 route_KCCFLN05_t route = &(ROUTE(card_src->id, card_dst->id));
642 int route_size = route->size;
645 XBT_IN4("(%s,%s,%g,%g)", card_src->name, card_dst->name, size, rate);
646 xbt_assert2(route_size,
647 "You're trying to send data from %s to %s but there is no connexion between these two cards.",
648 card_src->name, card_dst->name);
650 action = xbt_new0(s_surf_action_workstation_KCCFLN05_t, 1);
652 action->generic_action.using = 1;
653 action->generic_action.cost = size;
654 action->generic_action.remains = size;
655 action->generic_action.max_duration = NO_MAX_DURATION;
656 action->generic_action.start = surf_get_clock();
657 action->generic_action.finish = -1.0;
660 action->generic_action.model_type =
661 (surf_model_t) surf_workstation_model;
662 action->suspended = 0; /* Should be useless because of the
663 calloc but it seems to help valgrind... */
664 action->generic_action.state_set =
665 surf_workstation_model->common_public->states.running_action_set;
667 xbt_dynar_push(card_src->outgoing_communications, &action);
668 xbt_dynar_push(card_dst->incomming_communications, &action);
670 xbt_swag_insert(action, action->generic_action.state_set);
673 action->latency = 0.0;
674 for (i = 0; i < route_size; i++)
675 action->latency += route->links[i]->lat_current;
676 action->lat_current = action->latency;
678 if (action->latency > 0)
679 action->variable = lmm_variable_new(maxmin_system, action, 0.0, -1.0, route_size + 4); /* +1 for the src bus
682 +1 for the dst cpu */
684 action->variable = lmm_variable_new(maxmin_system, action, 1.0, -1.0,
687 if (action->rate < 0) {
688 if (action->lat_current > 0)
689 lmm_update_variable_bound(maxmin_system, action->variable,
690 SG_TCP_CTE_GAMMA / (2.0 *
691 action->lat_current));
693 lmm_update_variable_bound(maxmin_system, action->variable, -1.0);
695 if (action->lat_current > 0)
696 lmm_update_variable_bound(maxmin_system, action->variable,
698 SG_TCP_CTE_GAMMA / (2.0 *
702 lmm_update_variable_bound(maxmin_system, action->variable,
706 lmm_update_variable_latency(maxmin_system, action->variable,
707 action->latency); /* Should be useless */
709 for (i = 0; i < route_size; i++)
710 lmm_expand(maxmin_system, route->links[i]->constraint,
711 action->variable, 1.0);
713 lmm_expand(maxmin_system, card_src->bus, action->variable, 1.0);
715 lmm_expand(maxmin_system, card_dst->bus, action->variable, 1.0);
716 lmm_expand(maxmin_system, card_src->constraint, action->variable, 0.0);
717 lmm_expand(maxmin_system, card_dst->constraint, action->variable, 0.0);
720 return (surf_action_t) action;
723 static surf_action_t execute_parallel_task(int workstation_nb,
724 void **workstation_list,
725 double *computation_amount,
726 double *communication_amount,
727 double amount, double rate)
729 surf_action_workstation_KCCFLN05_t action = NULL;
734 if (parallel_task_network_link_set == NULL) {
735 parallel_task_network_link_set =
736 xbt_dict_new_ext(workstation_nb * workstation_nb * 10);
739 /* Compute the number of affected resources... */
740 for (i = 0; i < workstation_nb; i++) {
741 for (j = 0; j < workstation_nb; j++) {
742 cpu_KCCFLN05_t card_src = workstation_list[i];
743 cpu_KCCFLN05_t card_dst = workstation_list[j];
744 int route_size = ROUTE(card_src->id, card_dst->id).size;
745 network_link_KCCFLN05_t *route =
746 ROUTE(card_src->id, card_dst->id).links;
748 if (communication_amount[i * workstation_nb + j] > 0)
749 for (k = 0; k < route_size; k++) {
750 xbt_dict_set(parallel_task_network_link_set, route[k]->name,
755 nb_link = xbt_dict_length(parallel_task_network_link_set);
756 xbt_dict_reset(parallel_task_network_link_set);
759 for (i = 0; i < workstation_nb; i++)
760 if (computation_amount[i] > 0)
763 action = xbt_new0(s_surf_action_workstation_KCCFLN05_t, 1);
764 DEBUG3("Creating a parallel task (%p) with %d cpus and %d links.",
765 action, nb_host, nb_link);
766 action->generic_action.using = 1;
767 action->generic_action.cost = amount;
768 action->generic_action.remains = amount;
769 action->generic_action.max_duration = NO_MAX_DURATION;
770 action->generic_action.start = surf_get_clock();
771 action->generic_action.finish = -1.0;
772 action->generic_action.model_type =
773 (surf_model_t) surf_workstation_model;
774 action->suspended = 0; /* Should be useless because of the
775 calloc but it seems to help valgrind... */
776 action->generic_action.state_set =
777 surf_workstation_model->common_public->states.running_action_set;
779 xbt_swag_insert(action, action->generic_action.state_set);
782 if (action->rate > 0)
783 action->variable = lmm_variable_new(maxmin_system, action, 1.0, -1.0,
787 lmm_variable_new(maxmin_system, action, 1.0, action->rate,
790 for (i = 0; i < workstation_nb; i++)
791 if (computation_amount[i] > 0)
792 lmm_expand(maxmin_system,
793 ((cpu_KCCFLN05_t) workstation_list[i])->constraint,
794 action->variable, computation_amount[i]);
796 for (i = 0; i < workstation_nb; i++) {
797 for (j = 0; j < workstation_nb; j++) {
798 cpu_KCCFLN05_t card_src = workstation_list[i];
799 cpu_KCCFLN05_t card_dst = workstation_list[j];
800 int route_size = ROUTE(card_src->id, card_dst->id).size;
801 network_link_KCCFLN05_t *route =
802 ROUTE(card_src->id, card_dst->id).links;
804 for (k = 0; k < route_size; k++) {
805 if (communication_amount[i * workstation_nb + j] > 0) {
806 lmm_expand_add(maxmin_system, route[k]->constraint,
808 communication_amount[i * workstation_nb + j]);
814 if (nb_link + nb_host == 0) {
815 action->generic_action.cost = 1.0;
816 action->generic_action.remains = 0.0;
819 return (surf_action_t) action;
822 /* returns an array of network_link_KCCFLN05_t */
823 static const void **get_route(void *src, void *dst)
825 cpu_KCCFLN05_t card_src = src;
826 cpu_KCCFLN05_t card_dst = dst;
827 route_KCCFLN05_t route = &(ROUTE(card_src->id, card_dst->id));
829 return (const void **) route->links;
832 static int get_route_size(void *src, void *dst)
834 cpu_KCCFLN05_t card_src = src;
835 cpu_KCCFLN05_t card_dst = dst;
836 route_KCCFLN05_t route = &(ROUTE(card_src->id, card_dst->id));
840 static const char *get_link_name(const void *link)
842 return ((network_link_KCCFLN05_t) link)->name;
845 static double get_link_bandwidth(const void *link)
847 return ((network_link_KCCFLN05_t) link)->bw_current;
850 static double get_link_latency(const void *link)
852 return ((network_link_KCCFLN05_t) link)->lat_current;
855 /**************************************/
856 /*** Resource Creation & Destruction **/
857 /**************************************/
860 static void router_free(void *router)
862 free(((router_KCCFLN05_t) router)->name);
865 static void router_new(const char *name)
867 static unsigned int nb_routers = 0;
869 INFO1("Creating a router %s", name);
871 router_KCCFLN05_t router;
872 router = xbt_new0(s_router_KCCFLN05_t, 1);
874 router->name = xbt_strdup(name);
875 router->id = nb_routers++;
876 xbt_dict_set(router_set, name, router, router_free);
879 static void parse_routers(void)
881 //add a dumb router just to be GTNETS compatible
882 router_new(A_surfxml_router_name);
885 static void cpu_free(void *cpu)
887 free(((cpu_KCCFLN05_t) cpu)->name);
888 xbt_dynar_free(&(((cpu_KCCFLN05_t) cpu)->incomming_communications));
889 xbt_dynar_free(&(((cpu_KCCFLN05_t) cpu)->outgoing_communications));
893 static cpu_KCCFLN05_t cpu_new(const char *name, double power_scale,
894 double power_initial,
895 tmgr_trace_t power_trace,
896 e_surf_cpu_state_t state_initial,
897 tmgr_trace_t state_trace,
898 double interference_send,
899 double interference_recv,
900 double interference_send_recv,
901 double max_outgoing_rate)
903 cpu_KCCFLN05_t cpu = xbt_new0(s_cpu_KCCFLN05_t, 1);
905 cpu->model = (surf_model_t) surf_workstation_model;
906 cpu->type = SURF_WORKSTATION_RESOURCE_CPU;
907 cpu->name = xbt_strdup(name);
908 cpu->id = nb_workstation++;
910 cpu->power_scale = power_scale;
911 xbt_assert0(cpu->power_scale > 0, "Power has to be >0");
913 cpu->power_current = power_initial;
916 tmgr_history_add_trace(history, power_trace, 0.0, 0, cpu);
918 cpu->state_current = state_initial;
921 tmgr_history_add_trace(history, state_trace, 0.0, 0, cpu);
923 cpu->interference_send = interference_send;
924 cpu->interference_recv = interference_recv;
925 cpu->interference_send_recv = interference_send_recv;
928 lmm_constraint_new(maxmin_system, cpu,
929 cpu->power_current * cpu->power_scale);
930 if (max_outgoing_rate > 0)
931 cpu->bus = lmm_constraint_new(maxmin_system, cpu, max_outgoing_rate);
933 cpu->incomming_communications =
934 xbt_dynar_new(sizeof(surf_action_workstation_KCCFLN05_t), NULL);
935 cpu->outgoing_communications =
936 xbt_dynar_new(sizeof(surf_action_workstation_KCCFLN05_t), NULL);
938 xbt_dict_set(workstation_set, name, cpu, cpu_free);
943 static void parse_cpu(void)
945 double power_scale = 0.0;
946 double power_initial = 0.0;
947 tmgr_trace_t power_trace = NULL;
948 e_surf_cpu_state_t state_initial = SURF_CPU_OFF;
949 tmgr_trace_t state_trace = NULL;
950 double interference_send = 0.0;
951 double interference_recv = 0.0;
952 double interference_send_recv = 0.0;
953 double max_outgoing_rate = -1.0;
955 surf_parse_get_double(&power_scale, A_surfxml_cpu_power);
956 surf_parse_get_double(&power_initial, A_surfxml_cpu_availability);
957 surf_parse_get_trace(&power_trace, A_surfxml_cpu_availability_file);
959 xbt_assert0((A_surfxml_cpu_state == A_surfxml_cpu_state_ON) ||
960 (A_surfxml_cpu_state == A_surfxml_cpu_state_OFF),
962 if (A_surfxml_cpu_state == A_surfxml_cpu_state_ON)
963 state_initial = SURF_CPU_ON;
964 if (A_surfxml_cpu_state == A_surfxml_cpu_state_OFF)
965 state_initial = SURF_CPU_OFF;
966 surf_parse_get_trace(&state_trace, A_surfxml_cpu_state_file);
968 surf_parse_get_double(&interference_send,
969 A_surfxml_cpu_interference_send);
970 surf_parse_get_double(&interference_recv,
971 A_surfxml_cpu_interference_recv);
972 surf_parse_get_double(&interference_send_recv,
973 A_surfxml_cpu_interference_send_recv);
974 surf_parse_get_double(&max_outgoing_rate,
975 A_surfxml_cpu_max_outgoing_rate);
977 cpu_new(A_surfxml_cpu_name, power_scale, power_initial, power_trace,
978 state_initial, state_trace, interference_send, interference_recv,
979 interference_send_recv, max_outgoing_rate);
982 static void create_routing_table(void)
985 xbt_new0(s_route_KCCFLN05_t, nb_workstation * nb_workstation);
988 static void network_link_free(void *nw_link)
990 free(((network_link_KCCFLN05_t) nw_link)->name);
994 static network_link_KCCFLN05_t network_link_new(char *name,
996 tmgr_trace_t bw_trace,
998 tmgr_trace_t lat_trace,
999 e_surf_network_link_state_t
1001 tmgr_trace_t state_trace,
1002 e_surf_network_link_sharing_policy_t
1005 network_link_KCCFLN05_t nw_link = xbt_new0(s_network_link_KCCFLN05_t, 1);
1008 nw_link->model = (surf_model_t) surf_workstation_model;
1009 nw_link->type = SURF_WORKSTATION_RESOURCE_LINK;
1010 nw_link->name = name;
1011 nw_link->bw_current = bw_initial;
1014 tmgr_history_add_trace(history, bw_trace, 0.0, 0, nw_link);
1015 nw_link->state_current = state_initial;
1016 nw_link->lat_current = lat_initial;
1018 nw_link->lat_event =
1019 tmgr_history_add_trace(history, lat_trace, 0.0, 0, nw_link);
1021 nw_link->state_event =
1022 tmgr_history_add_trace(history, state_trace, 0.0, 0, nw_link);
1024 nw_link->constraint =
1025 lmm_constraint_new(maxmin_system, nw_link, nw_link->bw_current);
1027 if (policy == SURF_NETWORK_LINK_FATPIPE)
1028 lmm_constraint_shared(nw_link->constraint);
1030 xbt_dict_set(network_link_set, name, nw_link, network_link_free);
1035 static void parse_network_link(void)
1039 tmgr_trace_t bw_trace;
1041 tmgr_trace_t lat_trace;
1042 e_surf_network_link_state_t state_initial = SURF_NETWORK_LINK_ON;
1043 e_surf_network_link_sharing_policy_t policy_initial =
1044 SURF_NETWORK_LINK_SHARED;
1045 tmgr_trace_t state_trace;
1047 name = xbt_strdup(A_surfxml_network_link_name);
1048 surf_parse_get_double(&bw_initial, A_surfxml_network_link_bandwidth);
1049 surf_parse_get_trace(&bw_trace, A_surfxml_network_link_bandwidth_file);
1050 surf_parse_get_double(&lat_initial, A_surfxml_network_link_latency);
1051 surf_parse_get_trace(&lat_trace, A_surfxml_network_link_latency_file);
1053 xbt_assert0((A_surfxml_network_link_state ==
1054 A_surfxml_network_link_state_ON)
1055 || (A_surfxml_network_link_state ==
1056 A_surfxml_network_link_state_OFF), "Invalid state");
1057 if (A_surfxml_network_link_state == A_surfxml_network_link_state_ON)
1058 state_initial = SURF_NETWORK_LINK_ON;
1059 else if (A_surfxml_network_link_state ==
1060 A_surfxml_network_link_state_OFF)
1061 state_initial = SURF_NETWORK_LINK_OFF;
1063 if (A_surfxml_network_link_sharing_policy ==
1064 A_surfxml_network_link_sharing_policy_SHARED)
1065 policy_initial = SURF_NETWORK_LINK_SHARED;
1066 else if (A_surfxml_network_link_sharing_policy ==
1067 A_surfxml_network_link_sharing_policy_FATPIPE)
1068 policy_initial = SURF_NETWORK_LINK_FATPIPE;
1070 surf_parse_get_trace(&state_trace, A_surfxml_network_link_state_file);
1072 network_link_new(name, bw_initial, bw_trace,
1073 lat_initial, lat_trace, state_initial, state_trace,
1077 static void route_new(int src_id, int dst_id,
1078 network_link_KCCFLN05_t * link_list, int nb_link,
1079 double impact_on_src, double impact_on_dst,
1080 double impact_on_src_with_other_recv,
1081 double impact_on_dst_with_other_send)
1083 route_KCCFLN05_t route = &(ROUTE(src_id, dst_id));
1085 route->size = nb_link;
1086 route->links = link_list =
1087 xbt_realloc(link_list, sizeof(network_link_KCCFLN05_t) * nb_link);
1088 route->impact_on_src = impact_on_src;
1089 route->impact_on_dst = impact_on_src;
1090 route->impact_on_src_with_other_recv = impact_on_src_with_other_recv;
1091 route->impact_on_dst_with_other_send = impact_on_dst_with_other_send;
1095 static int link_list_capacity;
1096 static network_link_KCCFLN05_t *link_list = NULL;
1097 static int src_id = -1;
1098 static int dst_id = -1;
1099 static double impact_on_src;
1100 static double impact_on_dst;
1101 static double impact_on_src_with_other_recv;
1102 static double impact_on_dst_with_other_send;
1104 static void parse_route_set_endpoints(void)
1106 cpu_KCCFLN05_t cpu_tmp = NULL;
1108 cpu_tmp = (cpu_KCCFLN05_t) name_service(A_surfxml_route_src);
1109 if (cpu_tmp != NULL) {
1110 src_id = cpu_tmp->id;
1112 xbt_assert1(xbt_dict_get_or_null(router_set, A_surfxml_route_src),
1113 "Invalid name '%s': neither a cpu nor a router!",
1114 A_surfxml_route_src);
1119 cpu_tmp = (cpu_KCCFLN05_t) name_service(A_surfxml_route_dst);
1120 if (cpu_tmp != NULL) {
1121 dst_id = cpu_tmp->id;
1123 xbt_assert1(xbt_dict_get_or_null(router_set, A_surfxml_route_dst),
1124 "Invalid name '%s': neither a cpu nor a router!",
1125 A_surfxml_route_dst);
1130 surf_parse_get_double(&impact_on_src, A_surfxml_route_impact_on_src);
1131 surf_parse_get_double(&impact_on_dst, A_surfxml_route_impact_on_dst);
1132 surf_parse_get_double(&impact_on_src_with_other_recv,
1133 A_surfxml_route_impact_on_src_with_other_recv);
1134 surf_parse_get_double(&impact_on_dst_with_other_send,
1135 A_surfxml_route_impact_on_dst_with_other_send);
1138 link_list_capacity = 1;
1139 link_list = xbt_new(network_link_KCCFLN05_t, link_list_capacity);
1143 static void parse_route_elem(void)
1146 if (nb_link == link_list_capacity) {
1147 link_list_capacity *= 2;
1149 xbt_realloc(link_list,
1150 (link_list_capacity) *
1151 sizeof(network_link_KCCFLN05_t));
1154 link_list[nb_link++] =
1155 xbt_dict_get(network_link_set, A_surfxml_route_element_name);
1158 RETHROW1("Link %s not found (dict raised this exception: %s)",
1159 A_surfxml_route_element_name);
1163 static void parse_route_set_route(void)
1165 if (src_id != -1 && dst_id != -1)
1166 route_new(src_id, dst_id, link_list, nb_link, impact_on_src,
1167 impact_on_dst, impact_on_src_with_other_recv,
1168 impact_on_dst_with_other_send);
1171 static void parse_file(const char *file)
1175 /* Figuring out the cpus */
1176 surf_parse_reset_parser();
1177 ETag_surfxml_cpu_fun = parse_cpu;
1178 surf_parse_open(file);
1179 xbt_assert1((!surf_parse()), "Parse error in %s", file);
1182 create_routing_table();
1184 /* Figuring out the router (added after GTNETS) */
1185 surf_parse_reset_parser();
1186 STag_surfxml_router_fun = parse_routers;
1187 surf_parse_open(file);
1188 xbt_assert1((!surf_parse()), "Parse error in %s", file);
1191 /* Figuring out the network links */
1192 surf_parse_reset_parser();
1193 ETag_surfxml_network_link_fun = parse_network_link;
1194 surf_parse_open(file);
1195 xbt_assert1((!surf_parse()), "Parse error in %s", file);
1198 /* Building the routes */
1199 surf_parse_reset_parser();
1200 STag_surfxml_route_fun = parse_route_set_endpoints;
1201 ETag_surfxml_route_element_fun = parse_route_elem;
1202 ETag_surfxml_route_fun = parse_route_set_route;
1203 surf_parse_open(file);
1204 xbt_assert1((!surf_parse()), "Parse error in %s", file);
1207 /* Adding loopback if needed */
1208 for (i = 0; i < nb_workstation; i++)
1209 if (!ROUTE(i, i).size) {
1211 loopback = network_link_new(xbt_strdup("__MSG_loopback__"),
1212 498000000, NULL, 0.000015, NULL,
1213 SURF_NETWORK_LINK_ON, NULL,
1214 SURF_NETWORK_LINK_FATPIPE);
1215 ROUTE(i, i).size = 1;
1216 ROUTE(i, i).links = xbt_new0(network_link_KCCFLN05_t, 1);
1217 ROUTE(i, i).links[0] = loopback;
1222 /**************************************/
1223 /********* Module creation ***********/
1224 /**************************************/
1226 static void model_init_internal(void)
1228 s_surf_action_t action;
1230 surf_workstation_model = xbt_new0(s_surf_workstation_model_t, 1);
1232 surf_workstation_model->common_private =
1233 xbt_new0(s_surf_model_private_t, 1);
1234 surf_workstation_model->common_public =
1235 xbt_new0(s_surf_model_public_t, 1);
1236 surf_workstation_model->extension_public =
1237 xbt_new0(s_surf_workstation_model_extension_public_t, 1);
1239 surf_workstation_model->common_public->states.ready_action_set =
1240 xbt_swag_new(xbt_swag_offset(action, state_hookup));
1241 surf_workstation_model->common_public->states.running_action_set =
1242 xbt_swag_new(xbt_swag_offset(action, state_hookup));
1243 surf_workstation_model->common_public->states.failed_action_set =
1244 xbt_swag_new(xbt_swag_offset(action, state_hookup));
1245 surf_workstation_model->common_public->states.done_action_set =
1246 xbt_swag_new(xbt_swag_offset(action, state_hookup));
1248 surf_workstation_model->common_public->name_service = name_service;
1249 surf_workstation_model->common_public->get_resource_name =
1251 surf_workstation_model->common_public->action_get_state =
1252 surf_action_get_state;
1253 surf_workstation_model->common_public->action_get_start_time =
1254 surf_action_get_start_time;
1255 surf_workstation_model->common_public->action_get_finish_time =
1256 surf_action_get_finish_time;
1257 surf_workstation_model->common_public->action_use = action_use;
1258 surf_workstation_model->common_public->action_free = action_free;
1259 surf_workstation_model->common_public->action_cancel = action_cancel;
1260 surf_workstation_model->common_public->action_recycle =
1262 surf_workstation_model->common_public->action_change_state =
1263 surf_action_change_state;
1264 surf_workstation_model->common_public->action_set_data =
1265 surf_action_set_data;
1266 surf_workstation_model->common_public->suspend = action_suspend;
1267 surf_workstation_model->common_public->resume = action_resume;
1268 surf_workstation_model->common_public->is_suspended =
1269 action_is_suspended;
1270 surf_workstation_model->common_public->set_max_duration =
1271 action_set_max_duration;
1272 surf_workstation_model->common_public->set_priority =
1273 action_set_priority;
1274 surf_workstation_model->common_public->name = "Workstation KCCFLN05";
1276 surf_workstation_model->common_private->resource_used = resource_used;
1277 surf_workstation_model->common_private->share_resources =
1279 surf_workstation_model->common_private->update_actions_state =
1280 update_actions_state;
1281 surf_workstation_model->common_private->update_resource_state =
1282 update_resource_state;
1283 surf_workstation_model->common_private->finalize = finalize;
1285 surf_workstation_model->extension_public->execute = execute;
1286 surf_workstation_model->extension_public->sleep = action_sleep;
1287 surf_workstation_model->extension_public->get_state =
1289 surf_workstation_model->extension_public->get_speed = get_speed;
1290 surf_workstation_model->extension_public->get_available_speed =
1291 get_available_speed;
1292 surf_workstation_model->extension_public->communicate = communicate;
1293 surf_workstation_model->extension_public->execute_parallel_task =
1294 execute_parallel_task;
1295 surf_workstation_model->extension_public->get_route = get_route;
1296 surf_workstation_model->extension_public->get_route_size =
1298 surf_workstation_model->extension_public->get_link_name =
1300 surf_workstation_model->extension_public->get_link_bandwidth =
1302 surf_workstation_model->extension_public->get_link_latency =
1305 workstation_set = xbt_dict_new();
1306 router_set = xbt_dict_new();
1307 network_link_set = xbt_dict_new();
1309 maxmin_system = lmm_system_new();
1312 /**************************************/
1313 /*************** Generic **************/
1314 /**************************************/
1315 void surf_workstation_model_init_KCCFLN05(const char *filename)
1317 xbt_assert0(!surf_cpu_model, "CPU model type already defined");
1318 xbt_assert0(!surf_network_model,
1319 "network model type already defined");
1320 model_init_internal();
1321 parse_file(filename);
1323 xbt_dynar_push(model_list, &surf_workstation_model);