X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/f9df6a0ce7023e4e22d83bb6c50f27bd21fab329..bfdba6424c0645e31cc60ee166e388cf8f283c3b:/src/surf/storage_n11.cpp diff --git a/src/surf/storage_n11.cpp b/src/surf/storage_n11.cpp index 39a791712d..8161a1b1a7 100644 --- a/src/surf/storage_n11.cpp +++ b/src/surf/storage_n11.cpp @@ -9,9 +9,6 @@ #include /*ceil*/ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_storage); -static int storage_selective_update = 0; -static xbt_swag_t storage_running_action_set_that_does_not_need_being_checked = nullptr; - /************* * CallBacks * *************/ @@ -57,38 +54,27 @@ void storage_register_callbacks() void surf_storage_model_init_default() { surf_storage_model = new simgrid::surf::StorageN11Model(); - xbt_dynar_push(all_existing_models, &surf_storage_model); + all_existing_models->push_back(surf_storage_model); } namespace simgrid { namespace surf { StorageN11Model::StorageN11Model() : StorageModel() { - Action *action = nullptr; - XBT_DEBUG("surf_storage_model_init_internal"); - - storage_running_action_set_that_does_not_need_being_checked = - xbt_swag_new(xbt_swag_offset(*action, stateHookup_)); - if (!maxminSystem_) { - maxminSystem_ = lmm_system_new(storage_selective_update); - } + maxminSystem_ = lmm_system_new(false /*lazy?*/); } StorageN11Model::~StorageN11Model(){ - xbt_swag_free(storage_running_action_set_that_does_not_need_being_checked); - storage_running_action_set_that_does_not_need_being_checked = nullptr; } #include "src/surf/xml/platf.hpp" // FIXME: move that back to the parsing area Storage *StorageN11Model::createStorage(const char* id, const char* type_id, - const char* content_name, const char* content_type, xbt_dict_t properties, - const char* attach) + const char* content_name, const char* content_type, xbt_dict_t properties, const char* attach) { xbt_assert(!surf_storage_resource_priv(surf_storage_resource_by_name(id)), - "Storage '%s' declared several times in the platform file", - id); + "Storage '%s' declared several times in the platform file", id); storage_type_t storage_type = (storage_type_t) xbt_lib_get_or_null(storage_type_lib, type_id,ROUTING_STORAGE_TYPE_LEVEL); @@ -106,42 +92,25 @@ Storage *StorageN11Model::createStorage(const char* id, const char* type_id, xbt_lib_set(storage_lib, id, SURF_STORAGE_LEVEL, storage); XBT_DEBUG("SURF storage create resource\n\t\tid '%s'\n\t\ttype '%s'\n\t\tproperties '%p'\n\t\tBread '%f'\n", - id, - type_id, - properties, - Bread); + id, type_id, properties, Bread); - if(!p_storageList) - p_storageList = xbt_dynar_new(sizeof(char *),nullptr); - xbt_dynar_push(p_storageList, &storage); + p_storageList.push_back(storage); return storage; } -double StorageN11Model::next_occuring_event(double /*now*/) +double StorageN11Model::nextOccuringEvent(double now) { - XBT_DEBUG("storage_share_resources"); - unsigned int i, j; - Storage *storage; - void *_write_action; - StorageAction *write_action; - - double min_completion = shareResourcesMaxMin(getRunningActionSet(), - maxminSystem_, lmm_solve); - - double rate; - // Foreach disk - xbt_dynar_foreach(p_storageList,i,storage) - { - rate = 0; - // Foreach write action on disk - xbt_dynar_foreach(storage->p_writeActions, j, _write_action) - { - write_action = static_cast(_write_action); + double min_completion = StorageModel::nextOccuringEventFull(now); + + for(auto storage: p_storageList) { + double rate = 0; + // Foreach write action on that disk + for (auto write_action: storage->writeActions_) { rate += lmm_variable_getvalue(write_action->getVariable()); } if(rate > 0) - min_completion = MIN(min_completion, (storage->m_size-storage->m_usedSize)/rate); + min_completion = MIN(min_completion, (storage->size_-storage->usedSize_)/rate); } return min_completion; @@ -149,72 +118,59 @@ double StorageN11Model::next_occuring_event(double /*now*/) void StorageN11Model::updateActionsState(double /*now*/, double delta) { - StorageAction *action = nullptr; ActionList *actionSet = getRunningActionSet(); for(ActionList::iterator it(actionSet->begin()), itNext=it, itend(actionSet->end()) ; it != itend ; it=itNext) { ++itNext; - action = static_cast(&*it); - if(action->m_type == WRITE) - { + StorageAction *action = static_cast(&*it); + + if(action->m_type == WRITE){ // Update the disk usage // Update the file size // For each action of type write - double current_progress = - delta * lmm_variable_getvalue(action->getVariable()); + double current_progress = delta * lmm_variable_getvalue(action->getVariable()); long int incr = current_progress; - XBT_DEBUG("%s:\n\t progress = %.2f, current_progress = %.2f, " - "incr = %ld, lrint(1) = %ld, lrint(2) = %ld", + XBT_DEBUG("%s:\n\t progress = %.2f, current_progress = %.2f, incr = %ld, lrint(1) = %ld, lrint(2) = %ld", action->p_file->name, action->progress, current_progress, incr, lrint(action->progress + current_progress), lrint(action->progress)+ incr); /* take care of rounding error accumulation */ - if (lrint(action->progress + current_progress) > - lrint(action->progress)+ incr) + if (lrint(action->progress + current_progress) > lrint(action->progress)+ incr) incr++; action->progress +=current_progress; - action->p_storage->m_usedSize += incr; // disk usage + action->p_storage->usedSize_ += incr; // disk usage action->p_file->current_position+= incr; // current_position // which becomes the new file size action->p_file->size = action->p_file->current_position ; sg_size_t *psize = xbt_new(sg_size_t,1); *psize = action->p_file->size; - xbt_dict_t content_dict = action->p_storage->p_content; + xbt_dict_t content_dict = action->p_storage->content_; xbt_dict_set(content_dict, action->p_file->name, psize, nullptr); } action->updateRemains(lmm_variable_getvalue(action->getVariable()) * delta); - if (action->getMaxDuration() != NO_MAX_DURATION) + if (action->getMaxDuration() > NO_MAX_DURATION) action->updateMaxDuration(delta); - if(action->getRemainsNoUpdate() > 0 && - lmm_get_variable_weight(action->getVariable()) > 0 && - action->p_storage->m_usedSize == action->p_storage->m_size) - { + if(action->getRemainsNoUpdate() > 0 && lmm_get_variable_weight(action->getVariable()) > 0 && + action->p_storage->usedSize_ == action->p_storage->size_) { action->finish(); action->setState(Action::State::failed); - } else if ((action->getRemainsNoUpdate() <= 0) && - (lmm_get_variable_weight(action->getVariable()) > 0)) - { - action->finish(); - action->setState(Action::State::done); - } else if ((action->getMaxDuration() != NO_MAX_DURATION) && - (action->getMaxDuration() <= 0)) - { + } else if (((action->getRemainsNoUpdate() <= 0) && (lmm_get_variable_weight(action->getVariable()) > 0)) || + ((action->getMaxDuration() > NO_MAX_DURATION) && (action->getMaxDuration() <= 0))) { action->finish(); action->setState(Action::State::done); } } - return; } /************ @@ -235,7 +191,7 @@ StorageAction *StorageN11::open(const char* mount, const char* path) XBT_DEBUG("\tOpen file '%s'",path); sg_size_t size, *psize; - psize = (sg_size_t*) xbt_dict_get_or_null(p_content, path); + psize = (sg_size_t*) xbt_dict_get_or_null(content_, path); // if file does not exist create an empty file if(psize) size = *psize; @@ -243,7 +199,7 @@ StorageAction *StorageN11::open(const char* mount, const char* path) psize = xbt_new(sg_size_t,1); size = 0; *psize = size; - xbt_dict_set(p_content, path, psize, nullptr); + xbt_dict_set(content_, path, psize, nullptr); XBT_DEBUG("File '%s' was not found, file created.",path); } surf_file_t file = xbt_new0(s_surf_file_t,1); @@ -260,17 +216,15 @@ StorageAction *StorageN11::open(const char* mount, const char* path) StorageAction *StorageN11::close(surf_file_t fd) { - char *filename = fd->name; - XBT_DEBUG("\tClose file '%s' size '%llu'", filename, fd->size); + XBT_DEBUG("\tClose file '%s' size '%llu'", fd->name, fd->size); // unref write actions from storage - void *_write_action; - StorageAction *write_action; - unsigned int i; - xbt_dynar_foreach(p_writeActions, i, _write_action) { - write_action = static_cast(_write_action); + for (std::vector::iterator it = writeActions_.begin(); it != writeActions_.end();) { + StorageAction *write_action = *it; if ((write_action->p_file) == fd) { - xbt_dynar_cursor_rm(p_writeActions, &i); write_action->unref(); + it = writeActions_.erase(it); + } else { + ++it; } } free(fd->name); @@ -304,11 +258,10 @@ StorageAction *StorageN11::write(surf_file_t fd, sg_size_t size) StorageAction *action = new StorageN11Action(getModel(), size, isOff(), this, WRITE); action->p_file = fd; - /* Substract the part of the file that might disappear from the used sized on - * the storage element */ - m_usedSize -= (fd->size - fd->current_position); + /* Substract the part of the file that might disappear from the used sized on the storage element */ + usedSize_ -= (fd->size - fd->current_position); // If the storage is full before even starting to write - if(m_usedSize==m_size) { + if(usedSize_==size_) { action->setState(Action::State::failed); } return action; @@ -332,16 +285,14 @@ StorageN11Action::StorageN11Action(Model *model, double cost, bool failed, Stora case STAT: break; case READ: - lmm_expand(model->getMaxminSystem(), storage->p_constraintRead, - getVariable(), 1.0); + lmm_expand(model->getMaxminSystem(), storage->constraintRead_, getVariable(), 1.0); break; case WRITE: - lmm_expand(model->getMaxminSystem(), storage->p_constraintWrite, - getVariable(), 1.0); + lmm_expand(model->getMaxminSystem(), storage->constraintWrite_, getVariable(), 1.0); //TODO there is something annoying with what's below. Have to sort it out... // Action *action = this; - // xbt_dynar_push(storage->p_writeActions, &action); + // storage->p_writeActions->push_back(action); // ref(); break; } @@ -366,7 +317,6 @@ int StorageN11Action::unref() void StorageN11Action::cancel() { setState(Action::State::failed); - return; } void StorageN11Action::suspend()