1 #include "workstation.hpp"
2 #include "simgrid/sg_config.h"
5 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_workstation, surf,
6 "Logging specific to the SURF workstation module");
9 WorkstationModelPtr surf_workstation_model = NULL;
11 //FIXME:Faire hériter ou composer de cup et network
17 static void workstation_new(sg_platf_host_cbarg_t host){
18 surf_workstation_model->createResource(host->id);
25 void surf_workstation_model_init_current_default(void)
27 surf_workstation_model = new WorkstationModel();
28 xbt_cfg_setdefault_boolean(_sg_cfg_set, "network/crosstraffic", "yes");
29 surf_cpu_model_init_Cas01();
30 surf_network_model_init_LegrandVelho();
32 ModelPtr model = static_cast<ModelPtr>(surf_workstation_model);
33 xbt_dynar_push(model_list, &model);
34 sg_platf_host_add_cb(workstation_new);
37 void surf_workstation_model_init_compound()
40 xbt_assert(surf_cpu_model, "No CPU model defined yet!");
41 xbt_assert(surf_network_model, "No network model defined yet!");
42 surf_workstation_model = new WorkstationModel();
44 ModelPtr model = static_cast<ModelPtr>(surf_workstation_model);
45 xbt_dynar_push(model_list, &model);
46 sg_platf_host_add_cb(workstation_new);
49 WorkstationModel::WorkstationModel() : Model("Workstation") {
52 WorkstationModel::~WorkstationModel() {
55 void WorkstationModel::parseInit(sg_platf_host_cbarg_t host){
56 createResource(host->id);
59 WorkstationCLM03Ptr WorkstationModel::createResource(string name){
61 WorkstationCLM03Ptr workstation = new WorkstationCLM03(surf_workstation_model, name.c_str(), NULL,
62 (xbt_dynar_t)xbt_lib_get_or_null(storage_lib, name.c_str(), ROUTING_STORAGE_HOST_LEVEL),
63 (RoutingEdgePtr)xbt_lib_get_or_null(host_lib, name.c_str(), ROUTING_HOST_LEVEL),
64 dynamic_cast<CpuPtr>(static_cast<ResourcePtr>(xbt_lib_get_or_null(host_lib, name.c_str(), SURF_CPU_LEVEL))));
65 XBT_DEBUG("Create workstation %s with %ld mounted disks", name.c_str(), xbt_dynar_length(workstation->p_storage));
66 xbt_lib_set(host_lib, name.c_str(), SURF_WKS_LEVEL, static_cast<ResourcePtr>(workstation));
70 double WorkstationModel::shareResources(double now){
74 void WorkstationModel::updateActionsState(double now, double delta){
78 ActionPtr WorkstationModel::executeParallelTask(int workstation_nb,
79 void **workstation_list,
80 double *computation_amount,
81 double *communication_amount,
83 #define cost_or_zero(array,pos) ((array)?(array)[pos]:0.0)
84 if ((workstation_nb == 1)
85 && (cost_or_zero(communication_amount, 0) == 0.0))
86 return ((WorkstationCLM03Ptr)workstation_list[0])->execute(computation_amount[0]);
87 else if ((workstation_nb == 1)
88 && (cost_or_zero(computation_amount, 0) == 0.0))
89 return communicate((WorkstationCLM03Ptr)workstation_list[0], (WorkstationCLM03Ptr)workstation_list[0],communication_amount[0], rate);
90 else if ((workstation_nb == 2)
91 && (cost_or_zero(computation_amount, 0) == 0.0)
92 && (cost_or_zero(computation_amount, 1) == 0.0)) {
96 for (i = 0; i < workstation_nb * workstation_nb; i++) {
97 if (cost_or_zero(communication_amount, i) > 0.0) {
99 value = cost_or_zero(communication_amount, i);
103 return communicate((WorkstationCLM03Ptr)workstation_list[0], (WorkstationCLM03Ptr)workstation_list[1],value, rate);
107 THROW_UNIMPLEMENTED; /* This model does not implement parallel tasks */
111 /* returns an array of network_link_CM02_t */
112 xbt_dynar_t WorkstationModel::getRoute(WorkstationCLM03Ptr src, WorkstationCLM03Ptr dst)
114 XBT_DEBUG("ws_get_route");
115 return surf_network_model->getRoute(src->p_netElm, dst->p_netElm);
118 ActionPtr WorkstationModel::communicate(WorkstationCLM03Ptr src, WorkstationCLM03Ptr dst, double size, double rate){
119 return surf_network_model->communicate(src->p_netElm, dst->p_netElm, size, rate);
127 WorkstationCLM03::WorkstationCLM03(WorkstationModelPtr model, const char* name, xbt_dict_t properties, xbt_dynar_t storage, RoutingEdgePtr netElm, CpuPtr cpu)
128 : Resource(model, name, properties), p_storage(storage), p_netElm(netElm), p_cpu(cpu) {}
130 bool WorkstationCLM03::isUsed(){
131 THROW_IMPOSSIBLE; /* This model does not implement parallel tasks */
135 void WorkstationCLM03::updateState(tmgr_trace_event_t event_type, double value, double date){
136 THROW_IMPOSSIBLE; /* This model does not implement parallel tasks */
139 ActionPtr WorkstationCLM03::execute(double size) {
140 return p_cpu->execute(size);
143 ActionPtr WorkstationCLM03::sleep(double duration) {
144 return p_cpu->sleep(duration);
147 e_surf_resource_state_t WorkstationCLM03::getState() {
148 return p_cpu->getState();
151 int WorkstationCLM03::getCore(){
152 return p_cpu->getCore();
155 double WorkstationCLM03::getSpeed(double load){
156 return p_cpu->getSpeed(load);
159 double WorkstationCLM03::getAvailableSpeed(){
160 return p_cpu->getAvailableSpeed();
163 double WorkstationCLM03::getCurrentPowerPeak()
165 return p_cpu->getCurrentPowerPeak();
168 double WorkstationCLM03::getPowerPeakAt(int pstate_index)
170 return p_cpu->getPowerPeakAt(pstate_index);
173 int WorkstationCLM03::getNbPstates()
175 return p_cpu->getNbPstates();
178 void WorkstationCLM03::setPowerPeakAt(int pstate_index)
180 p_cpu->setPowerPeakAt(pstate_index);
183 double WorkstationCLM03::getConsumedEnergy()
185 return p_cpu->getConsumedEnergy();
189 xbt_dict_t WorkstationCLM03::getProperties()
191 return p_cpu->m_properties;
195 StoragePtr WorkstationCLM03::findStorageOnMountList(const char* mount)
197 StoragePtr st = NULL;
201 XBT_DEBUG("Search for storage name '%s' on '%s'", mount, m_name);
202 xbt_dynar_foreach(p_storage,cursor,mnt)
204 XBT_DEBUG("See '%s'",mnt.name);
205 if(!strcmp(mount,mnt.name)){
206 st = dynamic_cast<StoragePtr>(static_cast<ResourcePtr>(mnt.storage));
210 if(!st) xbt_die("Can't find mount '%s' for '%s'", mount, m_name);
214 xbt_dict_t WorkstationCLM03::getStorageList()
218 xbt_dict_t storage_list = xbt_dict_new_homogeneous(NULL);
219 char *storage_name = NULL;
221 xbt_dynar_foreach(p_storage,i,mnt){
222 storage_name = (char *)dynamic_cast<StoragePtr>(static_cast<ResourcePtr>(mnt.storage))->m_name;
223 xbt_dict_set(storage_list,mnt.name,storage_name,NULL);
228 ActionPtr WorkstationCLM03::open(const char* mount, const char* path) {
229 StoragePtr st = findStorageOnMountList(mount);
230 XBT_DEBUG("OPEN on disk '%s'", st->m_name);
231 return st->open(mount, path);
234 ActionPtr WorkstationCLM03::close(surf_file_t fd) {
235 StoragePtr st = findStorageOnMountList(fd->mount);
236 XBT_DEBUG("CLOSE on disk '%s'",st->m_name);
237 return st->close(fd);
240 ActionPtr WorkstationCLM03::read(surf_file_t fd, sg_storage_size_t size) {
241 StoragePtr st = findStorageOnMountList(fd->mount);
242 XBT_DEBUG("READ on disk '%s'",st->m_name);
243 return st->read(fd, size);
246 ActionPtr WorkstationCLM03::write(surf_file_t fd, sg_storage_size_t size) {
247 StoragePtr st = findStorageOnMountList(fd->mount);
248 XBT_DEBUG("WRITE on disk '%s'",st->m_name);
249 return st->write(fd, size);
252 int WorkstationCLM03::unlink(surf_file_t fd) {
254 XBT_WARN("No such file descriptor. Impossible to unlink");
257 // XBT_INFO("%s %zu", fd->storage, fd->size);
258 StoragePtr st = findStorageOnMountList(fd->mount);
259 /* Check if the file is on this storage */
260 if (!xbt_dict_get_or_null(st->p_content, fd->name)){
261 XBT_WARN("File %s is not on disk %s. Impossible to unlink", fd->name,
265 XBT_DEBUG("UNLINK on disk '%s'",st->m_name);
266 st->m_usedSize -= fd->size;
268 // Remove the file from storage
269 xbt_dict_remove(st->p_content, fd->name);
279 ActionPtr WorkstationCLM03::ls(const char* mount, const char *path){
280 XBT_DEBUG("LS on mount '%s' and file '%s'", mount, path);
281 StoragePtr st = findStorageOnMountList(mount);
285 sg_storage_size_t WorkstationCLM03::getSize(surf_file_t fd){
289 xbt_dynar_t WorkstationCLM03::getInfo( surf_file_t fd)
291 StoragePtr st = findStorageOnMountList(fd->mount);
292 sg_storage_size_t *psize = xbt_new(sg_storage_size_t, 1);
294 xbt_dynar_t info = xbt_dynar_new(sizeof(void*), NULL);
295 xbt_dynar_push_as(info, sg_storage_size_t *, psize);
296 xbt_dynar_push_as(info, void *, fd->mount);
297 xbt_dynar_push_as(info, void *, (void *)st->m_name);
298 xbt_dynar_push_as(info, void *, st->p_typeId);
299 xbt_dynar_push_as(info, void *, st->p_contentType);
304 sg_storage_size_t WorkstationCLM03::getFreeSize(const char* name)
306 StoragePtr st = findStorageOnMountList(name);
307 return st->m_size - st->m_usedSize;
310 sg_storage_size_t WorkstationCLM03::getUsedSize(const char* name)
312 StoragePtr st = findStorageOnMountList(name);
313 return st->m_usedSize;
316 e_surf_resource_state_t WorkstationCLM03Lmm::getState() {
317 return WorkstationCLM03::getState();