From: suter Date: Fri, 11 Apr 2014 13:24:15 +0000 (+0200) Subject: correct the semantic of the write X-Git-Tag: v3_11~120^2~6 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/a9df68430653de724aa5089095ed6c9e3055a779 correct the semantic of the write --- diff --git a/src/surf/storage_interface.cpp b/src/surf/storage_interface.cpp index d1c824d2fb..bbe461698d 100644 --- a/src/surf/storage_interface.cpp +++ b/src/surf/storage_interface.cpp @@ -167,16 +167,17 @@ sg_size_t Storage::getSize(){ * Action * **********/ StorageAction::StorageAction(ModelPtr model, double cost, bool failed, - StoragePtr storage, e_surf_action_storage_type_t type) + StoragePtr storage, e_surf_action_storage_type_t type) : Action(model, cost, failed) -, m_type(type), p_storage(storage), p_file(NULL), p_lsDict(NULL) -{ +, m_type(type), p_storage(storage), p_file(NULL), p_lsDict(NULL){ + progress = 0; }; StorageAction::StorageAction(ModelPtr model, double cost, bool failed, lmm_variable_t var, - StoragePtr storage, e_surf_action_storage_type_t type) + StoragePtr storage, e_surf_action_storage_type_t type) : Action(model, cost, failed, var) , m_type(type), p_storage(storage), p_file(NULL), p_lsDict(NULL) { + progress = 0; } void StorageAction::setState(e_surf_action_state_t state){ diff --git a/src/surf/storage_interface.hpp b/src/surf/storage_interface.hpp index 357200e7a9..db02f42bd3 100644 --- a/src/surf/storage_interface.hpp +++ b/src/surf/storage_interface.hpp @@ -293,6 +293,7 @@ public: StoragePtr p_storage; surf_file_t p_file; xbt_dict_t p_lsDict; + double progress; }; typedef struct s_storage_type { diff --git a/src/surf/storage_n11.cpp b/src/surf/storage_n11.cpp index 3b191c8b73..bdba8e2cba 100644 --- a/src/surf/storage_n11.cpp +++ b/src/surf/storage_n11.cpp @@ -6,7 +6,7 @@ #include "storage_n11.hpp" #include "surf_private.h" - +#include /*ceil*/ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_storage); static int storage_selective_update = 0; @@ -305,17 +305,34 @@ void StorageN11Model::updateActionsState(double /*now*/, double delta) ; it != itend ; it=itNext) { ++itNext; action = static_cast(&*it); + if(action->m_type == WRITE) { // Update the disk usage - // Update the file size - // For each action of type write - double rate = lmm_variable_getvalue(action->getVariable()); - /* Hack to avoid rounding differences between x86 and x86_64 - * (note that the next sizes are of type sg_size_t). */ - long incr = delta * rate + 0.00001; // Use legacy value. I don't know what this hack can be... FIXME: Pierre, please check. + // Update the file size + // For each action of type write + 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", + 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) + incr++; + + action->progress +=current_progress; + action->p_storage->m_usedSize += incr; // disk usage - action->p_file->size += incr; // file size + 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; @@ -416,7 +433,7 @@ StorageActionPtr StorageN11::open(const char* mount, const char* path) if(psize) size = *psize; else { - psize = xbt_new(sg_size_t,1); + psize = xbt_new(sg_size_t,1); size = 0; *psize = size; xbt_dict_set(p_content, path, psize, NULL); @@ -476,8 +493,10 @@ StorageActionPtr StorageN11::write(surf_file_t fd, sg_size_t size) StorageActionPtr action = new StorageN11Action(getModel(), size, getState() != SURF_RESOURCE_ON, this, WRITE); action->p_file = fd; - fd->current_position += size; - // If the storage is full + /* Substract the part of the file that might disappear from the used sized on + * the storage element */ + m_usedSize -= (fd->size - fd->current_position); + // If the storage is full before even starting to write if(m_usedSize==m_size) { action->setState(SURF_ACTION_FAILED); } @@ -504,11 +523,11 @@ StorageN11Action::StorageN11Action(ModelPtr model, double cost, bool failed, Sto break; case READ: lmm_expand(model->getMaxminSystem(), storage->p_constraintRead, - getVariable(), 1.0); + getVariable(), 1.0); break; case WRITE: lmm_expand(model->getMaxminSystem(), storage->p_constraintWrite, - getVariable(), 1.0); + getVariable(), 1.0); ActionPtr action = this; xbt_dynar_push(storage->p_writeActions, &action); ref();