1 #include "workstation_interface.hpp"
2 #include "vm_workstation_interface.hpp"
3 #include "cpu_cas01.hpp"
4 #include "simgrid/sg_config.h"
6 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_workstation, surf,
7 "Logging specific to the SURF workstation module");
9 WorkstationModelPtr surf_workstation_model = NULL;
15 surf_callback(void, WorkstationPtr) workstationCreatedCallbacks;
16 surf_callback(void, WorkstationPtr) workstationDestructedCallbacks;
17 surf_callback(void, WorkstationPtr) workstationStateChangedCallbacks;
18 surf_callback(void, WorkstationActionPtr) workstationActionStateChangedCallbacks;
23 WorkstationModel::WorkstationModel(const char *name)
26 p_cpuModel = surf_cpu_model_pm;
29 WorkstationModel::WorkstationModel()
30 : Model("Workstation") {
31 p_cpuModel = surf_cpu_model_pm;
34 WorkstationModel::~WorkstationModel() {
37 /* Each VM has a dummy CPU action on the PM layer. This CPU action works as the
38 * constraint (capacity) of the VM in the PM layer. If the VM does not have any
39 * active task, the dummy CPU action must be deactivated, so that the VM does
40 * not get any CPU share in the PM layer. */
41 void WorkstationModel::adjustWeightOfDummyCpuActions()
43 /* iterate for all hosts including virtual machines */
44 xbt_lib_cursor_t cursor;
48 xbt_lib_foreach(host_lib, cursor, key, ind_host) {
49 WorkstationPtr ws = static_cast<WorkstationPtr>(ind_host[SURF_WKS_LEVEL]);
50 CpuCas01Ptr cpu_cas01 = static_cast<CpuCas01Ptr>(ind_host[SURF_CPU_LEVEL]);
54 /* skip if it is not a virtual machine */
55 if (ws->getModel() != static_cast<ModelPtr>(surf_vm_workstation_model))
57 xbt_assert(cpu_cas01, "cpu-less workstation");
59 /* It is a virtual machine, so we can cast it to workstation_VM2013_t */
60 WorkstationVMPtr ws_vm = static_cast<WorkstationVMPtr>(ws);
62 int is_active = lmm_constraint_used(cpu_cas01->getModel()->getMaxminSystem(), cpu_cas01->getConstraint());
63 // int is_active_old = constraint_is_active(cpu_cas01);
66 // xbt_assert(is_active == is_active_old, "%d %d", is_active, is_active_old);
70 /* some tasks exist on this VM */
71 XBT_DEBUG("set the weight of the dummy CPU action on PM to 1");
73 /* FIXME: we shoud use lmm_update_variable_weight() ? */
74 /* FIXME: If we assgign 1.05 and 0.05, the system makes apparently wrong values. */
75 ws_vm->p_action->setPriority(1);
78 /* no task exits on this VM */
79 XBT_DEBUG("set the weight of the dummy CPU action on PM to 0");
81 ws_vm->p_action->setPriority(0);
89 Workstation::Workstation()
91 surf_callback_emit(workstationCreatedCallbacks, this);
94 Workstation::Workstation(ModelPtr model, const char *name, xbt_dict_t props,
95 xbt_dynar_t storage, RoutingEdgePtr netElm, CpuPtr cpu)
96 : Resource(model, name, props)
97 , p_storage(storage), p_netElm(netElm), p_cpu(cpu)
99 surf_callback_emit(workstationCreatedCallbacks, this);
102 Workstation::Workstation(ModelPtr model, const char *name, xbt_dict_t props, lmm_constraint_t constraint,
103 xbt_dynar_t storage, RoutingEdgePtr netElm, CpuPtr cpu)
104 : Resource(model, name, props, constraint)
105 , p_storage(storage), p_netElm(netElm), p_cpu(cpu)
107 surf_callback_emit(workstationCreatedCallbacks, this);
110 Workstation::~Workstation(){
111 surf_callback_emit(workstationDestructedCallbacks, this);
114 void Workstation::setState(e_surf_resource_state_t state){
115 Resource::setState(state);
116 surf_callback_emit(workstationStateChangedCallbacks, this);
119 int Workstation::getCore(){
120 return p_cpu->getCore();
123 double Workstation::getSpeed(double load){
124 return p_cpu->getSpeed(load);
127 double Workstation::getAvailableSpeed(){
128 return p_cpu->getAvailableSpeed();
131 double Workstation::getCurrentPowerPeak()
133 return p_cpu->getCurrentPowerPeak();
136 double Workstation::getPowerPeakAt(int pstate_index)
138 return p_cpu->getPowerPeakAt(pstate_index);
141 int Workstation::getNbPstates()
143 return p_cpu->getNbPstates();
146 void Workstation::setPowerPeakAt(int pstate_index)
148 p_cpu->setPowerPeakAt(pstate_index);
151 xbt_dict_t Workstation::getProperties()
153 return p_cpu->getProperties();
156 StoragePtr Workstation::findStorageOnMountList(const char* mount)
158 StoragePtr st = NULL;
162 XBT_DEBUG("Search for storage name '%s' on '%s'", mount, getName());
163 xbt_dynar_foreach(p_storage,cursor,mnt)
165 XBT_DEBUG("See '%s'",mnt.name);
166 if(!strcmp(mount,mnt.name)){
167 st = static_cast<StoragePtr>(mnt.storage);
171 if(!st) xbt_die("Can't find mount '%s' for '%s'", mount, getName());
175 xbt_dict_t Workstation::getStorageList()
179 xbt_dict_t storage_list = xbt_dict_new_homogeneous(NULL);
180 char *storage_name = NULL;
182 xbt_dynar_foreach(p_storage,i,mnt){
183 storage_name = (char *)static_cast<StoragePtr>(mnt.storage)->getName();
184 xbt_dict_set(storage_list,mnt.name,storage_name,NULL);
189 ActionPtr Workstation::open(const char* mount, const char* path) {
190 StoragePtr st = findStorageOnMountList(mount);
191 XBT_DEBUG("OPEN on disk '%s'", st->getName());
192 return st->open(mount, path);
195 ActionPtr Workstation::close(surf_file_t fd) {
196 StoragePtr st = findStorageOnMountList(fd->mount);
197 XBT_DEBUG("CLOSE on disk '%s'",st->getName());
198 return st->close(fd);
201 ActionPtr Workstation::read(surf_file_t fd, sg_size_t size) {
202 StoragePtr st = findStorageOnMountList(fd->mount);
203 XBT_DEBUG("READ on disk '%s'",st->getName());
204 return st->read(fd, size);
207 ActionPtr Workstation::write(surf_file_t fd, sg_size_t size) {
208 StoragePtr st = findStorageOnMountList(fd->mount);
209 XBT_DEBUG("WRITE on disk '%s'",st->getName());
210 return st->write(fd, size);
213 int Workstation::unlink(surf_file_t fd) {
215 XBT_WARN("No such file descriptor. Impossible to unlink");
218 // XBT_INFO("%s %zu", fd->storage, fd->size);
219 StoragePtr st = findStorageOnMountList(fd->mount);
220 /* Check if the file is on this storage */
221 if (!xbt_dict_get_or_null(st->p_content, fd->name)){
222 XBT_WARN("File %s is not on disk %s. Impossible to unlink", fd->name,
226 XBT_DEBUG("UNLINK on disk '%s'",st->getName());
227 st->m_usedSize -= fd->size;
229 // Remove the file from storage
230 xbt_dict_remove(st->p_content, fd->name);
240 ActionPtr Workstation::ls(const char* mount, const char *path){
241 XBT_DEBUG("LS on mount '%s' and file '%s'", mount, path);
242 StoragePtr st = findStorageOnMountList(mount);
246 sg_size_t Workstation::getSize(surf_file_t fd){
250 xbt_dynar_t Workstation::getInfo( surf_file_t fd)
252 StoragePtr st = findStorageOnMountList(fd->mount);
253 sg_size_t *psize = xbt_new(sg_size_t, 1);
255 xbt_dynar_t info = xbt_dynar_new(sizeof(void*), NULL);
256 xbt_dynar_push_as(info, sg_size_t *, psize);
257 xbt_dynar_push_as(info, void *, fd->mount);
258 xbt_dynar_push_as(info, void *, (void *)st->getName());
259 xbt_dynar_push_as(info, void *, st->p_typeId);
260 xbt_dynar_push_as(info, void *, st->p_contentType);
265 sg_size_t Workstation::fileTell(surf_file_t fd){
266 return fd->current_position;
269 int Workstation::fileSeek(surf_file_t fd, sg_size_t offset, int origin){
273 fd->current_position = 0;
276 if(offset > fd->size)
278 fd->current_position = offset;
281 fd->current_position = fd->size;
284 return MSG_TASK_CANCELED;
288 sg_size_t Workstation::getFreeSize(const char* name)
290 StoragePtr st = findStorageOnMountList(name);
291 return st->m_size - st->m_usedSize;
294 sg_size_t Workstation::getUsedSize(const char* name)
296 StoragePtr st = findStorageOnMountList(name);
297 return st->m_usedSize;
300 xbt_dynar_t Workstation::getVms()
302 xbt_dynar_t dyn = xbt_dynar_new(sizeof(smx_host_t), NULL);
304 /* iterate for all hosts including virtual machines */
305 xbt_lib_cursor_t cursor;
308 xbt_lib_foreach(host_lib, cursor, key, ind_host) {
309 WorkstationPtr ws = static_cast<WorkstationPtr>(ind_host[SURF_WKS_LEVEL]);
312 /* skip if it is not a virtual machine */
313 if (ws->getModel() != static_cast<ModelPtr>(surf_vm_workstation_model))
316 /* It is a virtual machine, so we can cast it to workstation_VM2013_t */
317 WorkstationVMPtr ws_vm = static_cast<WorkstationVMPtr>(ws);
318 if (this == ws_vm-> p_subWs)
319 xbt_dynar_push(dyn, &ws_vm->p_subWs);
325 void Workstation::getParams(ws_params_t params)
327 memcpy(params, &p_params, sizeof(s_ws_params_t));
330 void Workstation::setParams(ws_params_t params)
332 /* may check something here. */
333 memcpy(&p_params, params, sizeof(s_ws_params_t));
340 void WorkstationAction::setState(e_surf_action_state_t state){
341 Action::setState(state);
342 surf_callback_emit(workstationActionStateChangedCallbacks, this);