Ejemplo n.º 1
0
/** @brief initialize common datastructures to all models */
surf_model_t surf_model_init(void)
{
  s_surf_action_t action;
  surf_model_t model = xbt_new0(s_surf_model_t, 1);

  model->model_private = xbt_new0(s_surf_model_private_t, 1);

  model->states.ready_action_set =
      xbt_swag_new(xbt_swag_offset(action, state_hookup));
  model->states.running_action_set =
      xbt_swag_new(xbt_swag_offset(action, state_hookup));
  model->states.failed_action_set =
      xbt_swag_new(xbt_swag_offset(action, state_hookup));
  model->states.done_action_set =
      xbt_swag_new(xbt_swag_offset(action, state_hookup));

  model->action_unref = int_die_impossible_paction;
  model->action_cancel = void_die_impossible_paction;
  model->action_recycle = void_die_impossible_paction;

  model->action_state_get = surf_action_state_get;
  model->action_state_set = surf_action_state_set;
  model->action_get_start_time = surf_action_get_start_time;
  model->action_get_finish_time = surf_action_get_finish_time;
  model->action_data_set = surf_action_data_set;

  model->model_private->modified_set = NULL;
  model->model_private->action_heap = NULL;
  model->model_private->update_mechanism = UM_UNDEFINED;
  model->model_private->selective_update = 0;

  return model;
}
Ejemplo n.º 2
0
/********************************* Host **************************************/
msg_host_t __MSG_host_create(smx_host_t workstation)
{
  const char *name = SIMIX_host_get_name(workstation);
  msg_host_priv_t host = xbt_new0(s_msg_host_priv_t, 1);
  s_msg_vm_t vm; // simply to compute the offset

  host->vms = xbt_swag_new(xbt_swag_offset(vm,host_vms_hookup));

#ifdef MSG_USE_DEPRECATED
  int i;
  char alias[MAX_ALIAS_NAME + 1] = { 0 };       /* buffer used to build the key of the mailbox */

  if (msg_global->max_channel > 0)
    host->mailboxes = xbt_new0(msg_mailbox_t, msg_global->max_channel);

  for (i = 0; i < msg_global->max_channel; i++) {
    sprintf(alias, "%s:%d", name, i);

    /* the key of the mailbox (in this case) is build from the name of the host and the channel number */
    host->mailboxes[i] = MSG_mailbox_new(alias);
    memset(alias, 0, MAX_ALIAS_NAME + 1);
  }
#endif

  xbt_lib_set(host_lib,name,MSG_HOST_LEVEL,host);
  
  return xbt_lib_get_elm_or_null(host_lib, name);
}
Ejemplo n.º 3
0
static void surf_new_model_init_internal(void)
{
    s_surf_action_t action;

    XBT_DEBUG("surf_new_model_model_init_internal");
    surf_new_model = surf_model_init();

    new_model_running_action_set_that_does_not_need_being_checked =
        xbt_swag_new(xbt_swag_offset(action, state_hookup));

    surf_new_model->name = "New Model";
    surf_new_model->action_unref = new_model_action_unref;
    surf_new_model->action_cancel = new_model_action_cancel;
    surf_new_model->action_state_set = new_model_action_state_set;

    surf_new_model->model_private->finalize = new_model_finalize;
    surf_new_model->model_private->update_actions_state = new_model_update_actions_state;
    surf_new_model->model_private->share_resources = new_model_share_resources;
    surf_new_model->model_private->resource_used = new_model_resource_used;
    surf_new_model->model_private->update_resource_state = new_model_resources_state;

    surf_new_model->suspend = new_model_action_suspend;
    surf_new_model->resume = new_model_action_resume;
    surf_new_model->is_suspended = new_model_action_is_suspended;
    surf_new_model->set_max_duration = new_model_action_set_max_duration;
    surf_new_model->set_priority = new_model_action_set_priority;

    surf_new_model->extension.new_model.fct = new_model_action_fct;
    surf_new_model->extension.new_model.create_resource = new_model_create_resource;

    if (!new_model_maxmin_system) {
        new_model_maxmin_system = lmm_system_new(new_model_selective_update);
    }

}
Ejemplo n.º 4
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();
}
Ejemplo n.º 5
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(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;
}
Ejemplo n.º 6
0
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);
  }
}
Ejemplo n.º 7
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;
}
Ejemplo n.º 8
0
void SIMIX_request_init(void)
{
  s_smx_req_t req;
  int i, nthreads = SIMIX_context_get_nthreads();

  req_lists = xbt_new0(xbt_swag_t, nthreads);
  for(i=0; i < nthreads; i++)
    req_lists[i] = xbt_swag_new(xbt_swag_offset(req, reqtable_hookup));

}
Ejemplo n.º 9
0
/** @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;
}
Ejemplo n.º 10
0
/**
 * \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;
}
Ejemplo n.º 11
0
lmm_constraint_t lmm_constraint_new(lmm_system_t sys, void *id,
                                    double bound_value)
{
  lmm_constraint_t cnst = NULL;
  s_lmm_element_t elem;

  cnst = xbt_new0(s_lmm_constraint_t, 1);
  cnst->id = id;
  cnst->id_int = Global_const_debug_id++;
  xbt_swag_init(&(cnst->element_set),
                xbt_swag_offset(elem, element_set_hookup));
  xbt_swag_init(&(cnst->active_element_set),
                xbt_swag_offset(elem, active_element_set_hookup));

  cnst->bound = bound_value;
  cnst->usage = 0;
  cnst->shared = 1;
  insert_constraint(sys, cnst);

  return cnst;
}
Ejemplo n.º 12
0
lmm_system_t lmm_system_new(int selective_update)
{
  lmm_system_t l = NULL;
  s_lmm_variable_t var;
  s_lmm_constraint_t cnst;

  l = xbt_new0(s_lmm_system_t, 1);

  l->modified = 0;
  l->selective_update_active = selective_update;
  l->visited_counter = 1;

  XBT_DEBUG("Setting selective_update_active flag to %d", l->selective_update_active);

  xbt_swag_init(&(l->variable_set), xbt_swag_offset(var, variable_set_hookup));
  xbt_swag_init(&(l->constraint_set), xbt_swag_offset(cnst, constraint_set_hookup));

  xbt_swag_init(&(l->active_constraint_set), xbt_swag_offset(cnst, active_constraint_set_hookup));

  xbt_swag_init(&(l->modified_constraint_set), xbt_swag_offset(cnst, modified_constraint_set_hookup));
  xbt_swag_init(&(l->saturated_variable_set), xbt_swag_offset(var, saturated_variable_set_hookup));
  xbt_swag_init(&(l->saturated_constraint_set), xbt_swag_offset(cnst, saturated_constraint_set_hookup));

  l->variable_mallocator = xbt_mallocator_new(65536,
                                              lmm_variable_mallocator_new_f,
                                              lmm_variable_mallocator_free_f,
                                              lmm_variable_mallocator_reset_f);

  return l;
}
Ejemplo n.º 13
0
lmm_constraint_t lmm_constraint_new(lmm_system_t sys, void *id, double bound_value)
{
  lmm_constraint_t cnst = nullptr;
  s_lmm_element_t elem;

  cnst = xbt_new0(s_lmm_constraint_t, 1);
  cnst->id = id;
  cnst->id_int = Global_const_debug_id++;
  xbt_swag_init(&(cnst->enabled_element_set), xbt_swag_offset(elem, enabled_element_set_hookup));
  xbt_swag_init(&(cnst->disabled_element_set), xbt_swag_offset(elem, disabled_element_set_hookup));
  xbt_swag_init(&(cnst->active_element_set), xbt_swag_offset(elem, active_element_set_hookup));

  cnst->bound = bound_value;
  cnst->concurrency_maximum=0;
  cnst->concurrency_current=0;
  cnst->concurrency_limit=sg_concurrency_limit;
  cnst->usage = 0;
  cnst->sharing_policy = 1; /* FIXME: don't hardcode the value */
  insert_constraint(sys, cnst);

  return cnst;
}
Ejemplo n.º 14
0
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));
    }
  }
