1 /* Copyright (c) 2007, 2008, 2009, 2010. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
10 #include "surf_private.h"
13 SURF_WORKSTATION_RESOURCE_CPU,
14 SURF_WORKSTATION_RESOURCE_LINK,
15 } e_surf_workstation_model_type_t;
17 /**************************************/
18 /********* cpu object *****************/
19 /**************************************/
20 typedef struct cpu_L07 {
21 s_surf_resource_t generic_resource; /* Do not move this field: must match surf_resource_t */
22 e_surf_workstation_model_type_t type; /* Do not move this field: must match link_L07_t */
23 lmm_constraint_t constraint; /* Do not move this field: must match link_L07_t */
26 tmgr_trace_event_t power_event;
27 e_surf_resource_state_t state_current;
28 tmgr_trace_event_t state_event;
29 int id; /* cpu and network card are a single object... */
30 } s_cpu_L07_t, *cpu_L07_t;
32 /**************************************/
33 /*********** network object ***********/
34 /**************************************/
36 typedef struct link_L07 {
37 s_surf_resource_t generic_resource; /* Do not move this field: must match surf_resource_t */
38 e_surf_workstation_model_type_t type; /* Do not move this field: must match cpu_L07_t */
39 lmm_constraint_t constraint; /* Do not move this field: must match cpu_L07_t */
41 tmgr_trace_event_t lat_event;
43 tmgr_trace_event_t bw_event;
44 e_surf_resource_state_t state_current;
45 tmgr_trace_event_t state_event;
46 } s_link_L07_t, *link_L07_t;
48 /**************************************/
49 /*************** actions **************/
50 /**************************************/
51 typedef struct surf_action_workstation_L07 {
52 s_surf_action_t generic_action;
53 lmm_variable_t variable;
55 cpu_L07_t *workstation_list;
56 double *computation_amount;
57 double *communication_amount;
61 } s_surf_action_workstation_L07_t, *surf_action_workstation_L07_t;
64 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_workstation);
66 static int ptask_host_count = 0;
67 static xbt_dict_t ptask_parallel_task_link_set = NULL;
68 lmm_system_t ptask_maxmin_system = NULL;
71 static void ptask_update_action_bound(surf_action_workstation_L07_t action)
73 int workstation_nb = action->workstation_nb;
74 double lat_current = 0.0;
75 double lat_bound = -1.0;
80 for (i = 0; i < workstation_nb; i++) {
81 for (j = 0; j < workstation_nb; j++) {
83 global_routing->get_route(surf_resource_name
84 (action->workstation_list[i]),
85 surf_resource_name(action->
91 if (action->communication_amount[i * workstation_nb + j] > 0) {
92 xbt_dynar_foreach(route, cpt, link) {
93 lat += link->lat_current;
97 lat * action->communication_amount[i * workstation_nb +
102 lat_bound = sg_tcp_gamma / (2.0 * lat_current);
103 XBT_DEBUG("action (%p) : lat_bound = %g", action, lat_bound);
104 if ((action->latency == 0.0) && (action->suspended == 0)) {
105 if (action->rate < 0)
106 lmm_update_variable_bound(ptask_maxmin_system, action->variable,
109 lmm_update_variable_bound(ptask_maxmin_system, action->variable,
110 min(action->rate, lat_bound));
114 /**************************************/
115 /******* Resource Public **********/
116 /**************************************/
118 static int ptask_action_unref(surf_action_t action)
122 if (!action->refcount) {
123 xbt_swag_remove(action, action->state_set);
124 if (((surf_action_workstation_L07_t) action)->variable)
125 lmm_variable_free(ptask_maxmin_system,
126 ((surf_action_workstation_L07_t)
128 free(((surf_action_workstation_L07_t) action)->workstation_list);
129 free(((surf_action_workstation_L07_t) action)->communication_amount);
130 free(((surf_action_workstation_L07_t) action)->computation_amount);
131 surf_action_free(&action);
137 static void ptask_action_cancel(surf_action_t action)
139 surf_action_state_set(action, SURF_ACTION_FAILED);
143 /* action_change_state is inherited from the surf module */
144 /* action_set_data is inherited from the surf module */
146 static void ptask_action_suspend(surf_action_t action)
148 XBT_IN("(%p))", action);
149 if (((surf_action_workstation_L07_t) action)->suspended != 2) {
150 ((surf_action_workstation_L07_t) action)->suspended = 1;
151 lmm_update_variable_weight(ptask_maxmin_system,
152 ((surf_action_workstation_L07_t)
153 action)->variable, 0.0);
158 static void ptask_action_resume(surf_action_t action)
160 surf_action_workstation_L07_t act =
161 (surf_action_workstation_L07_t) action;
164 if (act->suspended != 2) {
165 lmm_update_variable_weight(ptask_maxmin_system, act->variable, 1.0);
171 static int ptask_action_is_suspended(surf_action_t action)
173 return (((surf_action_workstation_L07_t) action)->suspended == 1);
176 static void ptask_action_set_max_duration(surf_action_t action,
178 { /* FIXME: should inherit */
179 XBT_IN("(%p,%g)", action, duration);
180 action->max_duration = duration;
185 static void ptask_action_set_priority(surf_action_t action,
187 { /* FIXME: should inherit */
188 XBT_IN("(%p,%g)", action, priority);
189 action->priority = priority;
193 static double ptask_action_get_remains(surf_action_t action)
195 XBT_IN("(%p)", action);
196 return action->remains;
200 /**************************************/
201 /******* Resource Private **********/
202 /**************************************/
204 static int ptask_resource_used(void *resource_id)
206 /* We can freely cast as a link_L07_t because it has
207 the same prefix as cpu_L07_t */
208 return lmm_constraint_used(ptask_maxmin_system,
209 ((link_L07_t) resource_id)->constraint);
213 static double ptask_share_resources(double now)
215 s_surf_action_workstation_L07_t s_action;
216 surf_action_workstation_L07_t action = NULL;
218 xbt_swag_t running_actions =
219 surf_workstation_model->states.running_action_set;
220 double min = generic_maxmin_share_resources(running_actions,
221 xbt_swag_offset(s_action,
226 xbt_swag_foreach(action, running_actions) {
227 if (action->latency > 0) {
229 min = action->latency;
230 XBT_DEBUG("Updating min (value) with %p (start %f): %f", action,
231 action->generic_action.start, min);
232 } else if (action->latency < min) {
233 min = action->latency;
234 XBT_DEBUG("Updating min (latency) with %p (start %f): %f", action,
235 action->generic_action.start, min);
240 XBT_DEBUG("min value : %f", min);
245 static void ptask_update_actions_state(double now, double delta)
248 surf_action_workstation_L07_t action = NULL;
249 surf_action_workstation_L07_t next_action = NULL;
250 xbt_swag_t running_actions =
251 surf_workstation_model->states.running_action_set;
253 xbt_swag_foreach_safe(action, next_action, running_actions) {
255 if (action->latency > 0) {
256 if (action->latency > deltap) {
257 double_update(&(action->latency), deltap);
260 double_update(&(deltap), action->latency);
261 action->latency = 0.0;
263 if ((action->latency == 0.0) && (action->suspended == 0)) {
264 ptask_update_action_bound(action);
265 lmm_update_variable_weight(ptask_maxmin_system, action->variable,
269 XBT_DEBUG("Action (%p) : remains (%g) updated by %g.",
270 action, action->generic_action.remains,
271 lmm_variable_getvalue(action->variable) * delta);
272 double_update(&(action->generic_action.remains),
273 lmm_variable_getvalue(action->variable) * delta);
275 if (action->generic_action.max_duration != NO_MAX_DURATION)
276 double_update(&(action->generic_action.max_duration), delta);
278 XBT_DEBUG("Action (%p) : remains (%g).",
279 action, action->generic_action.remains);
280 if ((action->generic_action.remains <= 0) &&
281 (lmm_get_variable_weight(action->variable) > 0)) {
282 action->generic_action.finish = surf_get_clock();
283 surf_action_state_set((surf_action_t) action, SURF_ACTION_DONE);
284 } else if ((action->generic_action.max_duration != NO_MAX_DURATION) &&
285 (action->generic_action.max_duration <= 0)) {
286 action->generic_action.finish = surf_get_clock();
287 surf_action_state_set((surf_action_t) action, SURF_ACTION_DONE);
289 /* Need to check that none of the model has failed */
290 lmm_constraint_t cnst = NULL;
292 void *constraint_id = NULL;
295 lmm_get_cnst_from_var(ptask_maxmin_system, action->variable,
297 constraint_id = lmm_constraint_id(cnst);
299 /* if(((link_L07_t)constraint_id)->type== */
300 /* SURF_WORKSTATION_RESOURCE_LINK) { */
301 /* XBT_DEBUG("Checking for link %s (%p)", */
302 /* ((link_L07_t)constraint_id)->name, */
303 /* ((link_L07_t)constraint_id)); */
305 /* if(((cpu_L07_t)constraint_id)->type== */
306 /* SURF_WORKSTATION_RESOURCE_CPU) { */
307 /* XBT_DEBUG("Checking for cpu %s (%p) : %s", */
308 /* ((cpu_L07_t)constraint_id)->name, */
309 /* ((cpu_L07_t)constraint_id), */
310 /* ((cpu_L07_t)constraint_id)->state_current==SURF_CPU_OFF?"Off":"On"); */
313 if (((((link_L07_t) constraint_id)->type ==
314 SURF_WORKSTATION_RESOURCE_LINK) &&
315 (((link_L07_t) constraint_id)->state_current ==
316 SURF_RESOURCE_OFF)) ||
317 ((((cpu_L07_t) constraint_id)->type ==
318 SURF_WORKSTATION_RESOURCE_CPU) &&
319 (((cpu_L07_t) constraint_id)->state_current ==
320 SURF_RESOURCE_OFF))) {
321 XBT_DEBUG("Action (%p) Failed!!", action);
322 action->generic_action.finish = surf_get_clock();
323 surf_action_state_set((surf_action_t) action,
333 static void ptask_update_resource_state(void *id,
334 tmgr_trace_event_t event_type,
335 double value, double date)
338 link_L07_t nw_link = id;
340 if (nw_link->type == SURF_WORKSTATION_RESOURCE_LINK) {
341 XBT_DEBUG("Updating link %s (%p)", surf_resource_name(nw_link), nw_link);
342 if (event_type == nw_link->bw_event) {
343 nw_link->bw_current = value;
344 lmm_update_constraint_bound(ptask_maxmin_system, nw_link->constraint,
345 nw_link->bw_current);
346 if (tmgr_trace_event_free(event_type))
347 nw_link->bw_event = NULL;
348 } else if (event_type == nw_link->lat_event) {
349 lmm_variable_t var = NULL;
350 surf_action_workstation_L07_t action = NULL;
351 lmm_element_t elem = NULL;
353 nw_link->lat_current = value;
354 while ((var = lmm_get_var_from_cnst
355 (ptask_maxmin_system, nw_link->constraint, &elem))) {
358 action = lmm_variable_id(var);
359 ptask_update_action_bound(action);
361 if (tmgr_trace_event_free(event_type))
362 nw_link->lat_event = NULL;
364 } else if (event_type == nw_link->state_event) {
366 nw_link->state_current = SURF_RESOURCE_ON;
368 nw_link->state_current = SURF_RESOURCE_OFF;
369 if (tmgr_trace_event_free(event_type))
370 nw_link->state_event = NULL;
372 XBT_CRITICAL("Unknown event ! \n");
376 } else if (cpu->type == SURF_WORKSTATION_RESOURCE_CPU) {
377 XBT_DEBUG("Updating cpu %s (%p) with value %g", surf_resource_name(cpu),
379 if (event_type == cpu->power_event) {
380 cpu->power_current = value;
381 lmm_update_constraint_bound(ptask_maxmin_system, cpu->constraint,
382 cpu->power_current * cpu->power_scale);
383 if (tmgr_trace_event_free(event_type))
384 cpu->power_event = NULL;
385 } else if (event_type == cpu->state_event) {
387 cpu->state_current = SURF_RESOURCE_ON;
389 cpu->state_current = SURF_RESOURCE_OFF;
390 if (tmgr_trace_event_free(event_type))
391 cpu->state_event = NULL;
393 XBT_CRITICAL("Unknown event ! \n");
403 static void ptask_finalize(void)
405 if (ptask_parallel_task_link_set != NULL)
406 xbt_dict_free(&ptask_parallel_task_link_set);
408 surf_model_exit(surf_workstation_model);
409 surf_workstation_model = NULL;
410 surf_model_exit(surf_network_model);
411 surf_network_model = NULL;
412 global_routing->finalize();
414 ptask_host_count = 0;
416 if (ptask_maxmin_system) {
417 lmm_system_free(ptask_maxmin_system);
418 ptask_maxmin_system = NULL;
422 /**************************************/
423 /******* Resource Private **********/
424 /**************************************/
426 static e_surf_resource_state_t ptask_resource_get_state(void *cpu)
428 return ((cpu_L07_t) cpu)->state_current;
431 static double ptask_get_speed(void *cpu, double load)
433 return load * (((cpu_L07_t) cpu)->power_scale);
436 static double ptask_get_available_speed(void *cpu)
438 return ((cpu_L07_t) cpu)->power_current;
441 static surf_action_t ptask_execute_parallel_task(int workstation_nb,
442 void **workstation_list,
444 *computation_amount, double
445 *communication_amount,
449 surf_action_workstation_L07_t action = NULL;
454 double latency = 0.0;
456 if (ptask_parallel_task_link_set == NULL)
457 ptask_parallel_task_link_set = xbt_dict_new();
459 xbt_dict_reset(ptask_parallel_task_link_set);
461 /* Compute the number of affected resources... */
462 for (i = 0; i < workstation_nb; i++) {
463 for (j = 0; j < workstation_nb; j++) {
466 global_routing->get_route(surf_resource_name
467 (workstation_list[i]),
468 surf_resource_name(workstation_list
472 if (communication_amount[i * workstation_nb + j] > 0)
473 xbt_dynar_foreach(route, cpt, link) {
474 lat += link->lat_current;
475 xbt_dict_set(ptask_parallel_task_link_set,
476 link->generic_resource.name, link, NULL);
478 latency = MAX(latency, lat);
482 nb_link = xbt_dict_length(ptask_parallel_task_link_set);
483 xbt_dict_reset(ptask_parallel_task_link_set);
485 for (i = 0; i < workstation_nb; i++)
486 if (computation_amount[i] > 0)
490 surf_action_new(sizeof(s_surf_action_workstation_L07_t), amount,
491 surf_workstation_model, 0);
492 XBT_DEBUG("Creating a parallel task (%p) with %d cpus and %d links.",
493 action, workstation_nb, nb_link);
494 action->suspended = 0; /* Should be useless because of the
495 calloc but it seems to help valgrind... */
496 action->workstation_nb = workstation_nb;
497 action->workstation_list = (cpu_L07_t *) workstation_list;
498 action->computation_amount = computation_amount;
499 action->communication_amount = communication_amount;
500 action->latency = latency;
504 lmm_variable_new(ptask_maxmin_system, action, 1.0,
505 (action->rate > 0) ? action->rate : -1.0,
506 workstation_nb + nb_link);
508 if (action->latency > 0)
509 lmm_update_variable_weight(ptask_maxmin_system, action->variable, 0.0);
511 for (i = 0; i < workstation_nb; i++)
512 lmm_expand(ptask_maxmin_system,
513 ((cpu_L07_t) workstation_list[i])->constraint,
514 action->variable, computation_amount[i]);
516 for (i = 0; i < workstation_nb; i++) {
517 for (j = 0; j < workstation_nb; j++) {
520 global_routing->get_route(surf_resource_name
521 (workstation_list[i]),
522 surf_resource_name(workstation_list
525 if (communication_amount[i * workstation_nb + j] == 0.0)
527 xbt_dynar_foreach(route, cpt, link) {
528 lmm_expand_add(ptask_maxmin_system, link->constraint,
530 communication_amount[i * workstation_nb + j]);
535 if (nb_link + nb_host == 0) {
536 action->generic_action.cost = 1.0;
537 action->generic_action.remains = 0.0;
540 return (surf_action_t) action;
543 static surf_action_t ptask_execute(void *cpu, double size)
545 void **workstation_list = xbt_new0(void *, 1);
546 double *computation_amount = xbt_new0(double, 1);
547 double *communication_amount = xbt_new0(double, 1);
549 workstation_list[0] = cpu;
550 communication_amount[0] = 0.0;
551 computation_amount[0] = size;
553 return ptask_execute_parallel_task(1, workstation_list,
555 communication_amount, 1, -1);
558 static surf_action_t ptask_communicate(void *src, void *dst, double size,
561 void **workstation_list = xbt_new0(void *, 2);
562 double *computation_amount = xbt_new0(double, 2);
563 double *communication_amount = xbt_new0(double, 4);
564 surf_action_t res = NULL;
566 workstation_list[0] = src;
567 workstation_list[1] = dst;
568 communication_amount[1] = size;
570 res = ptask_execute_parallel_task(2, workstation_list,
572 communication_amount, 1, rate);
577 static surf_action_t ptask_action_sleep(void *cpu, double duration)
579 surf_action_workstation_L07_t action = NULL;
581 XBT_IN("(%s,%g)", surf_resource_name(cpu), duration);
583 action = (surf_action_workstation_L07_t) ptask_execute(cpu, 1.0);
584 action->generic_action.max_duration = duration;
585 action->suspended = 2;
586 lmm_update_variable_weight(ptask_maxmin_system, action->variable, 0.0);
589 return (surf_action_t) action;
592 static xbt_dynar_t ptask_get_route(void *src, void *dst)
594 return global_routing->get_route(surf_resource_name(src),
595 surf_resource_name(dst));
598 static double ptask_get_link_bandwidth(const void *link)
600 return ((link_L07_t) link)->bw_current;
603 static double ptask_get_link_latency(const void *link)
605 return ((link_L07_t) link)->lat_current;
608 static int ptask_link_shared(const void *link)
610 return lmm_constraint_is_shared(((link_L07_t) link)->constraint);
613 /**************************************/
614 /*** Resource Creation & Destruction **/
615 /**************************************/
617 static cpu_L07_t ptask_cpu_new(const char *name, double power_scale,
618 double power_initial,
619 tmgr_trace_t power_trace,
620 e_surf_resource_state_t state_initial,
621 tmgr_trace_t state_trace,
622 xbt_dict_t cpu_properties)
624 cpu_L07_t cpu = xbt_new0(s_cpu_L07_t, 1);
625 xbt_assert(!surf_workstation_resource_by_name(name),
626 "Host '%s' declared several times in the platform file.",
629 cpu->generic_resource.model = surf_workstation_model;
630 cpu->type = SURF_WORKSTATION_RESOURCE_CPU;
631 cpu->generic_resource.name = xbt_strdup(name);
632 cpu->generic_resource.properties = cpu_properties;
633 cpu->id = ptask_host_count++;
635 cpu->power_scale = power_scale;
636 xbt_assert(cpu->power_scale > 0, "Power has to be >0");
638 cpu->power_current = power_initial;
641 tmgr_history_add_trace(history, power_trace, 0.0, 0, cpu);
643 cpu->state_current = state_initial;
646 tmgr_history_add_trace(history, state_trace, 0.0, 0, cpu);
649 lmm_constraint_new(ptask_maxmin_system, cpu,
650 cpu->power_current * cpu->power_scale);
652 xbt_lib_set(host_lib, name, SURF_WKS_LEVEL, cpu);
657 static void ptask_parse_cpu_init(void)
659 double power_scale = 0.0;
660 double power_initial = 0.0;
661 tmgr_trace_t power_trace = NULL;
662 e_surf_resource_state_t state_initial = SURF_RESOURCE_OFF;
663 tmgr_trace_t state_trace = NULL;
665 power_scale = get_cpu_power(A_surfxml_host_power);
666 surf_parse_get_double(&power_initial, A_surfxml_host_availability);
667 power_trace = tmgr_trace_new(A_surfxml_host_availability_file);
669 xbt_assert((A_surfxml_host_state == A_surfxml_host_state_ON) ||
670 (A_surfxml_host_state == A_surfxml_host_state_OFF),
672 if (A_surfxml_host_state == A_surfxml_host_state_ON)
673 state_initial = SURF_RESOURCE_ON;
674 if (A_surfxml_host_state == A_surfxml_host_state_OFF)
675 state_initial = SURF_RESOURCE_OFF;
676 state_trace = tmgr_trace_new(A_surfxml_host_state_file);
678 ptask_cpu_new(A_surfxml_host_id, power_scale, power_initial, power_trace,
679 state_initial, state_trace, current_property_set);
680 current_property_set=NULL;
683 static void ptask_cpu_create_resource(char *name, double power_peak,
685 tmgr_trace_t power_trace,
686 e_surf_resource_state_t
688 tmgr_trace_t state_trace,
689 xbt_dict_t cpu_properties)
691 ptask_cpu_new(xbt_strdup(name), power_peak, power_scale, power_trace,
692 state_initial, state_trace, cpu_properties);
695 static link_L07_t ptask_link_new(char *name,
697 tmgr_trace_t bw_trace,
699 tmgr_trace_t lat_trace,
700 e_surf_resource_state_t
702 tmgr_trace_t state_trace,
703 e_surf_link_sharing_policy_t
704 policy, xbt_dict_t properties)
706 link_L07_t nw_link = xbt_new0(s_link_L07_t, 1);
707 xbt_assert(!xbt_lib_get_or_null(link_lib, name, SURF_LINK_LEVEL),
708 "Link '%s' declared several times in the platform file.",
711 nw_link->generic_resource.model = surf_workstation_model;
712 nw_link->generic_resource.properties = properties;
713 nw_link->generic_resource.name = name;
714 nw_link->type = SURF_WORKSTATION_RESOURCE_LINK;
715 nw_link->bw_current = bw_initial;
718 tmgr_history_add_trace(history, bw_trace, 0.0, 0, nw_link);
719 nw_link->state_current = state_initial;
720 nw_link->lat_current = lat_initial;
723 tmgr_history_add_trace(history, lat_trace, 0.0, 0, nw_link);
725 nw_link->state_event =
726 tmgr_history_add_trace(history, state_trace, 0.0, 0, nw_link);
728 nw_link->constraint =
729 lmm_constraint_new(ptask_maxmin_system, nw_link,
730 nw_link->bw_current);
732 if (policy == SURF_LINK_FATPIPE)
733 lmm_constraint_shared(nw_link->constraint);
735 xbt_lib_set(link_lib, name, SURF_LINK_LEVEL, nw_link);
739 static void ptask_parse_link_init(void)
742 tmgr_trace_t bw_trace;
744 tmgr_trace_t lat_trace;
745 e_surf_resource_state_t state_initial_link = SURF_RESOURCE_ON;
746 e_surf_link_sharing_policy_t policy_initial_link = SURF_LINK_SHARED;
747 tmgr_trace_t state_trace;
748 char *name_link_up = NULL;
749 char *name_link_down = NULL;
750 char *name_link = NULL;
752 if(A_surfxml_link_sharing_policy ==
753 A_surfxml_link_sharing_policy_FULLDUPLEX) {
754 name_link_up = bprintf("%s_UP", A_surfxml_link_id);
755 name_link_down = bprintf("%s_DOWN", A_surfxml_link_id);
757 name_link = xbt_strdup(A_surfxml_link_id);
759 surf_parse_get_double(&bw_initial, A_surfxml_link_bandwidth);
760 bw_trace = tmgr_trace_new(A_surfxml_link_bandwidth_file);
761 surf_parse_get_double(&lat_initial, A_surfxml_link_latency);
762 lat_trace = tmgr_trace_new(A_surfxml_link_latency_file);
764 xbt_assert((A_surfxml_link_state == A_surfxml_link_state_ON)
765 || (A_surfxml_link_state ==
766 A_surfxml_link_state_OFF), "Invalid state");
767 if (A_surfxml_link_state == A_surfxml_link_state_ON)
768 state_initial_link = SURF_RESOURCE_ON;
769 else if (A_surfxml_link_state == A_surfxml_link_state_OFF)
770 state_initial_link = SURF_RESOURCE_OFF;
772 if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_SHARED)
773 policy_initial_link = SURF_LINK_SHARED;
774 if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_FATPIPE)
775 policy_initial_link = SURF_LINK_FATPIPE;
776 if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_FULLDUPLEX)
777 policy_initial_link = SURF_LINK_FULLDUPLEX;
779 state_trace = tmgr_trace_new(A_surfxml_link_state_file);
781 if(policy_initial_link == SURF_LINK_FULLDUPLEX)
783 ptask_link_new(name_link_up, bw_initial, bw_trace, lat_initial, lat_trace,
784 state_initial_link, state_trace, policy_initial_link,
785 current_property_set);
786 ptask_link_new(name_link_down, bw_initial, bw_trace, lat_initial, lat_trace,
787 state_initial_link, state_trace, policy_initial_link,
788 current_property_set);
792 ptask_link_new(name_link, bw_initial, bw_trace, lat_initial, lat_trace,
793 state_initial_link, state_trace, policy_initial_link,
794 current_property_set);
796 current_property_set = NULL;
799 static void ptask_link_create_resource(char *name,
801 tmgr_trace_t bw_trace,
803 tmgr_trace_t lat_trace,
804 e_surf_resource_state_t
806 tmgr_trace_t state_trace,
807 e_surf_link_sharing_policy_t
808 policy, xbt_dict_t properties)
810 ptask_link_new(name, bw_initial, bw_trace,
811 lat_initial, lat_trace, state_initial, state_trace,
816 static void ptask_add_traces(void)
818 xbt_dict_cursor_t cursor = NULL;
819 char *trace_name, *elm;
821 if (!trace_connect_list_host_avail)
824 /* Connect traces relative to cpu */
825 xbt_dict_foreach(trace_connect_list_host_avail, cursor, trace_name, elm) {
826 tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
827 cpu_L07_t host = surf_workstation_resource_by_name(elm);
829 xbt_assert(host, "Host %s undefined", elm);
830 xbt_assert(trace, "Trace %s undefined", trace_name);
833 tmgr_history_add_trace(history, trace, 0.0, 0, host);
836 xbt_dict_foreach(trace_connect_list_power, cursor, trace_name, elm) {
837 tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
838 cpu_L07_t host = surf_workstation_resource_by_name(elm);
840 xbt_assert(host, "Host %s undefined", elm);
841 xbt_assert(trace, "Trace %s undefined", trace_name);
844 tmgr_history_add_trace(history, trace, 0.0, 0, host);
847 /* Connect traces relative to network */
848 xbt_dict_foreach(trace_connect_list_link_avail, cursor, trace_name, elm) {
849 tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
851 xbt_lib_get_or_null(link_lib, elm, SURF_LINK_LEVEL);
853 xbt_assert(link, "Link %s undefined", elm);
854 xbt_assert(trace, "Trace %s undefined", trace_name);
857 tmgr_history_add_trace(history, trace, 0.0, 0, link);
860 xbt_dict_foreach(trace_connect_list_bandwidth, cursor, trace_name, elm) {
861 tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
863 xbt_lib_get_or_null(link_lib, elm, SURF_LINK_LEVEL);
865 xbt_assert(link, "Link %s undefined", elm);
866 xbt_assert(trace, "Trace %s undefined", trace_name);
868 link->bw_event = tmgr_history_add_trace(history, trace, 0.0, 0, link);
871 xbt_dict_foreach(trace_connect_list_latency, cursor, trace_name, elm) {
872 tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
874 xbt_lib_get_or_null(link_lib, elm, SURF_LINK_LEVEL);
876 xbt_assert(link, "Link %s undefined", elm);
877 xbt_assert(trace, "Trace %s undefined", trace_name);
879 link->lat_event = tmgr_history_add_trace(history, trace, 0.0, 0, link);
883 static void ptask_define_callbacks(const char *file)
885 /* Adding callback functions */
886 surfxml_add_callback(ETag_surfxml_host_cb_list, &ptask_parse_cpu_init);
887 surfxml_add_callback(ETag_surfxml_link_cb_list, &ptask_parse_link_init);
888 surfxml_add_callback(ETag_surfxml_platform_cb_list, &ptask_add_traces);
891 /**************************************/
892 /********* Module creation ***********/
893 /**************************************/
895 static void ptask_model_init_internal(void)
897 surf_workstation_model = surf_model_init();
899 surf_workstation_model->action_unref = ptask_action_unref;
900 surf_workstation_model->action_cancel = ptask_action_cancel;
901 surf_workstation_model->action_state_set = surf_action_state_set;
902 surf_workstation_model->suspend = ptask_action_suspend;
903 surf_workstation_model->resume = ptask_action_resume;
904 surf_workstation_model->is_suspended = ptask_action_is_suspended;
905 surf_workstation_model->set_max_duration = ptask_action_set_max_duration;
906 surf_workstation_model->set_priority = ptask_action_set_priority;
907 surf_workstation_model->get_remains = ptask_action_get_remains;
908 surf_workstation_model->name = "Workstation ptask_L07";
910 surf_workstation_model->model_private->resource_used =
912 surf_workstation_model->model_private->share_resources =
913 ptask_share_resources;
914 surf_workstation_model->model_private->update_actions_state =
915 ptask_update_actions_state;
916 surf_workstation_model->model_private->update_resource_state =
917 ptask_update_resource_state;
918 surf_workstation_model->model_private->finalize = ptask_finalize;
921 surf_workstation_model->extension.workstation.execute = ptask_execute;
922 surf_workstation_model->extension.workstation.sleep = ptask_action_sleep;
923 surf_workstation_model->extension.workstation.get_state =
924 ptask_resource_get_state;
925 surf_workstation_model->extension.workstation.get_speed =
927 surf_workstation_model->extension.workstation.get_available_speed =
928 ptask_get_available_speed;
929 surf_workstation_model->extension.workstation.communicate =
931 surf_workstation_model->extension.workstation.get_route =
933 surf_workstation_model->extension.workstation.execute_parallel_task =
934 ptask_execute_parallel_task;
935 surf_workstation_model->extension.workstation.get_link_bandwidth =
936 ptask_get_link_bandwidth;
937 surf_workstation_model->extension.workstation.get_link_latency =
938 ptask_get_link_latency;
939 surf_workstation_model->extension.workstation.link_shared =
941 surf_workstation_model->extension.workstation.get_properties =
942 surf_resource_properties;
943 surf_workstation_model->extension.workstation.link_create_resource =
944 ptask_link_create_resource;
945 surf_workstation_model->extension.workstation.cpu_create_resource =
946 ptask_cpu_create_resource;
947 surf_workstation_model->extension.workstation.add_traces =
950 if (!ptask_maxmin_system)
951 ptask_maxmin_system = lmm_system_new();
953 routing_model_create(sizeof(link_L07_t),
954 ptask_link_new(xbt_strdup("__loopback__"),
955 498000000, NULL, 0.000015, NULL,
956 SURF_RESOURCE_ON, NULL,
957 SURF_LINK_FATPIPE, NULL),
958 ptask_get_link_latency);
962 /**************************************/
963 /*************** Generic **************/
964 /**************************************/
965 void surf_workstation_model_init_ptask_L07(const char *filename)
967 XBT_INFO("surf_workstation_model_init_ptask_L07");
968 xbt_assert(!surf_cpu_model, "CPU model type already defined");
969 xbt_assert(!surf_network_model, "network model type already defined");
970 surf_network_model = surf_model_init();
971 ptask_define_callbacks(filename);
972 ptask_model_init_internal();
974 update_model_description(surf_workstation_model_description,
975 "ptask_L07", surf_workstation_model);
976 xbt_dynar_push(model_list, &surf_workstation_model);