ActionPtr NetworkCm02Model::communicate(RoutingEdgePtr src, RoutingEdgePtr dst, double size, double rate) { unsigned int i; void *_link; NetworkCm02LinkPtr link; int failed = 0; NetworkCm02ActionPtr action = NULL; double bandwidth_bound; double latency = 0.0; xbt_dynar_t back_route = NULL; int constraints_per_variable = 0; xbt_dynar_t route = xbt_dynar_new(sizeof(RoutingEdgePtr), NULL); XBT_IN("(%s,%s,%g,%g)", src->getName(), dst->getName(), size, rate); routing_platf->getRouteAndLatency(src, dst, &route, &latency); xbt_assert(!xbt_dynar_is_empty(route) || latency, "You're trying to send data from %s to %s but there is no connection at all between these two hosts.", src->getName(), dst->getName()); xbt_dynar_foreach(route, i, _link) { link = static_cast<NetworkCm02LinkPtr>(_link); if (link->getState() == SURF_RESOURCE_OFF) { failed = 1; break; } }
CpuAction *CpuCas01::sleep(double duration) { if (duration > 0) duration = MAX(duration, sg_surf_precision); XBT_IN("(%s,%g)", getName(), duration); CpuCas01Action *action = new CpuCas01Action(getModel(), 1.0, isOff(), speed_.scale * speed_.peak, getConstraint()); // FIXME: sleep variables should not consume 1.0 in lmm_expand action->maxDuration_ = duration; action->suspended_ = 2; if (duration == NO_MAX_DURATION) { /* Move to the *end* of the corresponding action set. This convention is used to speed up update_resource_state */ action->getStateSet()->erase(action->getStateSet()->iterator_to(*action)); action->stateSet_ = static_cast<CpuCas01Model*>(getModel())->p_cpuRunningActionSetThatDoesNotNeedBeingChecked; action->getStateSet()->push_back(*action); } lmm_update_variable_weight(getModel()->getMaxminSystem(), action->getVariable(), 0.0); if (getModel()->getUpdateMechanism() == UM_LAZY) { // remove action from the heap action->heapRemove(getModel()->getActionHeap()); // this is necessary for a variable with weight 0 since such variables are ignored in lmm and we need to set its // max_duration correctly at the next call to share_resources getModel()->getModifiedSet()->push_front(*action); } XBT_OUT(); return action; }
void surf_action_set_category(surf_action_t action, const char *category) { XBT_IN("(%p,%s)", action, category); action->category = xbt_strdup(category); XBT_OUT(); }
void SIMIX_synchro_finish(smx_activity_t synchro) { XBT_IN("(%p)",synchro); smx_simcall_t simcall = synchro->simcalls.front(); synchro->simcalls.pop_front(); switch (synchro->state) { case SIMIX_SRC_TIMEOUT: SMX_EXCEPTION(simcall->issuer, timeout_error, 0, "Synchro's wait timeout"); break; case SIMIX_FAILED: simcall->issuer->context->iwannadie = 1; // SMX_EXCEPTION(simcall->issuer, host_error, 0, "Host failed"); break; default: THROW_IMPOSSIBLE; break; } SIMIX_synchro_stop_waiting(simcall->issuer, simcall); simcall->issuer->waiting_synchro = nullptr; delete synchro; SIMIX_simcall_answer(simcall); XBT_OUT(); }
/** Unlock a mutex for a process * * Unlocks the mutex and gives it to a process waiting for it. * If the unlocker is not the owner of the mutex nothing happens. * If there are no process waiting, it sets the mutex as free. */ void Mutex::unlock(smx_actor_t issuer) { XBT_IN("(%p, %p)", this, issuer); if(!this->locked) THROWF(mismatch_error, 0, "Cannot release that mutex: it was not locked."); /* If the mutex is not owned by the issuer, that's not good */ if (issuer != this->owner) THROWF(mismatch_error, 0, "Cannot release that mutex: it was locked by %s (pid:%ld), not by you.", this->owner->name.c_str(),this->owner->pid); if (xbt_swag_size(this->sleeping) > 0) { /*process to wake up */ smx_actor_t p = (smx_actor_t) xbt_swag_extract(this->sleeping); delete p->waiting_synchro; p->waiting_synchro = nullptr; this->owner = p; SIMIX_simcall_answer(&p->simcall); } else { /* nobody to wake up */ this->locked = false; this->owner = nullptr; } XBT_OUT(); }
/** * \brief Signalizes a condition. * * Signalizes a condition and wakes up a sleeping process. * If there are no process sleeping, no action is done. * \param cond A condition */ void SIMIX_cond_signal(smx_cond_t cond) { XBT_IN("(%p)",cond); smx_actor_t proc = nullptr; smx_mutex_t mutex = nullptr; smx_simcall_t simcall = nullptr; XBT_DEBUG("Signal condition %p", cond); /* If there are processes waiting for the condition choose one and try to make it acquire the mutex */ if ((proc = (smx_actor_t) xbt_swag_extract(cond->sleeping))) { /* Destroy waiter's synchronization */ delete proc->waiting_synchro; proc->waiting_synchro = nullptr; /* Now transform the cond wait simcall into a mutex lock one */ simcall = &proc->simcall; if(simcall->call == SIMCALL_COND_WAIT) mutex = simcall_cond_wait__get__mutex(simcall); else mutex = simcall_cond_wait_timeout__get__mutex(simcall); simcall->call = SIMCALL_MUTEX_LOCK; simcall_HANDLER_mutex_lock(simcall, mutex); } XBT_OUT(); }
/** * \brief Signalizes a condition. * * Signalizes a condition and wakes up a sleeping process. * If there are no process sleeping, no action is done. * \param cond A condition */ void SIMIX_cond_signal(smx_cond_t cond) { XBT_IN("(%p)",cond); smx_process_t proc = NULL; smx_mutex_t mutex = NULL; smx_simcall_t simcall = NULL; XBT_DEBUG("Signal condition %p", cond); /* If there are processes waiting for the condition choose one and try to make it acquire the mutex */ if ((proc = xbt_swag_extract(cond->sleeping))) { /* Destroy waiter's synchro action */ SIMIX_synchro_destroy(proc->waiting_action); proc->waiting_action = NULL; /* Now transform the cond wait simcall into a mutex lock one */ simcall = &proc->simcall; if(simcall->call == SIMCALL_COND_WAIT) mutex = simcall_cond_wait__get__mutex(simcall); else mutex = simcall_cond_wait_timeout__get__mutex(simcall); simcall->call = SIMCALL_MUTEX_LOCK; SIMIX_pre_mutex_lock(simcall, mutex); } XBT_OUT(); }
void SIMIX_synchro_stop_waiting(smx_process_t process, smx_simcall_t simcall) { XBT_IN("(%p, %p)",process,simcall); switch (simcall->call) { case SIMCALL_MUTEX_LOCK: xbt_swag_remove(process, simcall_mutex_lock__get__mutex(simcall)->sleeping); break; case SIMCALL_COND_WAIT: xbt_swag_remove(process, simcall_cond_wait__get__cond(simcall)->sleeping); break; case SIMCALL_COND_WAIT_TIMEOUT: xbt_swag_remove(process, simcall_cond_wait_timeout__get__cond(simcall)->sleeping); break; case SIMCALL_SEM_ACQUIRE: xbt_swag_remove(process, simcall_sem_acquire__get__sem(simcall)->sleeping); break; case SIMCALL_SEM_ACQUIRE_TIMEOUT: xbt_swag_remove(process, simcall_sem_acquire_timeout__get__sem(simcall)->sleeping); break; default: THROW_IMPOSSIBLE; } XBT_OUT(); }
static void SIMIX_synchro_finish(smx_action_t action) { XBT_IN("(%p)",action); smx_simcall_t simcall = xbt_fifo_shift(action->simcalls); switch (action->state) { case SIMIX_SRC_TIMEOUT: SMX_EXCEPTION(simcall->issuer, timeout_error, 0, "Synchro's wait timeout"); break; case SIMIX_FAILED: simcall->issuer->context->iwannadie = 1; // SMX_EXCEPTION(simcall->issuer, host_error, 0, "Host failed"); break; default: THROW_IMPOSSIBLE; break; } SIMIX_synchro_stop_waiting(simcall->issuer, simcall); simcall->issuer->waiting_action = NULL; SIMIX_synchro_destroy(action); SIMIX_simcall_answer(simcall); XBT_OUT(); }
static XBT_INLINE void lmm_variable_disable(lmm_system_t sys, lmm_variable_t var) { int i; int n; lmm_element_t elem = NULL; XBT_IN("(sys=%p, var=%p)", sys, var); sys->modified = 1; n = 0; for (i = 0; i < var->cnsts_number; i++) { elem = &var->cnsts[i]; xbt_swag_remove(elem, &(elem->constraint->element_set)); xbt_swag_remove(elem, &(elem->constraint->active_element_set)); if (!xbt_swag_size(&(elem->constraint->element_set))) make_constraint_inactive(sys, elem->constraint); else { if (n < i) var->cnsts[n].constraint = elem->constraint; n++; } } if (n) { var->cnsts_number = n; lmm_update_modified_set(sys, var->cnsts[0].constraint); } var->cnsts_number = 0; XBT_OUT(); }
StorageN11Action::StorageN11Action(Model *model, double cost, bool failed, Storage *storage, e_surf_action_storage_type_t type) : StorageAction(model, cost, failed, lmm_variable_new(model->getMaxminSystem(), this, 1.0, -1.0 , 3), storage, type) { XBT_IN("(%s,%g", storage->getName(), cost); // Must be less than the max bandwidth for all actions lmm_expand(model->getMaxminSystem(), storage->getConstraint(), getVariable(), 1.0); switch(type) { case OPEN: case CLOSE: case STAT: break; case READ: lmm_expand(model->getMaxminSystem(), storage->constraintRead_, getVariable(), 1.0); break; case WRITE: 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; // storage->p_writeActions->push_back(action); // ref(); break; } XBT_OUT(); }
/** * \brief Handle a condition waiting simcall without timeouts * \param simcall the simcall */ void simcall_HANDLER_cond_wait(smx_simcall_t simcall, smx_cond_t cond, smx_mutex_t mutex) { XBT_IN("(%p)",simcall); smx_actor_t issuer = simcall->issuer; _SIMIX_cond_wait(cond, mutex, -1, issuer, simcall); XBT_OUT(); }
Mutex::Mutex() : mutex_(this) { XBT_IN("(%p)", this); // Useful to initialize sleeping swag: simgrid::simix::ActorImpl p; this->sleeping = xbt_swag_new(xbt_swag_offset(p, synchro_hookup)); XBT_OUT(); }
CpuAction *CpuCas01::execution_start(double size) { XBT_IN("(%s,%g)", getName(), size); CpuCas01Action *action = new CpuCas01Action(getModel(), size, isOff(), speed_.scale * speed_.peak, getConstraint()); XBT_OUT(); return action; }
/** * \brief Handle a condition waiting simcall without timeouts * \param simcall the simcall */ void SIMIX_pre_cond_wait(smx_simcall_t simcall, smx_cond_t cond, smx_mutex_t mutex) { XBT_IN("(%p)",simcall); smx_process_t issuer = simcall->issuer; _SIMIX_cond_wait(cond, mutex, -1, issuer, simcall); XBT_OUT(); }
void surf_action_set_max_duration(surf_action_t action, double duration) { surf_model_t model = action->model_type; XBT_IN("(%p,%g)", action, duration); action->max_duration = duration; if (model->model_private->update_mechanism == UM_LAZY) // remove action from the heap surf_action_lmm_heap_remove(model->model_private->action_heap,(surf_action_lmm_t)action); XBT_OUT(); }
void StorageN11Action::suspend() { XBT_IN("(%p)", this); if (suspended_ != 2) { lmm_update_variable_weight(getModel()->getMaxminSystem(), getVariable(), 0.0); suspended_ = 1; } XBT_OUT(); }
/** * \brief Handle a condition waiting simcall with timeouts * \param simcall the simcall */ void simcall_HANDLER_cond_wait_timeout(smx_simcall_t simcall, smx_cond_t cond, smx_mutex_t mutex, double timeout) { XBT_IN("(%p)",simcall); smx_process_t issuer = simcall->issuer; _SIMIX_cond_wait(cond, mutex, timeout, issuer, simcall); XBT_OUT(); }
void SIMIX_cond_unref(smx_cond_t cond) { XBT_IN("(%p)",cond); XBT_DEBUG("Destroy condition %p", cond); if (cond != nullptr) { intrusive_ptr_release(cond); } XBT_OUT(); }
void SIMIX_synchro_destroy(smx_action_t action) { XBT_IN("(%p)",action); XBT_DEBUG("Destroying synchro %p", action); action->synchro.sleep->model_type->action_unref(action->synchro.sleep); xbt_free(action->name); xbt_mallocator_release(simix_global->action_mallocator, action); XBT_OUT(); }
/** * \brief Destroys a mutex. * * Destroys and frees the mutex's memory. * \param mutex A mutex */ void SIMIX_mutex_destroy(smx_mutex_t mutex) { XBT_IN("(%p)",mutex); if (mutex){ xbt_swag_free(mutex->sleeping); xbt_free(mutex); } XBT_OUT(); }
double surf_action_get_remains(surf_action_t action) { XBT_IN("(%p)", action); surf_model_t model = action->model_type; /* update remains before return it */ if (model->model_private->update_mechanism == UM_LAZY) /* update remains before return it */ generic_update_action_remaining_lazy((surf_action_lmm_t)action, surf_get_clock()); XBT_OUT(); return action->remains; }
/** * \brief Initialize a condition. * * Allocates and creates the data for the condition. * It have to be called before the use of the condition. * \return A condition */ smx_cond_t SIMIX_cond_init() { XBT_IN("()"); simgrid::simix::ActorImpl p; smx_cond_t cond = new s_smx_cond(); cond->sleeping = xbt_swag_new(xbt_swag_offset(p, synchro_hookup)); cond->refcount_ = 1; XBT_OUT(); return cond; }
static smx_activity_t SIMIX_synchro_wait(sg_host_t smx_host, double timeout) { XBT_IN("(%p, %f)",smx_host,timeout); simgrid::kernel::activity::Raw *sync = new simgrid::kernel::activity::Raw(); sync->sleep = smx_host->pimpl_cpu->sleep(timeout); sync->sleep->setData(sync); XBT_OUT(); return sync; }
void SIMIX_synchro_destroy(smx_synchro_t synchro) { XBT_IN("(%p)",synchro); XBT_DEBUG("Destroying synchro %p", synchro); xbt_assert(synchro->type == SIMIX_SYNC_SYNCHRO); surf_action_unref(synchro->synchro.sleep); xbt_free(synchro->name); xbt_mallocator_release(simix_global->synchro_mallocator, synchro); XBT_OUT(); }
/** * \brief Initialize a condition. * * Allocates and creates the data for the condition. * It have to be called before the use of the condition. * \return A condition */ smx_cond_t SIMIX_cond_init(void) { XBT_IN("()"); s_smx_process_t p; smx_cond_t cond = xbt_new0(s_smx_cond_t, 1); cond->sleeping = xbt_swag_new(xbt_swag_offset(p, synchro_hookup)); cond->mutex = NULL; XBT_OUT(); return cond; }
void SIMIX_post_synchro(smx_action_t action) { XBT_IN("(%p)",action); if (surf_workstation_model->action_state_get(action->synchro.sleep) == SURF_ACTION_FAILED) action->state = SIMIX_FAILED; else if(surf_workstation_model->action_state_get(action->synchro.sleep) == SURF_ACTION_DONE) action->state = SIMIX_SRC_TIMEOUT; SIMIX_synchro_finish(action); XBT_OUT(); }
/** @brief Initialize a semaphore */ smx_sem_t SIMIX_sem_init(unsigned int value) { XBT_IN("(%u)",value); s_smx_process_t p; smx_sem_t sem = xbt_new0(s_smx_sem_t, 1); sem->sleeping = xbt_swag_new(xbt_swag_offset(p, synchro_hookup)); sem->value = value; XBT_OUT(); return sem; }
/** * \brief Broadcasts a condition. * * Signal ALL processes waiting on a condition. * If there are no process waiting, no action is done. * \param cond A condition */ void SIMIX_cond_broadcast(smx_cond_t cond) { XBT_IN("(%p)",cond); XBT_DEBUG("Broadcast condition %p", cond); /* Signal the condition until nobody is waiting on it */ while (xbt_swag_size(cond->sleeping)) { SIMIX_cond_signal(cond); } XBT_OUT(); }
/** * \brief Initialize a mutex. * * Allocs and creates the data for the mutex. * \return A mutex */ smx_mutex_t SIMIX_mutex_init(void) { XBT_IN("()"); s_smx_process_t p; /* useful to initialize sleeping swag */ smx_mutex_t mutex = xbt_new0(s_smx_mutex_t, 1); mutex->locked = 0; mutex->sleeping = xbt_swag_new(xbt_swag_offset(p, synchro_hookup)); XBT_OUT(); return mutex; }