コード例 #1
0
ファイル: smx_synchro.c プロジェクト: Shurakai/SimGrid
/**
 * \brief Tries to lock a mutex.
 *
 * Tries to lock a mutex, return 1 if the mutex is unlocked, else 0.
 * This function does not block and wait for the mutex to be unlocked.
 * \param mutex The mutex
 * \param issuer The process that tries to acquire the mutex
 * \return 1 - mutex free, 0 - mutex used
 */
int SIMIX_mutex_trylock(smx_mutex_t mutex, smx_process_t issuer)
{
  XBT_IN("(%p, %p)",mutex,issuer);
  if (mutex->locked){
    XBT_OUT();
    return 0;
  }

  mutex->locked = 1;
  mutex->owner = issuer;
  XBT_OUT();
  return 1;
}
コード例 #2
0
/** Tries to lock the mutex for a process
 *
 * \param  issuer  the process that tries to acquire the mutex
 * \return whether we managed to lock the mutex
 */
bool Mutex::try_lock(smx_actor_t issuer)
{
  XBT_IN("(%p, %p)", this, issuer);
  if (this->locked) {
    XBT_OUT();
    return false;
  }

  this->locked = true;
  this->owner = issuer;
  XBT_OUT();
  return true;
}
コード例 #3
0
ファイル: storage_n11.cpp プロジェクト: fabienchaix/simgrid
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();
}
コード例 #4
0
ファイル: surf_action.c プロジェクト: cemsbr/simgrid
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();
}
コード例 #5
0
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();
}
コード例 #6
0
ファイル: smx_synchro.c プロジェクト: Shurakai/SimGrid
/**
 * \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();
}
コード例 #7
0
/**
 * \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();
}
コード例 #8
0
ファイル: smx_synchro.c プロジェクト: Shurakai/SimGrid
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();
}
コード例 #9
0
ファイル: smx_synchro.c プロジェクト: Shurakai/SimGrid
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();
}
コード例 #10
0
/** 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();
}
コード例 #11
0
ファイル: maxmin.cpp プロジェクト: frs69wq/simgrid
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();
}
コード例 #12
0
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;
}
コード例 #13
0
/**
 * \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();
}
コード例 #14
0
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();
}
コード例 #15
0
ファイル: cpu_cas01.cpp プロジェクト: fabienchaix/simgrid
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;
}
コード例 #16
0
ファイル: smx_synchro.c プロジェクト: Shurakai/SimGrid
/**
 * \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();
}
コード例 #17
0
ファイル: smx_synchro.c プロジェクト: FlorianPO/simgrid
/**
 * \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();
}
コード例 #18
0
ファイル: smx_synchro.c プロジェクト: Shurakai/SimGrid
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();
}
コード例 #19
0
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();
}
コード例 #20
0
ファイル: smx_synchro.c プロジェクト: Shurakai/SimGrid
/**
 * \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();
}
コード例 #21
0
ファイル: surf_action.c プロジェクト: cemsbr/simgrid
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();
}
コード例 #22
0
ファイル: storage_n11.cpp プロジェクト: fabienchaix/simgrid
void StorageN11Action::suspend()
{
  XBT_IN("(%p)", this);
  if (suspended_ != 2) {
    lmm_update_variable_weight(getModel()->getMaxminSystem(), getVariable(), 0.0);
    suspended_ = 1;
  }
  XBT_OUT();
}
コード例 #23
0
/**
 * \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;
}
コード例 #24
0
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;
}
コード例 #25
0
ファイル: smx_synchro.c プロジェクト: Shurakai/SimGrid
/**
 * \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;
}
コード例 #26
0
ファイル: surf_action.c プロジェクト: cemsbr/simgrid
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;
}
コード例 #27
0
ファイル: smx_synchro.c プロジェクト: FlorianPO/simgrid
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();
}
コード例 #28
0
ファイル: smx_synchro.c プロジェクト: Shurakai/SimGrid
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();
}
コード例 #29
0
ファイル: smx_synchro.c プロジェクト: Shurakai/SimGrid
/** @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;
}
コード例 #30
0
ファイル: smx_synchro.c プロジェクト: Shurakai/SimGrid
/**
 * \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();
}