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 = static_cast<WorkstationPtr>(ind_host[SURF_WKS_LEVEL]);
43 CpuCas01Ptr cpu_cas01 = static_cast<CpuCas01Ptr>(ind_host[SURF_CPU_LEVEL]);
47 /* skip if it is not a virtual machine */
48 if (ws->getModel() != static_cast<ModelPtr>(surf_vm_workstation_model))
50 xbt_assert(cpu_cas01, "cpu-less workstation");
52 /* It is a virtual machine, so we can cast it to workstation_VM2013_t */
53 WorkstationVMPtr ws_vm = static_cast<WorkstationVMPtr>(ws);
55 int is_active = lmm_constraint_used(cpu_cas01->getModel()->getMaxminSystem(), cpu_cas01->getConstraint());
56 // int is_active_old = constraint_is_active(cpu_cas01);
59 // xbt_assert(is_active == is_active_old, "%d %d", is_active, is_active_old);
63 /* some tasks exist on this VM */
64 XBT_DEBUG("set the weight of the dummy CPU action on PM to 1");
66 /* FIXME: we shoud use lmm_update_variable_weight() ? */
67 /* FIXME: If we assgign 1.05 and 0.05, the system makes apparently wrong values. */
68 ws_vm->p_action->setPriority(1);
71 /* no task exits on this VM */
72 XBT_DEBUG("set the weight of the dummy CPU action on PM to 0");
74 ws_vm->p_action->setPriority(0);
82 Workstation::Workstation(ModelPtr model, const char *name, xbt_dict_t props,
83 xbt_dynar_t storage, RoutingEdgePtr netElm, CpuPtr cpu)
84 : Resource(model, name, props)
85 , p_storage(storage), p_netElm(netElm), p_cpu(cpu)
88 Workstation::Workstation(ModelPtr model, const char *name, xbt_dict_t props, lmm_constraint_t constraint,
89 xbt_dynar_t storage, RoutingEdgePtr netElm, CpuPtr cpu)
90 : Resource(model, name, props, constraint)
91 , p_storage(storage), p_netElm(netElm), p_cpu(cpu)
94 int Workstation::getCore(){
95 return p_cpu->getCore();
98 double Workstation::getSpeed(double load){
99 return p_cpu->getSpeed(load);
102 double Workstation::getAvailableSpeed(){
103 return p_cpu->getAvailableSpeed();
106 double Workstation::getCurrentPowerPeak()
108 return p_cpu->getCurrentPowerPeak();
111 double Workstation::getPowerPeakAt(int pstate_index)
113 return p_cpu->getPowerPeakAt(pstate_index);
116 int Workstation::getNbPstates()
118 return p_cpu->getNbPstates();
121 void Workstation::setPowerPeakAt(int pstate_index)
123 p_cpu->setPowerPeakAt(pstate_index);
126 xbt_dict_t Workstation::getProperties()
128 return p_cpu->getProperties();
132 StoragePtr Workstation::findStorageOnMountList(const char* mount)
134 StoragePtr st = NULL;
138 XBT_DEBUG("Search for storage name '%s' on '%s'", mount, getName());
139 xbt_dynar_foreach(p_storage,cursor,mnt)
141 XBT_DEBUG("See '%s'",mnt.name);
142 if(!strcmp(mount,mnt.name)){
143 st = static_cast<StoragePtr>(mnt.storage);
147 if(!st) xbt_die("Can't find mount '%s' for '%s'", mount, getName());
151 xbt_dict_t Workstation::getStorageList()
155 xbt_dict_t storage_list = xbt_dict_new_homogeneous(NULL);
156 char *storage_name = NULL;
158 xbt_dynar_foreach(p_storage,i,mnt){
159 storage_name = (char *)static_cast<StoragePtr>(mnt.storage)->getName();
160 xbt_dict_set(storage_list,mnt.name,storage_name,NULL);
165 ActionPtr Workstation::open(const char* mount, const char* path) {
166 StoragePtr st = findStorageOnMountList(mount);
167 XBT_DEBUG("OPEN on disk '%s'", st->getName());
168 return st->open(mount, path);
171 ActionPtr Workstation::close(surf_file_t fd) {
172 StoragePtr st = findStorageOnMountList(fd->mount);
173 XBT_DEBUG("CLOSE on disk '%s'",st->getName());
174 return st->close(fd);
177 ActionPtr Workstation::read(surf_file_t fd, sg_size_t size) {
178 StoragePtr st = findStorageOnMountList(fd->mount);
179 XBT_DEBUG("READ on disk '%s'",st->getName());
180 return st->read(fd, size);
183 ActionPtr Workstation::write(surf_file_t fd, sg_size_t size) {
184 StoragePtr st = findStorageOnMountList(fd->mount);
185 XBT_DEBUG("WRITE on disk '%s'",st->getName());
186 return st->write(fd, size);
189 int Workstation::unlink(surf_file_t fd) {
191 XBT_WARN("No such file descriptor. Impossible to unlink");
194 // XBT_INFO("%s %zu", fd->storage, fd->size);
195 StoragePtr st = findStorageOnMountList(fd->mount);
196 /* Check if the file is on this storage */
197 if (!xbt_dict_get_or_null(st->p_content, fd->name)){
198 XBT_WARN("File %s is not on disk %s. Impossible to unlink", fd->name,
202 XBT_DEBUG("UNLINK on disk '%s'",st->getName());
203 st->m_usedSize -= fd->size;
205 // Remove the file from storage
206 xbt_dict_remove(st->p_content, fd->name);
216 ActionPtr Workstation::ls(const char* mount, const char *path){
217 XBT_DEBUG("LS on mount '%s' and file '%s'", mount, path);
218 StoragePtr st = findStorageOnMountList(mount);
222 sg_size_t Workstation::getSize(surf_file_t fd){
226 xbt_dynar_t Workstation::getInfo( surf_file_t fd)
228 StoragePtr st = findStorageOnMountList(fd->mount);
229 sg_size_t *psize = xbt_new(sg_size_t, 1);
231 xbt_dynar_t info = xbt_dynar_new(sizeof(void*), NULL);
232 xbt_dynar_push_as(info, sg_size_t *, psize);
233 xbt_dynar_push_as(info, void *, fd->mount);
234 xbt_dynar_push_as(info, void *, (void *)st->getName());
235 xbt_dynar_push_as(info, void *, st->p_typeId);
236 xbt_dynar_push_as(info, void *, st->p_contentType);
241 sg_size_t Workstation::fileTell(surf_file_t fd){
242 return fd->current_position;
245 int Workstation::fileSeek(surf_file_t fd, sg_size_t offset, int origin){
249 fd->current_position = 0;
252 if(offset > fd->size)
254 fd->current_position = offset;
257 fd->current_position = fd->size;
260 return MSG_TASK_CANCELED;
264 sg_size_t Workstation::getFreeSize(const char* name)
266 StoragePtr st = findStorageOnMountList(name);
267 return st->m_size - st->m_usedSize;
270 sg_size_t Workstation::getUsedSize(const char* name)
272 StoragePtr st = findStorageOnMountList(name);
273 return st->m_usedSize;
276 xbt_dynar_t Workstation::getVms()
278 xbt_dynar_t dyn = xbt_dynar_new(sizeof(smx_host_t), NULL);
280 /* iterate for all hosts including virtual machines */
281 xbt_lib_cursor_t cursor;
284 xbt_lib_foreach(host_lib, cursor, key, ind_host) {
285 WorkstationPtr ws = static_cast<WorkstationPtr>(ind_host[SURF_WKS_LEVEL]);
288 /* skip if it is not a virtual machine */
289 if (ws->getModel() != static_cast<ModelPtr>(surf_vm_workstation_model))
292 /* It is a virtual machine, so we can cast it to workstation_VM2013_t */
293 WorkstationVMPtr ws_vm = static_cast<WorkstationVMPtr>(ws);
294 if (this == ws_vm-> p_subWs)
295 xbt_dynar_push(dyn, &ws_vm->p_subWs);
301 void Workstation::getParams(ws_params_t params)
303 memcpy(params, &p_params, sizeof(s_ws_params_t));
306 void Workstation::setParams(ws_params_t params)
308 /* may check something here. */
309 memcpy(&p_params, params, sizeof(s_ws_params_t));