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. */
8 #include "surf_timer_private.h"
10 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(timer, surf,
11 "Logging specific to the SURF timer module");
13 surf_timer_resource_t surf_timer_resource = NULL;
14 static tmgr_trace_t empty_trace = NULL;
15 static xbt_dict_t command_set = NULL;
17 static void timer_free(void *timer)
22 static command_t command_new(void *fun, void* args)
24 command_t command = xbt_new0(s_command_t, 1);
26 command->resource = (surf_resource_t) surf_timer_resource;
29 /* command->name = name; */
30 /* command->power_scale = power_scale; */
31 /* xbt_assert0(command->power_scale>0,"Power has to be >0"); */
32 /* command->power_current = power_initial; */
33 /* if (power_trace) */
34 /* command->power_event = */
35 /* tmgr_history_add_trace(history, power_trace, 0.0, 0, command); */
37 /* command->state_current = state_initial; */
38 /* if (state_trace) */
39 /* command->state_event = */
40 /* tmgr_history_add_trace(history, state_trace, 0.0, 0, command); */
42 /* command->constraint = */
43 /* lmm_constraint_new(maxmin_system, command, */
44 /* command->power_current * command->power_scale); */
46 /* xbt_dict_set(command_set, name, command, command_free); */
51 static void parse_timer(void)
55 static void parse_file(const char *file)
59 static void *name_service(const char *name)
65 static const char *get_resource_name(void *resource_id)
71 static int resource_used(void *resource_id)
76 static void action_free(surf_action_t action)
82 static void action_cancel(surf_action_t action)
88 static void action_recycle(surf_action_t action)
94 static void action_change_state(surf_action_t action,
95 e_surf_action_state_t state)
101 static double share_resources(double now)
106 static void update_actions_state(double now, double delta)
111 static void update_resource_state(void *id,
112 tmgr_trace_event_t event_type,
115 command_t command = id;
117 // Move this command to the list of commands to execute
122 static void set(double date, void *function, void *arg)
124 command_t command = NULL;
126 command = command_new(function, arg);
128 tmgr_history_add_trace(history, empty_trace, date, 0, command);
133 static int get(void **function, void **arg)
138 static void action_suspend(surf_action_t action)
143 static void action_resume(surf_action_t action)
148 static int action_is_suspended(surf_action_t action)
154 static void finalize(void)
156 xbt_dict_free(&command_set);
158 xbt_swag_free(surf_timer_resource->common_public->states.ready_action_set);
159 xbt_swag_free(surf_timer_resource->common_public->states.
161 xbt_swag_free(surf_timer_resource->common_public->states.
163 xbt_swag_free(surf_timer_resource->common_public->states.done_action_set);
164 free(surf_timer_resource->common_public);
165 free(surf_timer_resource->common_private);
166 free(surf_timer_resource->extension_public);
168 free(surf_timer_resource);
169 surf_timer_resource = NULL;
172 static void surf_timer_resource_init_internal(void)
174 s_surf_action_t action;
176 surf_timer_resource = xbt_new0(s_surf_timer_resource_t, 1);
178 surf_timer_resource->common_private =
179 xbt_new0(s_surf_resource_private_t, 1);
180 surf_timer_resource->common_public = xbt_new0(s_surf_resource_public_t, 1);
182 surf_timer_resource->extension_public =
183 xbt_new0(s_surf_timer_resource_extension_public_t, 1);
185 surf_timer_resource->common_public->states.ready_action_set =
186 xbt_swag_new(xbt_swag_offset(action, state_hookup));
187 surf_timer_resource->common_public->states.running_action_set =
188 xbt_swag_new(xbt_swag_offset(action, state_hookup));
189 surf_timer_resource->common_public->states.failed_action_set =
190 xbt_swag_new(xbt_swag_offset(action, state_hookup));
191 surf_timer_resource->common_public->states.done_action_set =
192 xbt_swag_new(xbt_swag_offset(action, state_hookup));
194 surf_timer_resource->common_public->name_service = name_service;
195 surf_timer_resource->common_public->get_resource_name = get_resource_name;
196 surf_timer_resource->common_public->action_get_state =
197 surf_action_get_state;
198 surf_timer_resource->common_public->action_free = action_free;
199 surf_timer_resource->common_public->action_cancel = action_cancel;
200 surf_timer_resource->common_public->action_recycle = action_recycle;
201 surf_timer_resource->common_public->action_change_state =
203 surf_timer_resource->common_public->action_set_data = surf_action_set_data;
204 surf_timer_resource->common_public->name = "TIMER";
206 surf_timer_resource->common_private->resource_used = resource_used;
207 surf_timer_resource->common_private->share_resources = share_resources;
208 surf_timer_resource->common_private->update_actions_state =
209 update_actions_state;
210 surf_timer_resource->common_private->update_resource_state =
211 update_resource_state;
212 surf_timer_resource->common_private->finalize = finalize;
214 surf_timer_resource->common_public->suspend = action_suspend;
215 surf_timer_resource->common_public->resume = action_resume;
216 surf_timer_resource->common_public->is_suspended = action_is_suspended;
218 surf_timer_resource->extension_public->set = set;
219 surf_timer_resource->extension_public->get = get;
221 command_set = xbt_dict_new();
222 empty_trace = tmgr_empty_trace_new();
224 xbt_assert0(maxmin_system, "surf_init has to be called first!");
227 void surf_timer_resource_init(const char *filename)
229 if (surf_timer_resource)
231 surf_timer_resource_init_internal();
232 xbt_dynar_push(resource_list, &surf_timer_resource);