1 /* Copyright (c) 2004-2014. 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 /** @brief Constructor */
64 HostModel(const char *name);
66 /** @brief Constructor */
69 /** @brief Destructor */
72 virtual Host *createHost(const char *name)=0;
73 void addTraces(){DIE_IMPOSSIBLE;}
75 virtual void adjustWeightOfDummyCpuActions();
76 virtual Action *executeParallelTask(int host_nb,
82 virtual Action *communicate(Host *src, Host *dst, double size, double rate)=0;
84 bool shareResourcesIsIdempotent() {return true;}
90 /** @ingroup SURF_host_interface
91 * @brief SURF Host interface class
92 * @details An host represents a machine with a aggregation of a Cpu, a Link and a Storage
94 class Host : public Resource {
97 * @brief Host constructor
99 * @param model HostModel associated to this Host
100 * @param name The name of the Host
101 * @param props Dictionary of properties associated to this Host
102 * @param storage The Storage associated to this Host
103 * @param netElm The RoutingEdge associated to this Host
104 * @param cpu The Cpu associated to this Host
106 Host(Model *model, const char *name, xbt_dict_t props,
107 xbt_dynar_t storage, RoutingEdge *netElm, Cpu *cpu);
110 * @brief Host constructor
112 * @param model HostModel associated to this Host
113 * @param name The name of the Host
114 * @param props Dictionary of properties associated to this Host
115 * @param constraint The lmm constraint associated to this Host if it is part of a LMM component
116 * @param storage The Storage associated to this Host
117 * @param netElm The RoutingEdge associated to this Host
118 * @param cpu The Cpu associated to this Host
120 Host(Model *model, const char *name, xbt_dict_t props,
121 lmm_constraint_t constraint, xbt_dynar_t storage, RoutingEdge *netElm,
124 /** @brief Host destructor */
127 void setState(e_surf_resource_state_t state);
130 * @brief Get the properties of the current Host
132 * @return The properties of the current Host
134 xbt_dict_t getProperties();
137 * @brief Execute some quantity of computation
139 * @param flops_amount The value of the processing amount (in flop) needed to process
140 * @return The CpuAction corresponding to the processing
143 virtual Action *execute(double flops_amount)=0;
146 * @brief Make a process sleep for duration seconds
148 * @param duration The number of seconds to sleep
149 * @return The CpuAction corresponding to the sleeping
152 virtual Action *sleep(double duration)=0;
155 * @brief Get the number of cores of the associated Cpu
157 * @return The number of cores of the associated Cpu
160 virtual int getCore();
163 * @brief Get the speed of the associated Cpu
166 * @return The speed of the associated Cpu
169 virtual double getSpeed(double load);
172 * @brief Get the available speed of the associated Cpu
175 * @return The available speed of the associated Cpu
178 virtual double getAvailableSpeed();
181 * @brief Get the associated Cpu power peak
183 * @return The associated Cpu power peak
186 virtual double getCurrentPowerPeak();
188 virtual double getPowerPeakAt(int pstate_index);
189 virtual int getNbPstates();
190 virtual void setPstate(int pstate_index);
191 virtual int getPstate();
194 * @brief Return the storage of corresponding mount point
196 * @param storage The mount point
197 * @return The corresponding Storage
199 virtual Storage *findStorageOnMountList(const char* storage);
202 * @brief Get the xbt_dict_t of mount_point: Storage
204 * @return The xbt_dict_t of mount_point: Storage
206 virtual xbt_dict_t getMountedStorageList();
209 * @brief Get the xbt_dynar_t of storages attached to the Host
211 * @return The xbt_dynar_t of Storage names
213 virtual xbt_dynar_t getAttachedStorageList();
218 * @param fullpath The full path to the file
220 * @return The StorageAction corresponding to the opening
222 virtual Action *open(const char* fullpath);
225 * @brief Close a file
227 * @param fd The file descriptor to close
228 * @return The StorageAction corresponding to the closing
230 virtual Action *close(surf_file_t fd);
233 * @brief Unlink a file
234 * @details [long description]
236 * @param fd [description]
237 * @return [description]
239 virtual int unlink(surf_file_t fd);
242 * @brief Get the size in bytes of the file
244 * @param fd The file descriptor to read
245 * @return The size in bytes of the file
247 virtual sg_size_t getSize(surf_file_t fd);
252 * @param fd The file descriptor to read
253 * @param size The size in bytes to read
254 * @return The StorageAction corresponding to the reading
256 virtual Action *read(surf_file_t fd, sg_size_t size);
259 * @brief Write a file
261 * @param fd The file descriptor to write
262 * @param size The size in bytes to write
263 * @return The StorageAction corresponding to the writing
265 virtual Action *write(surf_file_t fd, sg_size_t size);
268 * @brief Get the informations of a file descriptor
269 * @details The returned xbt_dynar_t contains:
270 * - the size of the file,
272 * - the storage name,
273 * - the storage typeId,
274 * - the storage content type
276 * @param fd The file descriptor
277 * @return An xbt_dynar_t with the file informations
279 virtual xbt_dynar_t getInfo(surf_file_t fd);
282 * @brief Get the current position of the file descriptor
284 * @param fd The file descriptor
285 * @return The current position of the file descriptor
287 virtual sg_size_t fileTell(surf_file_t fd);
290 * @brief Set the position indicator associated with the file descriptor to a new position
291 * @details [long description]
293 * @param fd The file descriptor
294 * @param offset The offset from the origin
295 * @param origin Position used as a reference for the offset
296 * - SEEK_SET: beginning of the file
297 * - SEEK_CUR: current position indicator
298 * - SEEK_END: end of the file
299 * @return MSG_OK if successful, otherwise MSG_TASK_CANCELED
301 virtual int fileSeek(surf_file_t fd, sg_offset_t offset, int origin);
304 * @brief Move a file to another location on the *same mount point*.
305 * @details [long description]
307 * @param fd The file descriptor
308 * @param fullpath The new full path
309 * @return MSG_OK if successful, MSG_TASK_CANCELED and a warning if the new
310 * full path is not on the same mount point
312 virtual int fileMove(surf_file_t fd, const char* fullpath);
314 xbt_dynar_t p_storage;
315 RoutingEdge *p_netElm;
319 * @brief Get the list of virtual machines on the current Host
321 * @return The list of VMs
323 xbt_dynar_t getVms();
327 * @brief [brief description]
328 * @details [long description]
330 * @param params [description]
332 void getParams(ws_params_t params);
335 * @brief [brief description]
336 * @details [long description]
338 * @param params [description]
340 void setParams(ws_params_t params);
341 s_ws_params_t p_params;
348 /** @ingroup SURF_host_interface
349 * @brief SURF host action interface class
351 class HostAction : public Action {
354 * @brief HostAction constructor
356 * @param model The HostModel associated to this HostAction
357 * @param cost The cost of this HostAction in [TODO]
358 * @param failed [description]
360 HostAction(Model *model, double cost, bool failed)
361 : Action(model, cost, failed) {}
364 * @brief HostAction constructor
366 * @param model The HostModel associated to this HostAction
367 * @param cost The cost of this HostAction in [TODO]
368 * @param failed [description]
369 * @param var The lmm variable associated to this StorageAction if it is part of a LMM component
371 HostAction(Model *model, double cost, bool failed, lmm_variable_t var)
372 : Action(model, cost, failed, var) {}
374 void setState(e_surf_action_state_t state);
378 #endif /* SURF_Host_INTERFACE_HPP_ */