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_
20 typedef HostModel *HostModelPtr;
23 typedef Host *HostPtr;
26 typedef HostAction *HostActionPtr;
32 /** @ingroup SURF_callbacks
33 * @brief Callbacks handler which emit the callbacks after Host creation *
34 * @details Callback functions have the following signature: `void(HostPtr)`
36 XBT_PUBLIC_DATA(surf_callback(void, HostPtr)) hostCreatedCallbacks;
38 /** @ingroup SURF_callbacks
39 * @brief Callbacks handler which emit the callbacks after Host destruction *
40 * @details Callback functions have the following signature: `void(HostPtr)`
42 XBT_PUBLIC_DATA(surf_callback(void, HostPtr)) hostDestructedCallbacks;
44 /** @ingroup SURF_callbacks
45 * @brief Callbacks handler which emit the callbacks after Host State changed *
46 * @details Callback functions have the following signature: `void(HostActionPtr action, e_surf_resource_state_t old, e_surf_resource_state_t current)`
48 XBT_PUBLIC_DATA(surf_callback(void, HostPtr, e_surf_resource_state_t, e_surf_resource_state_t)) hostStateChangedCallbacks;
50 /** @ingroup SURF_callbacks
51 * @brief Callbacks handler which emit the callbacks after HostAction State changed *
52 * @details Callback functions have the following signature: `void(HostActionPtr action, e_surf_resource_state_t old, e_surf_resource_state_t current)`
54 XBT_PUBLIC_DATA(surf_callback(void, HostActionPtr, e_surf_action_state_t, e_surf_action_state_t)) hostActionStateChangedCallbacks;
59 XBT_PUBLIC_DATA(HostModelPtr) surf_host_model;
60 XBT_PUBLIC(void) host_parse_init(sg_platf_host_cbarg_t host);
61 XBT_PUBLIC(void) host_add_traces();
66 /** @ingroup SURF_host_interface
67 * @brief SURF Host model interface class
68 * @details A model is an object which handle the interactions between its Resources and its Actions
70 class HostModel : public Model {
73 * @brief HostModel constructor
75 * @param name the name of the model
77 HostModel(const char *name);
79 /** @brief HostModel constructor */
82 /** @brief HostModel destructor */
85 virtual HostPtr createHost(const char *name)=0;
86 void addTraces(){DIE_IMPOSSIBLE;}
89 * @brief [brief description]
90 * @details [long description]
92 virtual void adjustWeightOfDummyCpuActions();
95 * @brief [brief description]
96 * @details [long description]
98 * @param host_nb [description]
99 * @param host_list [description]
100 * @param flops_amount [description]
101 * @param bytes_amount [description]
102 * @param rate [description]
103 * @return [description]
105 virtual ActionPtr executeParallelTask(int host_nb,
107 double *flops_amount,
108 double *bytes_amount,
112 * @brief [brief description]
113 * @details [long description]
115 * @param src [description]
116 * @param dst [description]
117 * @param size [description]
118 * @param rate [description]
119 * @return [description]
121 virtual ActionPtr communicate(HostPtr src, HostPtr dst, double size, double rate)=0;
123 CpuModelPtr p_cpuModel;
129 /** @ingroup SURF_host_interface
130 * @brief SURF Host interface class
131 * @details An host represents a machine with a aggregation of a Cpu, a NetworkLink and a Storage
133 class Host : public Resource {
136 * @brief Host constructor
138 * @param model HostModel associated to this Host
139 * @param name The name of the Host
140 * @param props Dictionary of properties associated to this Host
141 * @param storage The Storage associated to this Host
142 * @param netElm The RoutingEdge associated to this Host
143 * @param cpu The Cpu associated to this Host
145 Host(ModelPtr model, const char *name, xbt_dict_t props,
146 xbt_dynar_t storage, RoutingEdgePtr netElm, CpuPtr cpu);
149 * @brief Host constructor
151 * @param model HostModel associated to this Host
152 * @param name The name of the Host
153 * @param props Dictionary of properties associated to this Host
154 * @param constraint The lmm constraint associated to this Host if it is part of a LMM component
155 * @param storage The Storage associated to this Host
156 * @param netElm The RoutingEdge associated to this Host
157 * @param cpu The Cpu associated to this Host
159 Host(ModelPtr model, const char *name, xbt_dict_t props,
160 lmm_constraint_t constraint, xbt_dynar_t storage, RoutingEdgePtr netElm,
163 /** @brief Host destructor */
166 void setState(e_surf_resource_state_t state);
169 * @brief Get the properties of the current Host
171 * @return The properties of the current Host
173 xbt_dict_t getProperties();
176 * @brief Execute some quantity of computation
178 * @param flops_amount The value of the processing amount (in flop) needed to process
179 * @return The CpuAction corresponding to the processing
182 virtual ActionPtr execute(double flops_amount)=0;
185 * @brief Make a process sleep for duration seconds
187 * @param duration The number of seconds to sleep
188 * @return The CpuAction corresponding to the sleeping
191 virtual ActionPtr sleep(double duration)=0;
194 * @brief Get the number of cores of the associated Cpu
196 * @return The number of cores of the associated Cpu
199 virtual int getCore();
202 * @brief Get the speed of the associated Cpu
205 * @return The speed of the associated Cpu
208 virtual double getSpeed(double load);
211 * @brief Get the available speed of the associated Cpu
214 * @return The available speed of the associated Cpu
217 virtual double getAvailableSpeed();
220 * @brief Get the associated Cpu power peak
222 * @return The associated Cpu power peak
225 virtual double getCurrentPowerPeak();
227 virtual double getPowerPeakAt(int pstate_index);
228 virtual int getNbPstates();
229 virtual void setPstate(int pstate_index);
230 virtual int getPstate();
233 * @brief Return the storage of corresponding mount point
235 * @param storage The mount point
236 * @return The corresponding Storage
238 virtual StoragePtr findStorageOnMountList(const char* storage);
241 * @brief Get the xbt_dict_t of mount_point: Storage
243 * @return The xbt_dict_t of mount_point: Storage
245 virtual xbt_dict_t getMountedStorageList();
248 * @brief Get the xbt_dynar_t of storages attached to the Host
250 * @return The xbt_dynar_t of Storage names
252 virtual xbt_dynar_t getAttachedStorageList();
257 * @param fullpath The full path to the file
259 * @return The StorageAction corresponding to the opening
261 virtual ActionPtr open(const char* fullpath);
264 * @brief Close a file
266 * @param fd The file descriptor to close
267 * @return The StorageAction corresponding to the closing
269 virtual ActionPtr close(surf_file_t fd);
272 * @brief Unlink a file
273 * @details [long description]
275 * @param fd [description]
276 * @return [description]
278 virtual int unlink(surf_file_t fd);
281 * @brief Get the size in bytes of the file
283 * @param fd The file descriptor to read
284 * @return The size in bytes of the file
286 virtual sg_size_t getSize(surf_file_t fd);
291 * @param fd The file descriptor to read
292 * @param size The size in bytes to read
293 * @return The StorageAction corresponding to the reading
295 virtual ActionPtr read(surf_file_t fd, sg_size_t size);
298 * @brief Write a file
300 * @param fd The file descriptor to write
301 * @param size The size in bytes to write
302 * @return The StorageAction corresponding to the writing
304 virtual ActionPtr write(surf_file_t fd, sg_size_t size);
307 * @brief Get the informations of a file descriptor
308 * @details The returned xbt_dynar_t contains:
309 * - the size of the file,
311 * - the storage name,
312 * - the storage typeId,
313 * - the storage content type
315 * @param fd The file descriptor
316 * @return An xbt_dynar_t with the file informations
318 virtual xbt_dynar_t getInfo(surf_file_t fd);
321 * @brief Get the current position of the file descriptor
323 * @param fd The file descriptor
324 * @return The current position of the file descriptor
326 virtual sg_size_t fileTell(surf_file_t fd);
329 * @brief Set the position indicator associated with the file descriptor to a new position
330 * @details [long description]
332 * @param fd The file descriptor
333 * @param offset The offset from the origin
334 * @param origin Position used as a reference for the offset
335 * - SEEK_SET: beginning of the file
336 * - SEEK_CUR: current position indicator
337 * - SEEK_END: end of the file
338 * @return MSG_OK if successful, otherwise MSG_TASK_CANCELED
340 virtual int fileSeek(surf_file_t fd, sg_offset_t offset, int origin);
343 * @brief Move a file to another location on the *same mount point*.
344 * @details [long description]
346 * @param fd The file descriptor
347 * @param fullpath The new full path
348 * @return MSG_OK if successful, MSG_TASK_CANCELED and a warning if the new
349 * full path is not on the same mount point
351 virtual int fileMove(surf_file_t fd, const char* fullpath);
353 xbt_dynar_t p_storage;
354 RoutingEdgePtr p_netElm;
356 NetworkLinkPtr p_network;
359 * @brief Get the list of virtual machines on the current Host
361 * @return The list of VMs
363 xbt_dynar_t getVms();
367 * @brief [brief description]
368 * @details [long description]
370 * @param params [description]
372 void getParams(ws_params_t params);
375 * @brief [brief description]
376 * @details [long description]
378 * @param params [description]
380 void setParams(ws_params_t params);
381 s_ws_params_t p_params;
388 /** @ingroup SURF_host_interface
389 * @brief SURF host action interface class
391 class HostAction : public Action {
394 * @brief HostAction constructor
396 * @param model The HostModel associated to this HostAction
397 * @param cost The cost of this HostAction in [TODO]
398 * @param failed [description]
400 HostAction(ModelPtr model, double cost, bool failed)
401 : Action(model, cost, failed) {}
404 * @brief HostAction constructor
406 * @param model The HostModel associated to this HostAction
407 * @param cost The cost of this HostAction in [TODO]
408 * @param failed [description]
409 * @param var The lmm variable associated to this StorageAction if it is part of a LMM component
411 HostAction(ModelPtr model, double cost, bool failed, lmm_variable_t var)
412 : Action(model, cost, failed, var) {}
414 void setState(e_surf_action_state_t state);
418 #endif /* SURF_Host_INTERFACE_HPP_ */