void *surf_action_new(size_t size, double cost, surf_model_t model, int failed) { xbt_assert(size <= action_mallocator_allocated_size, "Cannot create a surf action of size %zu: the mallocator only provides actions of size %d", size, action_mallocator_allocated_size); surf_action_t action = xbt_mallocator_get(action_mallocator); action->refcount = 1; action->cost = cost; action->remains = cost; action->priority = 1.0; action->max_duration = NO_MAX_DURATION; action->start = surf_get_clock(); action->finish = -1.0; action->model_type = model; #ifdef HAVE_TRACING action->category = NULL; #endif if (failed) action->state_set = model->states.failed_action_set; else action->state_set = model->states.running_action_set; xbt_swag_insert(action, action->state_set); return action; }
void bottleneck_solve(lmm_system_t sys) { void *_var, *_var_next, *_cnst, *_cnst_next, *_elem; lmm_variable_t var = nullptr; lmm_constraint_t cnst = nullptr; s_lmm_constraint_t s_cnst; lmm_element_t elem = nullptr; xbt_swag_t cnst_list = nullptr; xbt_swag_t var_list = nullptr; xbt_swag_t elem_list = nullptr; int i; static s_xbt_swag_t cnst_to_update; if (!(sys->modified)) return; /* Init */ xbt_swag_init(&(cnst_to_update), xbt_swag_offset(s_cnst, saturated_constraint_set_hookup)); var_list = &(sys->variable_set); XBT_DEBUG("Variable set : %d", xbt_swag_size(var_list)); xbt_swag_foreach(_var, var_list) { var = (lmm_variable_t)_var; int nb = 0; var->value = 0.0; XBT_DEBUG("Handling variable %p", var); xbt_swag_insert(var, &(sys->saturated_variable_set)); for (i = 0; i < var->cnsts_number; i++) { if (var->cnsts[i].value == 0.0) nb++; } if ((nb == var->cnsts_number) && (var->weight > 0.0)) { XBT_DEBUG("Err, finally, there is no need to take care of variable %p", var); xbt_swag_remove(var, &(sys->saturated_variable_set)); var->value = 1.0; } if (var->weight <= 0.0) { XBT_DEBUG("Err, finally, there is no need to take care of variable %p", var); xbt_swag_remove(var, &(sys->saturated_variable_set)); } }
static void _SIMIX_sem_wait(smx_sem_t sem, double timeout, smx_process_t issuer, smx_simcall_t simcall) { XBT_IN("(%p, %f, %p, %p)",sem,timeout,issuer,simcall); smx_action_t sync_act = NULL; XBT_DEBUG("Wait semaphore %p (timeout:%f)", sem, timeout); if (sem->value <= 0) { sync_act = SIMIX_synchro_wait(issuer->smx_host, timeout); xbt_fifo_unshift(sync_act->simcalls, simcall); issuer->waiting_action = sync_act; xbt_swag_insert(issuer, sem->sleeping); } else { sem->value--; SIMIX_simcall_answer(simcall); } XBT_OUT(); }
static void _SIMIX_sem_wait(smx_sem_t sem, double timeout, smx_actor_t issuer, smx_simcall_t simcall) { XBT_IN("(%p, %f, %p, %p)",sem,timeout,issuer,simcall); smx_activity_t synchro = nullptr; XBT_DEBUG("Wait semaphore %p (timeout:%f)", sem, timeout); if (sem->value <= 0) { synchro = SIMIX_synchro_wait(issuer->host, timeout); synchro->simcalls.push_front(simcall); issuer->waiting_synchro = synchro; xbt_swag_insert(issuer, sem->sleeping); } else { sem->value--; SIMIX_simcall_answer(simcall); } XBT_OUT(); }
static inline void saturated_variable_set_update(s_lmm_constraint_light_t *cnst_light_tab, dyn_light_t saturated_constraint_set, lmm_system_t sys) { /* Add active variables (i.e. variables that need to be set) from the set of constraints to saturate (cnst_light_tab)*/ lmm_constraint_light_t cnst = NULL; void *_elem; lmm_element_t elem = NULL; xbt_swag_t elem_list = NULL; int i; for(i = 0; i< saturated_constraint_set->pos; i++){ cnst = &cnst_light_tab[saturated_constraint_set->data[i]]; elem_list = &(cnst->cnst->active_element_set); xbt_swag_foreach(_elem, elem_list) { elem = (lmm_element_t)_elem; //Visiting active_element_set, so, by construction, should never get a zero weight, correct? xbt_assert(elem->variable->weight > 0); if ((elem->value > 0)) xbt_swag_insert(elem->variable, &(sys->saturated_variable_set)); } }
static XBT_INLINE void saturated_variable_set_update( s_lmm_constraint_light_t *cnst_light_tab, dyn_light_t saturated_constraint_set, lmm_system_t sys) { lmm_constraint_light_t cnst = NULL; lmm_element_t elem = NULL; xbt_swag_t elem_list = NULL; int i; for(i = 0; i< saturated_constraint_set->pos; i++){ cnst = &cnst_light_tab[saturated_constraint_set->data[i]]; elem_list = &(cnst->cnst->active_element_set); xbt_swag_foreach(elem, elem_list) { if (elem->variable->weight <= 0) break; if ((elem->value > 0)) xbt_swag_insert(elem->variable, &(sys->saturated_variable_set)); } } }
static void _SIMIX_cond_wait(smx_cond_t cond, smx_mutex_t mutex, double timeout, smx_process_t issuer, smx_simcall_t simcall) { XBT_IN("(%p, %p, %f, %p,%p)",cond,mutex,timeout,issuer,simcall); smx_action_t sync_act = NULL; XBT_DEBUG("Wait condition %p", cond); /* If there is a mutex unlock it */ /* FIXME: what happens if the issuer is not the owner of the mutex? */ if (mutex != NULL) { cond->mutex = mutex; SIMIX_mutex_unlock(mutex, issuer); } sync_act = SIMIX_synchro_wait(issuer->smx_host, timeout); xbt_fifo_unshift(sync_act->simcalls, simcall); issuer->waiting_action = sync_act; xbt_swag_insert(simcall->issuer, cond->sleeping); XBT_OUT(); }
static void _SIMIX_cond_wait(smx_cond_t cond, smx_mutex_t mutex, double timeout, smx_actor_t issuer, smx_simcall_t simcall) { XBT_IN("(%p, %p, %f, %p,%p)",cond,mutex,timeout,issuer,simcall); smx_activity_t synchro = nullptr; XBT_DEBUG("Wait condition %p", cond); /* If there is a mutex unlock it */ /* FIXME: what happens if the issuer is not the owner of the mutex? */ if (mutex != nullptr) { cond->mutex = mutex; mutex->unlock(issuer); } synchro = SIMIX_synchro_wait(issuer->host, timeout); synchro->simcalls.push_front(simcall); issuer->waiting_synchro = synchro; xbt_swag_insert(simcall->issuer, cond->sleeping); XBT_OUT(); }
void Mutex::lock(smx_actor_t issuer) { XBT_IN("(%p; %p)", this, issuer); /* FIXME: check where to validate the arguments */ smx_activity_t synchro = nullptr; if (this->locked) { /* FIXME: check if the host is active ? */ /* Somebody using the mutex, use a synchronization to get host failures */ synchro = SIMIX_synchro_wait(issuer->host, -1); synchro->simcalls.push_back(&issuer->simcall); issuer->waiting_synchro = synchro; xbt_swag_insert(issuer, this->sleeping); } else { /* mutex free */ this->locked = true; this->owner = issuer; SIMIX_simcall_answer(&issuer->simcall); } XBT_OUT(); }
/** * \brief Handles a mutex lock simcall. * \param simcall the simcall */ void SIMIX_pre_mutex_lock(smx_simcall_t simcall, smx_mutex_t mutex) { XBT_IN("(%p)",simcall); /* FIXME: check where to validate the arguments */ smx_action_t sync_act = NULL; smx_process_t process = simcall->issuer; if (mutex->locked) { /* FIXME: check if the host is active ? */ /* Somebody using the mutex, use a synchro action to get host failures */ sync_act = SIMIX_synchro_wait(process->smx_host, -1); xbt_fifo_push(sync_act->simcalls, simcall); simcall->issuer->waiting_action = sync_act; xbt_swag_insert(simcall->issuer, mutex->sleeping); } else { /* mutex free */ mutex->locked = 1; mutex->owner = simcall->issuer; SIMIX_simcall_answer(simcall); } XBT_OUT(); }
static XBT_INLINE void saturated_variable_set_update( s_lmm_constraint_light_t *cnst_light_tab, dyn_light_t saturated_constraint_set, lmm_system_t sys) { /* Add active variables (i.e. variables that need to be set) from the set of constraints to saturate (cnst_light_tab)*/ lmm_constraint_light_t cnst = NULL; void *_elem; lmm_element_t elem = NULL; xbt_swag_t elem_list = NULL; int i; for(i = 0; i< saturated_constraint_set->pos; i++){ cnst = &cnst_light_tab[saturated_constraint_set->data[i]]; elem_list = &(cnst->cnst->active_element_set); xbt_swag_foreach(_elem, elem_list) { elem = (lmm_element_t)_elem; if (elem->variable->weight <= 0) break; if ((elem->value > 0)) xbt_swag_insert(elem->variable, &(sys->saturated_variable_set)); } }
void surf_action_state_set(surf_action_t action, e_surf_action_state_t state) { surf_action_state_t action_state = &(action->model_type->states); XBT_IN("(%p,%s)", action, surf_action_state_names[state]); xbt_swag_remove(action, action->state_set); if (state == SURF_ACTION_READY) action->state_set = action_state->ready_action_set; else if (state == SURF_ACTION_RUNNING) action->state_set = action_state->running_action_set; else if (state == SURF_ACTION_FAILED) action->state_set = action_state->failed_action_set; else if (state == SURF_ACTION_DONE) action->state_set = action_state->done_action_set; else action->state_set = NULL; if (action->state_set) xbt_swag_insert(action, action->state_set); XBT_OUT(); }
xbt_swag_foreach(_cnst, cnst_list) { cnst = (lmm_constraint_t)_cnst; xbt_swag_insert(cnst, &(sys->saturated_constraint_set)); }