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, sg_host_t *host_list,
59 double *flops_amount, double *bytes_amount, double rate);
61 bool next_occuring_event_isIdempotent() override {return true;}
67 /** @ingroup SURF_host_interface
68 * @brief SURF Host interface class
69 * @details An host represents a machine with a aggregation of a Cpu, a RoutingEdge and a Storage
72 : public simgrid::surf::Resource,
73 public simgrid::surf::PropertyHolder {
75 static simgrid::xbt::Extension<simgrid::s4u::Host, HostImpl> EXTENSION_ID;
78 static void classInit(); // must be called before the first use of that class
80 * @brief Host constructor
82 * @param model HostModel associated to this Host
83 * @param name The name of the Host
84 * @param props Dictionary of properties associated to this Host
85 * @param storage The Storage associated to this Host
86 * @param cpu The Cpu associated to this Host
88 HostImpl(HostModel *model, const char *name, xbt_dict_t props, xbt_dynar_t storage, Cpu *cpu);
91 * @brief Host constructor
93 * @param model HostModel associated to this Host
94 * @param name The name of the Host
95 * @param props Dictionary of properties associated to this Host
96 * @param constraint The lmm constraint associated to this Host if it is part of a LMM component
97 * @param storage The Storage associated to this Host
98 * @param cpu The Cpu associated to this Host
100 HostImpl(HostModel *model, const char *name, xbt_dict_t props,
101 lmm_constraint_t constraint, xbt_dynar_t storage, Cpu *cpu);
103 /* Host destruction logic */
104 /**************************/
108 HostModel *getModel()
110 return static_cast<HostModel*>(Resource::getModel());
112 void attach(simgrid::s4u::Host* host);
114 bool isOn() const override;
115 bool isOff() const override;
116 void turnOn() override;
117 void turnOff() override;
119 /** @brief Return the storage of corresponding mount point */
120 virtual simgrid::surf::Storage *findStorageOnMountList(const char* storage);
122 /** @brief Get the xbt_dict_t of mount_point: Storage */
123 virtual xbt_dict_t getMountedStorageList();
125 /** @brief Get the xbt_dynar_t of storages attached to the Host */
126 virtual xbt_dynar_t getAttachedStorageList();
131 * @param fullpath The full path to the file
132 * @return The StorageAction corresponding to the opening
134 virtual Action *open(const char* fullpath);
137 * @brief Close a file
139 * @param fd The file descriptor to close
140 * @return The StorageAction corresponding to the closing
142 virtual Action *close(surf_file_t fd);
145 * @brief Unlink a file
146 * @details [long description]
148 * @param fd [description]
149 * @return [description]
151 virtual int unlink(surf_file_t fd);
154 * @brief Get the size in bytes of the file
156 * @param fd The file descriptor to read
157 * @return The size in bytes of the file
159 virtual sg_size_t getSize(surf_file_t fd);
164 * @param fd The file descriptor to read
165 * @param size The size in bytes to read
166 * @return The StorageAction corresponding to the reading
168 virtual Action *read(surf_file_t fd, sg_size_t size);
171 * @brief Write a file
173 * @param fd The file descriptor to write
174 * @param size The size in bytes to write
175 * @return The StorageAction corresponding to the writing
177 virtual Action *write(surf_file_t fd, sg_size_t size);
180 * @brief Get the informations of a file descriptor
181 * @details The returned xbt_dynar_t contains:
182 * - the size of the file,
184 * - the storage name,
185 * - the storage typeId,
186 * - the storage content type
188 * @param fd The file descriptor
189 * @return An xbt_dynar_t with the file informations
191 virtual xbt_dynar_t getInfo(surf_file_t fd);
194 * @brief Get the current position of the file descriptor
196 * @param fd The file descriptor
197 * @return The current position of the file descriptor
199 virtual sg_size_t fileTell(surf_file_t fd);
202 * @brief Set the position indicator associated with the file descriptor to a new position
203 * @details [long description]
205 * @param fd The file descriptor
206 * @param offset The offset from the origin
207 * @param origin Position used as a reference for the offset
208 * - SEEK_SET: beginning of the file
209 * - SEEK_CUR: current position indicator
210 * - SEEK_END: end of the file
211 * @return MSG_OK if successful, otherwise MSG_TASK_CANCELED
213 virtual int fileSeek(surf_file_t fd, sg_offset_t offset, int origin);
216 * @brief Move a file to another location on the *same mount point*.
217 * @details [long description]
219 * @param fd The file descriptor
220 * @param fullpath The new full path
221 * @return MSG_OK if successful, MSG_TASK_CANCELED and a warning if the new
222 * full path is not on the same mount point
224 virtual int fileMove(surf_file_t fd, const char* fullpath);
226 bool isUsed() override {DIE_IMPOSSIBLE;} // FIXME: Host should not be a Resource
227 void apply_event(tmgr_trace_iterator_t event, double value) override
228 {THROW_IMPOSSIBLE;} // FIXME: Host should not be a Resource
231 xbt_dynar_t p_storage;
233 simgrid::s4u::Host* p_host = nullptr;
235 /** @brief Get the list of virtual machines on the current Host */
236 xbt_dynar_t getVms();
239 /** @brief Retrieve a copy of the parameters of that VM/PM
240 * @details The ramsize and overcommit fields are used on the PM too */
241 void getParams(vm_params_t params);
242 /** @brief Sets the params of that VM/PM */
243 void setParams(vm_params_t params);
244 simgrid::s4u::Host* getHost() { return p_host; }
246 s_vm_params_t p_params;
252 #endif /* SURF_Host_INTERFACE_HPP_ */