1 /* Copyright (c) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012. 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. */
7 /* ********************************************************************* */
8 /* TUTORIAL: New model */
9 /* ********************************************************************* */
14 #include "surf_private.h"
15 #include "new_model_private.h"
16 #include "surf/surf_resource.h"
18 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_new_model, surf,
19 "Logging specific to the SURF new model module");
21 surf_model_t surf_new_model = NULL;
22 lmm_system_t new_model_maxmin_system = NULL;
24 static int new_model_selective_update = 0;
26 new_model_running_action_set_that_does_not_need_being_checked = NULL;
29 #define GENERIC_LMM_ACTION(action) action->generic_lmm_action
30 #define GENERIC_ACTION(action) GENERIC_LMM_ACTION(action).generic_action
32 void surf_new_model_init_default(void){}
34 //FIXME:UPDATE FOR SURF++
35 #ifdef UPDATE_FOR_SURFPP
36 static void new_model_action_state_set(surf_action_t action, e_surf_action_state_t state);
38 static surf_action_t new_model_action_execute ()
44 static surf_action_t new_model_action_fct()
46 surf_action_t action = new_model_action_execute();
50 static void* new_model_create_resource(const char* id, const char* model,const char* type_id,const char* content_name)
56 static void new_model_finalize(void)
58 lmm_system_free(new_model_maxmin_system);
59 new_model_maxmin_system = NULL;
61 surf_model_exit(surf_new_model);
62 surf_new_model = NULL;
65 (new_model_running_action_set_that_does_not_need_being_checked);
66 new_model_running_action_set_that_does_not_need_being_checked = NULL;
69 static void new_model_update_actions_state(double now, double delta)
74 static double new_model_share_resources(double NOW)
79 static int new_model_resource_used(void *resource_id)
85 static void new_model_resources_state(void *id, tmgr_trace_event_t event_type,
86 double value, double time)
91 static int new_model_action_unref(surf_action_t action)
97 static void new_model_action_cancel(surf_action_t action)
99 surf_action_state_set(action, SURF_ACTION_FAILED);
103 static void new_model_action_state_set(surf_action_t action, e_surf_action_state_t state)
105 surf_action_state_set(action, state);
109 static void new_model_action_suspend(surf_action_t action)
111 XBT_IN("(%p)", action);
112 if (((surf_action_lmm_t) action)->suspended != 2) {
113 lmm_update_variable_weight(new_model_maxmin_system,
114 ((surf_action_lmm_t) action)->variable,
116 ((surf_action_lmm_t) action)->suspended = 1;
121 static void new_model_action_resume(surf_action_t action)
126 static int new_model_action_is_suspended(surf_action_t action)
128 return (((surf_action_lmm_t) action)->suspended == 1);
131 static void new_model_action_set_max_duration(surf_action_t action, double duration)
136 static void new_model_action_set_priority(surf_action_t action, double priority)
141 static void new_model_define_callbacks()
145 static void surf_new_model_init_internal(void)
147 s_surf_action_t action;
149 XBT_DEBUG("surf_new_model_model_init_internal");
150 surf_new_model = surf_model_init();
152 new_model_running_action_set_that_does_not_need_being_checked =
153 xbt_swag_new(xbt_swag_offset(action, state_hookup));
155 surf_new_model->name = "New Model";
156 surf_new_model->action_unref = new_model_action_unref;
157 surf_new_model->action_cancel = new_model_action_cancel;
158 surf_new_model->action_state_set = new_model_action_state_set;
160 surf_new_model->model_private->finalize = new_model_finalize;
161 surf_new_model->model_private->update_actions_state = new_model_update_actions_state;
162 surf_new_model->model_private->share_resources = new_model_share_resources;
163 surf_new_model->model_private->resource_used = new_model_resource_used;
164 surf_new_model->model_private->update_resource_state = new_model_resources_state;
166 surf_new_model->suspend = new_model_action_suspend;
167 surf_new_model->resume = new_model_action_resume;
168 surf_new_model->is_suspended = new_model_action_is_suspended;
169 surf_new_model->set_max_duration = new_model_action_set_max_duration;
170 surf_new_model->set_priority = new_model_action_set_priority;
172 surf_new_model->extension.new_model.fct = new_model_action_fct;
173 surf_new_model->extension.new_model.create_resource = new_model_create_resource;
175 if (!new_model_maxmin_system) {
176 new_model_maxmin_system = lmm_system_new(new_model_selective_update);
181 void surf_new_model_init_default(void)
183 surf_new_model_init_internal();
184 new_model_define_callbacks();
186 xbt_dynar_push(model_list, &surf_new_model);