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;
14 WorkstationModel::WorkstationModel(const char *name)
17 p_cpuModel = surf_cpu_model_pm;
20 WorkstationModel::WorkstationModel()
21 : Model("Workstation") {
22 p_cpuModel = surf_cpu_model_pm;
25 WorkstationModel::~WorkstationModel() {
30 /* Each VM has a dummy CPU action on the PM layer. This CPU action works as the
31 * constraint (capacity) of the VM in the PM layer. If the VM does not have any
32 * active task, the dummy CPU action must be deactivated, so that the VM does
33 * not get any CPU share in the PM layer. */
34 void WorkstationModel::adjustWeightOfDummyCpuActions()
36 /* iterate for all hosts including virtual machines */
37 xbt_lib_cursor_t cursor;
41 xbt_lib_foreach(host_lib, cursor, key, ind_host) {
42 WorkstationPtr ws = dynamic_cast<WorkstationPtr>(
43 static_cast<ResourcePtr>(ind_host[SURF_WKS_LEVEL]));
44 CpuCas01LmmPtr cpu_cas01 = dynamic_cast<CpuCas01LmmPtr>(
45 static_cast<ResourcePtr>(ind_host[SURF_CPU_LEVEL]));
49 /* skip if it is not a virtual machine */
50 if (ws->getModel() != static_cast<ModelPtr>(surf_vm_workstation_model))
52 xbt_assert(cpu_cas01, "cpu-less workstation");
54 /* It is a virtual machine, so we can cast it to workstation_VM2013_t */
55 WorkstationVMLmmPtr ws_vm = dynamic_cast<WorkstationVMLmmPtr>(ws);
57 int is_active = lmm_constraint_used(cpu_cas01->getModel()->getMaxminSystem(), cpu_cas01->constraint());
58 // int is_active_old = constraint_is_active(cpu_cas01);
61 // xbt_assert(is_active == is_active_old, "%d %d", is_active, is_active_old);
65 /* some tasks exist on this VM */
66 XBT_DEBUG("set the weight of the dummy CPU action on PM to 1");
68 /* FIXME: we shoud use lmm_update_variable_weight() ? */
69 /* FIXME: If we assgign 1.05 and 0.05, the system makes apparently wrong values. */
70 ws_vm->p_action->setPriority(1);
73 /* no task exits on this VM */
74 XBT_DEBUG("set the weight of the dummy CPU action on PM to 0");
76 ws_vm->p_action->setPriority(0);
84 Workstation::Workstation(xbt_dynar_t storage, RoutingEdgePtr netElm, CpuPtr cpu)
85 : p_storage(storage), p_netElm(netElm), p_cpu(cpu)
88 int Workstation::getCore(){
89 return p_cpu->getCore();
92 double Workstation::getSpeed(double load){
93 return p_cpu->getSpeed(load);
96 double Workstation::getAvailableSpeed(){
97 return p_cpu->getAvailableSpeed();
100 double Workstation::getCurrentPowerPeak()
102 return p_cpu->getCurrentPowerPeak();
105 double Workstation::getPowerPeakAt(int pstate_index)
107 return p_cpu->getPowerPeakAt(pstate_index);
110 int Workstation::getNbPstates()
112 return p_cpu->getNbPstates();
115 void Workstation::setPowerPeakAt(int pstate_index)
117 p_cpu->setPowerPeakAt(pstate_index);
120 double Workstation::getConsumedEnergy()
122 return p_cpu->getConsumedEnergy();
125 xbt_dict_t Workstation::getProperties()
127 return p_cpu->getProperties();
131 StoragePtr Workstation::findStorageOnMountList(const char* mount)
133 StoragePtr st = NULL;
137 XBT_DEBUG("Search for storage name '%s' on '%s'", mount, getName());
138 xbt_dynar_foreach(p_storage,cursor,mnt)
140 XBT_DEBUG("See '%s'",mnt.name);
141 if(!strcmp(mount,mnt.name)){
142 st = dynamic_cast<StoragePtr>(static_cast<ResourcePtr>(mnt.storage));
146 if(!st) xbt_die("Can't find mount '%s' for '%s'", mount, getName());
150 xbt_dict_t Workstation::getStorageList()
154 xbt_dict_t storage_list = xbt_dict_new_homogeneous(NULL);
155 char *storage_name = NULL;
157 xbt_dynar_foreach(p_storage,i,mnt){
158 storage_name = (char *)dynamic_cast<StoragePtr>(static_cast<ResourcePtr>(mnt.storage))->getName();
159 xbt_dict_set(storage_list,mnt.name,storage_name,NULL);
164 ActionPtr Workstation::open(const char* mount, const char* path) {
165 StoragePtr st = findStorageOnMountList(mount);
166 XBT_DEBUG("OPEN on disk '%s'", st->getName());
167 return st->open(mount, path);
170 ActionPtr Workstation::close(surf_file_t fd) {
171 StoragePtr st = findStorageOnMountList(fd->mount);
172 XBT_DEBUG("CLOSE on disk '%s'",st->getName());
173 return st->close(fd);
176 ActionPtr Workstation::read(surf_file_t fd, sg_size_t size) {
177 StoragePtr st = findStorageOnMountList(fd->mount);
178 XBT_DEBUG("READ on disk '%s'",st->getName());
179 return st->read(fd, size);
182 ActionPtr Workstation::write(surf_file_t fd, sg_size_t size) {
183 StoragePtr st = findStorageOnMountList(fd->mount);
184 XBT_DEBUG("WRITE on disk '%s'",st->getName());
185 return st->write(fd, size);
188 int Workstation::unlink(surf_file_t fd) {
190 XBT_WARN("No such file descriptor. Impossible to unlink");
193 // XBT_INFO("%s %zu", fd->storage, fd->size);
194 StoragePtr st = findStorageOnMountList(fd->mount);
195 /* Check if the file is on this storage */
196 if (!xbt_dict_get_or_null(st->p_content, fd->name)){
197 XBT_WARN("File %s is not on disk %s. Impossible to unlink", fd->name,
201 XBT_DEBUG("UNLINK on disk '%s'",st->getName());
202 st->m_usedSize -= fd->size;
204 // Remove the file from storage
205 xbt_dict_remove(st->p_content, fd->name);
215 ActionPtr Workstation::ls(const char* mount, const char *path){
216 XBT_DEBUG("LS on mount '%s' and file '%s'", mount, path);
217 StoragePtr st = findStorageOnMountList(mount);
221 sg_size_t Workstation::getSize(surf_file_t fd){
225 xbt_dynar_t Workstation::getInfo( surf_file_t fd)
227 StoragePtr st = findStorageOnMountList(fd->mount);
228 sg_size_t *psize = xbt_new(sg_size_t, 1);
230 xbt_dynar_t info = xbt_dynar_new(sizeof(void*), NULL);
231 xbt_dynar_push_as(info, sg_size_t *, psize);
232 xbt_dynar_push_as(info, void *, fd->mount);
233 xbt_dynar_push_as(info, void *, (void *)st->getName());
234 xbt_dynar_push_as(info, void *, st->p_typeId);
235 xbt_dynar_push_as(info, void *, st->p_contentType);
240 sg_size_t Workstation::fileTell(surf_file_t fd){
241 return fd->current_position;
244 int Workstation::fileSeek(surf_file_t fd, sg_size_t offset, int origin){
248 fd->current_position = 0;
251 if(offset > fd->size)
253 fd->current_position = offset;
256 fd->current_position = fd->size;
259 return MSG_TASK_CANCELED;
263 sg_size_t Workstation::getFreeSize(const char* name)
265 StoragePtr st = findStorageOnMountList(name);
266 return st->m_size - st->m_usedSize;
269 sg_size_t Workstation::getUsedSize(const char* name)
271 StoragePtr st = findStorageOnMountList(name);
272 return st->m_usedSize;
275 xbt_dynar_t Workstation::getVms()
277 xbt_dynar_t dyn = xbt_dynar_new(sizeof(smx_host_t), NULL);
279 /* iterate for all hosts including virtual machines */
280 xbt_lib_cursor_t cursor;
283 xbt_lib_foreach(host_lib, cursor, key, ind_host) {
284 WorkstationPtr ws = dynamic_cast<WorkstationPtr>(static_cast<ResourcePtr>(ind_host[SURF_WKS_LEVEL]));
287 /* skip if it is not a virtual machine */
288 if (ws->getModel() != static_cast<ModelPtr>(surf_vm_workstation_model))
291 /* It is a virtual machine, so we can cast it to workstation_VM2013_t */
292 WorkstationVMPtr ws_vm = dynamic_cast<WorkstationVMPtr>(ws);
293 if (this == ws_vm-> p_subWs)
294 xbt_dynar_push(dyn, &ws_vm->p_subWs);
300 void Workstation::getParams(ws_params_t params)
302 memcpy(params, &p_params, sizeof(s_ws_params_t));
305 void Workstation::setParams(ws_params_t params)
307 /* may check something here. */
308 memcpy(&p_params, params, sizeof(s_ws_params_t));