2 #include "simix/smx_host_private.h"
4 XBT_LOG_NEW_CATEGORY(surfpp, "All SURF categories");
5 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surfpp_kernel, surfpp,
6 "Logging specific to SURF (kernel)");
15 XBT_INLINE double surf_get_clock(void)
20 /* This function is a pimple that we ought to fix. But it won't be easy.
22 * The surf_solve() function does properly return the set of actions that changed.
23 * Instead, each model change a global data, and then the caller of surf_solve must
24 * pick into these sets of action_failed and action_done.
26 * This was not clean but ok as long as we didn't had to restart the processes when the resource comes back up.
27 * We worked by putting sentinel actions on every resources we are interested in,
28 * so that surf informs us if/when the corresponding resource fails.
30 * But this does not work to get Simix informed of when a resource comes back up, and this is where this pimple comes.
31 * We have a set of resources that are currently down and for which simix needs to know when it comes back up.
32 * And the current function is called *at every simulation step* to sweep over that set, searching for a resource
33 * that was turned back up in the meanwhile. This is UGLY and slow.
35 * The proper solution would be to not rely on globals for the action_failed and action_done swags.
36 * They must be passed as parameter by the caller (the handling of these actions in simix may let you
37 * think that these two sets can be merged, but their handling in SimDag induce the contrary unless this
38 * simdag code can check by itself whether the action is done of failed -- seems very doable, but yet more
41 * Once surf_solve() is passed the set of actions that changed, you want to add a new set of resources back up
42 * as parameter to this function. You also want to add a boolean field "restart_watched" to each resource, and
43 * make sure that whenever a resource with this field enabled comes back up, it's added to that set so that Simix
44 * sees it and react accordingly. This would kill that need for surf to call simix.
48 static void remove_watched_host(void *key)
50 xbt_dict_remove(watched_hosts_lib, *(char**)key);
53 /*TODO: keepit void surf_watched_hosts(void)
58 xbt_dict_cursor_t cursor;
59 xbt_dynar_t hosts = xbt_dynar_new(sizeof(char*), NULL);
61 XBT_DEBUG("Check for host SURF_RESOURCE_ON on watched_hosts_lib");
62 xbt_dict_foreach(watched_hosts_lib,cursor,key,_host)
64 host = (smx_host_t) host;
65 if(SIMIX_host_get_state(host) == SURF_RESOURCE_ON){
66 XBT_INFO("Restart processes on host: %s",SIMIX_host_get_name(host));
67 SIMIX_host_autorestart(host);
68 xbt_dynar_push_as(hosts, char*, key);
71 XBT_DEBUG("See SURF_RESOURCE_OFF on host: %s",key);
73 xbt_dynar_map(hosts, remove_watched_host);
74 xbt_dynar_free(&hosts);
81 void Model::addTurnedOnCallback(ResourceCallback rc)
86 void Model::notifyResourceTurnedOn(ResourcePtr r)
91 void Model::addTurnedOffCallback(ResourceCallback rc)
96 void Model::notifyResourceTurnedOff(ResourcePtr r)
101 void Model::addActionCancelCallback(ActionCallback ac)
106 void Model::notifyActionCancel(ActionPtr a)
111 void Model::addActionResumeCallback(ActionCallback ac)
116 void Model::notifyActionResume(ActionPtr a)
121 void Model::addActionSuspendCallback(ActionCallback ac)
126 void Model::notifyActionSuspend(ActionPtr a)
136 string Resource::getName() {
140 bool Resource::isOn()
145 void Resource::turnOn()
149 p_model->notifyResourceTurnedOn(this);
153 void Resource::turnOff()
157 p_model->notifyResourceTurnedOff(this);
164 /*TODO/const char *surf_action_state_names[6] = {
166 "SURF_ACTION_RUNNING",
167 "SURF_ACTION_FAILED",
169 "SURF_ACTION_TO_FREE",
170 "SURF_ACTION_NOT_IN_THE_SYSTEM"
173 e_surf_action_state_t Action::getState()
175 if (p_stateSet == p_model->p_readyActionSet)
176 return SURF_ACTION_READY;
177 if (p_stateSet == p_model->p_runningActionSet)
178 return SURF_ACTION_RUNNING;
179 if (p_stateSet == p_model->p_failedActionSet)
180 return SURF_ACTION_FAILED;
181 if (p_stateSet == p_model->p_doneActionSet)
182 return SURF_ACTION_DONE;
183 return SURF_ACTION_NOT_IN_THE_SYSTEM;
186 void Action::setState(e_surf_action_state_t state)
188 //surf_action_state_t action_state = &(action->model_type->states);
189 XBT_IN("(%p,%s)", this, surf_action_state_names[state]);
190 xbt_swag_remove(this, p_stateSet);
192 if (state == SURF_ACTION_READY)
193 p_stateSet = p_model->p_readyActionSet;
194 else if (state == SURF_ACTION_RUNNING)
195 p_stateSet = p_model->p_runningActionSet;
196 else if (state == SURF_ACTION_FAILED)
197 p_stateSet = p_model->p_failedActionSet;
198 else if (state == SURF_ACTION_DONE)
199 p_stateSet = p_model->p_doneActionSet;
204 xbt_swag_insert(this, p_stateSet);
208 double Action::getStartTime()
213 double Action::getFinishTime()
218 void Action::setData(void* data)
223 /*void Action::cancel()
225 p_model->notifyActionCancel(this);
228 void Action::suspend()
230 p_model->notifyActionSuspend(this);
233 void Action::resume()
235 p_model->notifyActionResume(this);
238 bool Action::isSuspended()