Ejemplo n.º 15
0
XBT_TEST_UNIT("basic", test_swag_basic, "Basic usage")
{
  shmurtz_t obj1, obj2, obj;
  xbt_swag_t setA, setB;

  obj1 = xbt_new0(s_shmurtz_t, 1);
  obj2 = xbt_new0(s_shmurtz_t, 1);

  obj1->name = "Obj 1";
  obj2->name = "Obj 2";

  xbt_test_add("Basic usage");
  xbt_test_log("%p %p %ld\n", obj1, &(obj1->setB),
                (long) ((char *) &(obj1->setB) - (char *) obj1));

  setA = xbt_swag_new(xbt_swag_offset(*obj1, setA));
  setB = xbt_swag_new(xbt_swag_offset(*obj1, setB));

  xbt_swag_insert(obj1, setA);
  xbt_swag_insert(obj1, setB);
  xbt_swag_insert(obj2, setA);
  xbt_swag_insert(obj2, setB);

  xbt_test_assert(xbt_swag_remove(NULL, setB) == NULL);
  xbt_test_assert(xbt_swag_remove(obj1, setB) == obj1);
  /*  xbt_test_assert(xbt_swag_remove(obj2, setB) == obj2); */

  xbt_test_add("Traverse set A");
  xbt_swag_foreach(obj, setA) {
    xbt_test_log("Saw: %s", obj->name);
  }