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"
11 #include "src/surf/PropertyHolder.hpp"
15 #ifndef SURF_HOST_INTERFACE_HPP_
16 #define SURF_HOST_INTERFACE_HPP_
25 class XBT_PRIVATE HostModel;
26 class XBT_PRIVATE HostImpl;
27 class XBT_PRIVATE HostAction;
37 XBT_PUBLIC_DATA(simgrid::surf::HostModel*) surf_host_model;
46 /** @ingroup SURF_host_interface
47 * @brief SURF Host model interface class
48 * @details A model is an object which handle the interactions between its Resources and its Actions
50 class HostModel : public Model {
52 HostModel() : Model() {}
53 ~HostModel() override {}
55 HostImpl *createHost(const char *name, NetCard *net, Cpu *cpu, xbt_dict_t props);
57 virtual void adjustWeightOfDummyCpuActions();
58 virtual Action *executeParallelTask(int host_nb,
64 bool next_occuring_event_isIdempotent() override {return true;}
70 /** @ingroup SURF_host_interface
71 * @brief SURF Host interface class
72 * @details An host represents a machine with a aggregation of a Cpu, a RoutingEdge and a Storage
75 : public simgrid::surf::Resource,
76 public simgrid::surf::PropertyHolder {
78 static simgrid::xbt::Extension<simgrid::s4u::Host, HostImpl> EXTENSION_ID;
81 static void classInit(); // must be called before the first use of that class
83 * @brief Host constructor
85 * @param model HostModel associated to this Host
86 * @param name The name of the Host
87 * @param props Dictionary of properties associated to this Host
88 * @param storage The Storage associated to this Host
89 * @param cpu The Cpu associated to this Host
91 HostImpl(HostModel *model, const char *name, xbt_dict_t props,
92 xbt_dynar_t storage, Cpu *cpu);
95 * @brief Host constructor
97 * @param model HostModel associated to this Host
98 * @param name The name of the Host
99 * @param props Dictionary of properties associated to this Host
100 * @param constraint The lmm constraint associated to this Host if it is part of a LMM component
101 * @param storage The Storage associated to this Host
102 * @param cpu The Cpu associated to this Host
104 HostImpl(HostModel *model, const char *name, xbt_dict_t props,
105 lmm_constraint_t constraint, xbt_dynar_t storage, Cpu *cpu);
107 /* Host destruction logic */
108 /**************************/
112 HostModel *getModel()
114 return static_cast<HostModel*>(Resource::getModel());
116 void attach(simgrid::s4u::Host* host);
118 bool isOn() override;
119 bool isOff() override;
120 void turnOn() override;
121 void turnOff() override;
123 /** @brief Return the storage of corresponding mount point */
124 virtual simgrid::surf::Storage *findStorageOnMountList(const char* storage);
126 /** @brief Get the xbt_dict_t of mount_point: Storage */
127 virtual xbt_dict_t getMountedStorageList();
129 /** @brief Get the xbt_dynar_t of storages attached to the Host */
130 virtual xbt_dynar_t getAttachedStorageList();
135 * @param fullpath The full path to the file
136 * @return The StorageAction corresponding to the opening
138 virtual Action *open(const char* fullpath);
141 * @brief Close a file
143 * @param fd The file descriptor to close
144 * @return The StorageAction corresponding to the closing
146 virtual Action *close(surf_file_t fd);
149 * @brief Unlink a file
150 * @details [long description]
152 * @param fd [description]
153 * @return [description]
155 virtual int unlink(surf_file_t fd);
158 * @brief Get the size in bytes of the file
160 * @param fd The file descriptor to read
161 * @return The size in bytes of the file
163 virtual sg_size_t getSize(surf_file_t fd);
168 * @param fd The file descriptor to read
169 * @param size The size in bytes to read
170 * @return The StorageAction corresponding to the reading
172 virtual Action *read(surf_file_t fd, sg_size_t size);
175 * @brief Write a file
177 * @param fd The file descriptor to write
178 * @param size The size in bytes to write
179 * @return The StorageAction corresponding to the writing
181 virtual Action *write(surf_file_t fd, sg_size_t size);
184 * @brief Get the informations of a file descriptor
185 * @details The returned xbt_dynar_t contains:
186 * - the size of the file,
188 * - the storage name,
189 * - the storage typeId,
190 * - the storage content type
192 * @param fd The file descriptor
193 * @return An xbt_dynar_t with the file informations
195 virtual xbt_dynar_t getInfo(surf_file_t fd);
198 * @brief Get the current position of the file descriptor
200 * @param fd The file descriptor
201 * @return The current position of the file descriptor
203 virtual sg_size_t fileTell(surf_file_t fd);
206 * @brief Set the position indicator associated with the file descriptor to a new position
207 * @details [long description]
209 * @param fd The file descriptor
210 * @param offset The offset from the origin
211 * @param origin Position used as a reference for the offset
212 * - SEEK_SET: beginning of the file
213 * - SEEK_CUR: current position indicator
214 * - SEEK_END: end of the file
215 * @return MSG_OK if successful, otherwise MSG_TASK_CANCELED
217 virtual int fileSeek(surf_file_t fd, sg_offset_t offset, int origin);
220 * @brief Move a file to another location on the *same mount point*.
221 * @details [long description]
223 * @param fd The file descriptor
224 * @param fullpath The new full path
225 * @return MSG_OK if successful, MSG_TASK_CANCELED and a warning if the new
226 * full path is not on the same mount point
228 virtual int fileMove(surf_file_t fd, const char* fullpath);
230 bool isUsed() override {DIE_IMPOSSIBLE;} // FIXME: Host should not be a Resource
231 void apply_event(tmgr_trace_iterator_t event, double value) override
232 {THROW_IMPOSSIBLE;} // FIXME: Host should not be a Resource
235 xbt_dynar_t p_storage;
237 simgrid::s4u::Host* p_host = nullptr;
239 /** @brief Get the list of virtual machines on the current Host */
240 xbt_dynar_t getVms();
243 /** @brief Retrieve a copy of the parameters of that VM/PM
244 * @details The ramsize and overcommit fields are used on the PM too */
245 void getParams(vm_params_t params);
246 /** @brief Sets the params of that VM/PM */
247 void setParams(vm_params_t params);
248 simgrid::s4u::Host* getHost() { return p_host; }
250 s_vm_params_t p_params;
256 #endif /* SURF_Host_INTERFACE_HPP_ */