1 /* Copyright (c) 2004-2015. 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 #include "surf_interface.hpp"
8 #include "storage_interface.hpp"
9 #include "cpu_interface.hpp"
10 #include "network_interface.hpp"
12 #ifndef SURF_HOST_INTERFACE_HPP_
13 #define SURF_HOST_INTERFACE_HPP_
27 /** @ingroup SURF_callbacks
28 * @brief Callbacks fired after Host creation. Signature: `void(Host*)`
30 XBT_PUBLIC_DATA(surf_callback(void, Host*)) hostCreatedCallbacks;
32 /** @ingroup SURF_callbacks
33 * @brief Callbacks fired Host destruction. Signature: `void(Host*)`
35 XBT_PUBLIC_DATA(surf_callback(void, Host*)) hostDestructedCallbacks;
37 /** @ingroup SURF_callbacks
38 * @brief Callbacks fired after Host State changed. Signature: `void(Host *, e_surf_resource_state_t old, e_surf_resource_state_t current)`
40 XBT_PUBLIC_DATA(surf_callback(void, Host*, e_surf_resource_state_t, e_surf_resource_state_t)) hostStateChangedCallbacks;
42 /** @ingroup SURF_callbacks
43 * @brief Callbacks fired HostAction State changed. Signature: `void(HostAction *, e_surf_action_state_t old, e_surf_action_state_t current)`
45 XBT_PUBLIC_DATA(surf_callback(void, HostAction*, e_surf_action_state_t, e_surf_action_state_t)) hostActionStateChangedCallbacks;
50 XBT_PUBLIC_DATA(HostModel*) surf_host_model;
51 XBT_PUBLIC(void) host_parse_init(sg_platf_host_cbarg_t host);
52 XBT_PUBLIC(void) host_add_traces();
57 /** @ingroup SURF_host_interface
58 * @brief SURF Host model interface class
59 * @details A model is an object which handle the interactions between its Resources and its Actions
61 class HostModel : public Model {
63 HostModel() : Model() {}
66 virtual Host *createHost(const char *name)=0;
67 void addTraces(){DIE_IMPOSSIBLE;}
69 virtual void adjustWeightOfDummyCpuActions();
70 virtual Action *executeParallelTask(int host_nb,
76 bool shareResourcesIsIdempotent() {return true;}
82 /** @ingroup SURF_host_interface
83 * @brief SURF Host interface class
84 * @details An host represents a machine with a aggregation of a Cpu, a Link and a Storage
86 class Host : public Resource {
89 * @brief Host constructor
91 * @param model HostModel associated to this Host
92 * @param name The name of the Host
93 * @param props Dictionary of properties associated to this Host
94 * @param storage The Storage associated to this Host
95 * @param netElm The RoutingEdge associated to this Host
96 * @param cpu The Cpu associated to this Host
98 Host(Model *model, const char *name, xbt_dict_t props,
99 xbt_dynar_t storage, RoutingEdge *netElm, Cpu *cpu);
102 * @brief Host constructor
104 * @param model HostModel associated to this Host
105 * @param name The name of the Host
106 * @param props Dictionary of properties associated to this Host
107 * @param constraint The lmm constraint associated to this Host if it is part of a LMM component
108 * @param storage The Storage associated to this Host
109 * @param netElm The RoutingEdge associated to this Host
110 * @param cpu The Cpu associated to this Host
112 Host(Model *model, const char *name, xbt_dict_t props,
113 lmm_constraint_t constraint, xbt_dynar_t storage, RoutingEdge *netElm,
116 /** @brief Host destructor */
119 void setState(e_surf_resource_state_t state);
122 * @brief Get the properties of the current Host
124 * @return The properties of the current Host
126 xbt_dict_t getProperties();
129 * @brief Execute some quantity of computation
131 * @param flops_amount The value of the processing amount (in flop) needed to process
132 * @return The CpuAction corresponding to the processing
135 virtual Action *execute(double flops_amount)=0;
138 * @brief Make a process sleep for duration seconds
140 * @param duration The number of seconds to sleep
141 * @return The CpuAction corresponding to the sleeping
144 virtual Action *sleep(double duration)=0;
146 /** @brief Return the storage of corresponding mount point */
147 virtual Storage *findStorageOnMountList(const char* storage);
149 /** @brief Get the xbt_dict_t of mount_point: Storage */
150 virtual xbt_dict_t getMountedStorageList();
152 /** @brief Get the xbt_dynar_t of storages attached to the Host */
153 virtual xbt_dynar_t getAttachedStorageList();
158 * @param fullpath The full path to the file
160 * @return The StorageAction corresponding to the opening
162 virtual Action *open(const char* fullpath);
165 * @brief Close a file
167 * @param fd The file descriptor to close
168 * @return The StorageAction corresponding to the closing
170 virtual Action *close(surf_file_t fd);
173 * @brief Unlink a file
174 * @details [long description]
176 * @param fd [description]
177 * @return [description]
179 virtual int unlink(surf_file_t fd);
182 * @brief Get the size in bytes of the file
184 * @param fd The file descriptor to read
185 * @return The size in bytes of the file
187 virtual sg_size_t getSize(surf_file_t fd);
192 * @param fd The file descriptor to read
193 * @param size The size in bytes to read
194 * @return The StorageAction corresponding to the reading
196 virtual Action *read(surf_file_t fd, sg_size_t size);
199 * @brief Write a file
201 * @param fd The file descriptor to write
202 * @param size The size in bytes to write
203 * @return The StorageAction corresponding to the writing
205 virtual Action *write(surf_file_t fd, sg_size_t size);
208 * @brief Get the informations of a file descriptor
209 * @details The returned xbt_dynar_t contains:
210 * - the size of the file,
212 * - the storage name,
213 * - the storage typeId,
214 * - the storage content type
216 * @param fd The file descriptor
217 * @return An xbt_dynar_t with the file informations
219 virtual xbt_dynar_t getInfo(surf_file_t fd);
222 * @brief Get the current position of the file descriptor
224 * @param fd The file descriptor
225 * @return The current position of the file descriptor
227 virtual sg_size_t fileTell(surf_file_t fd);
230 * @brief Set the position indicator associated with the file descriptor to a new position
231 * @details [long description]
233 * @param fd The file descriptor
234 * @param offset The offset from the origin
235 * @param origin Position used as a reference for the offset
236 * - SEEK_SET: beginning of the file
237 * - SEEK_CUR: current position indicator
238 * - SEEK_END: end of the file
239 * @return MSG_OK if successful, otherwise MSG_TASK_CANCELED
241 virtual int fileSeek(surf_file_t fd, sg_offset_t offset, int origin);
244 * @brief Move a file to another location on the *same mount point*.
245 * @details [long description]
247 * @param fd The file descriptor
248 * @param fullpath The new full path
249 * @return MSG_OK if successful, MSG_TASK_CANCELED and a warning if the new
250 * full path is not on the same mount point
252 virtual int fileMove(surf_file_t fd, const char* fullpath);
254 xbt_dynar_t p_storage;
255 RoutingEdge *p_netElm;
258 /** @brief Get the list of virtual machines on the current Host */
259 xbt_dynar_t getVms();
262 /** @brief Retrieve a copy of the parameters of that VM/PM
263 * @details The ramsize and overcommit fields are used on the PM too */
264 void getParams(vm_params_t params);
265 /** @brief Sets the params of that VM/PM */
266 void setParams(vm_params_t params);
268 s_vm_params_t p_params;
275 /** @ingroup SURF_host_interface
276 * @brief SURF host action interface class
278 class HostAction : public Action {
281 * @brief HostAction constructor
283 * @param model The HostModel associated to this HostAction
284 * @param cost The cost of this HostAction in [TODO]
285 * @param failed [description]
287 HostAction(Model *model, double cost, bool failed)
288 : Action(model, cost, failed) {}
291 * @brief HostAction constructor
293 * @param model The HostModel associated to this HostAction
294 * @param cost The cost of this HostAction in [TODO]
295 * @param failed [description]
296 * @param var The lmm variable associated to this StorageAction if it is part of a LMM component
298 HostAction(Model *model, double cost, bool failed, lmm_variable_t var)
299 : Action(model, cost, failed, var) {}
301 void setState(e_surf_action_state_t state);
305 #endif /* SURF_Host_INTERFACE_HPP_ */