Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' into hypervisor
[simgrid.git] / src / surf / new_model.c
1 /* Copyright (c) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012. The SimGrid Team.
2  * All rights reserved.                                                                 */
3
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.             */
6
7 /* ********************************************************************* */
8 /* TUTORIAL: New model                                                   */
9 /* ********************************************************************* */
10
11 #include "xbt/ex.h"
12 #include "xbt/dict.h"
13 #include "portable.h"
14 #include "surf_private.h"
15 #include "new_model_private.h"
16 #include "surf/surf_resource.h"
17
18 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_new_model, surf,
19                                 "Logging specific to the SURF new model module");
20
21 surf_model_t surf_new_model = NULL;
22 lmm_system_t new_model_maxmin_system = NULL;
23 static int new_model_selective_update = 0;
24 static xbt_swag_t
25     new_model_running_action_set_that_does_not_need_being_checked = NULL;
26
27 #define GENERIC_LMM_ACTION(action) action->generic_lmm_action
28 #define GENERIC_ACTION(action) GENERIC_LMM_ACTION(action).generic_action
29
30 static void new_model_action_state_set(surf_action_t action, e_surf_action_state_t state);
31
32 static surf_action_t new_model_action_execute ()
33 {
34   THROW_UNIMPLEMENTED;
35   return NULL;
36 }
37
38 static surf_action_t new_model_action_fct()
39 {
40   surf_action_t action = new_model_action_execute();
41   return action;
42 }
43
44 static void* new_model_create_resource(const char* id, const char* model,const char* type_id,const char* content_name)
45 {
46   THROW_UNIMPLEMENTED;
47   return NULL;
48 }
49
50 static void new_model_finalize(surf_model_t new_model)
51 {
52   lmm_system_free(new_model_maxmin_system);
53   new_model_maxmin_system = NULL;
54
55   surf_model_exit(new_model);
56   new_model = NULL;
57
58   xbt_swag_free
59       (new_model_running_action_set_that_does_not_need_being_checked);
60   new_model_running_action_set_that_does_not_need_being_checked = NULL;
61 }
62
63 static void new_model_update_actions_state(surf_model_t new_model, double now, double delta)
64 {
65   return;
66 }
67
68 static double new_model_share_resources(surf_model_t new_model, double NOW)
69 {
70   return -1;
71 }
72
73 static int new_model_resource_used(void *resource_id)
74 {
75   THROW_UNIMPLEMENTED;
76   return 0;
77 }
78
79 static void new_model_resources_state(void *id, tmgr_trace_event_t event_type,
80                                  double value, double time)
81 {
82   THROW_UNIMPLEMENTED;
83 }
84
85 static int new_model_action_unref(surf_action_t action)
86 {
87   THROW_UNIMPLEMENTED;
88   return 0;
89 }
90
91 static void new_model_action_cancel(surf_action_t action)
92 {
93   surf_action_state_set(action, SURF_ACTION_FAILED);
94   return;
95 }
96
97 static void new_model_action_state_set(surf_action_t action, e_surf_action_state_t state)
98 {
99   surf_action_state_set(action, state);
100   return;
101 }
102
103 static void new_model_action_suspend(surf_action_t action)
104 {
105   XBT_IN("(%p)", action);
106   if (((surf_action_lmm_t) action)->suspended != 2) {
107     lmm_update_variable_weight(new_model_maxmin_system,
108                                ((surf_action_lmm_t) action)->variable,
109                                0.0);
110     ((surf_action_lmm_t) action)->suspended = 1;
111   }
112   XBT_OUT();
113 }
114
115 static void new_model_action_resume(surf_action_t action)
116 {
117   THROW_UNIMPLEMENTED;
118 }
119
120 static int new_model_action_is_suspended(surf_action_t action)
121 {
122   return (((surf_action_lmm_t) action)->suspended == 1);
123 }
124
125 static void new_model_action_set_max_duration(surf_action_t action, double duration)
126 {
127   THROW_UNIMPLEMENTED;
128 }
129
130 static void new_model_action_set_priority(surf_action_t action, double priority)
131 {
132   THROW_UNIMPLEMENTED;
133 }
134
135 static void new_model_define_callbacks()
136 {
137 }
138
139 static void surf_new_model_init_internal(void)
140 {
141   s_surf_action_t action;
142
143   XBT_DEBUG("surf_new_model_model_init_internal");
144   surf_new_model = surf_model_init();
145
146   new_model_running_action_set_that_does_not_need_being_checked =
147       xbt_swag_new(xbt_swag_offset(action, state_hookup));
148
149   surf_new_model->name = "New Model";
150   surf_new_model->type = SURF_MODEL_TYPE_NEW_MODEL;
151   surf_new_model->action_unref = new_model_action_unref;
152   surf_new_model->action_cancel = new_model_action_cancel;
153   surf_new_model->action_state_set = new_model_action_state_set;
154
155   surf_new_model->model_private->finalize = new_model_finalize;
156   surf_new_model->model_private->update_actions_state = new_model_update_actions_state;
157   surf_new_model->model_private->share_resources = new_model_share_resources;
158   surf_new_model->model_private->resource_used = new_model_resource_used;
159   surf_new_model->model_private->update_resource_state = new_model_resources_state;
160
161   surf_new_model->suspend = new_model_action_suspend;
162   surf_new_model->resume = new_model_action_resume;
163   surf_new_model->is_suspended = new_model_action_is_suspended;
164   surf_new_model->set_max_duration = new_model_action_set_max_duration;
165   surf_new_model->set_priority = new_model_action_set_priority;
166
167   surf_new_model->extension.new_model.fct = new_model_action_fct;
168   surf_new_model->extension.new_model.create_resource = new_model_create_resource;
169
170   if (!new_model_maxmin_system) {
171     new_model_maxmin_system = lmm_system_new(new_model_selective_update);
172   }
173
174 }
175
176 void surf_new_model_init_default(void)
177 {
178   surf_new_model_init_internal();
179   new_model_define_callbacks();
180
181   xbt_dynar_push(model_list, &surf_new_model);
182 }