Esempio n. 1
0
void NetworkCm02Model::updateActionsStateLazy(double now, double /*delta*/)
{
  NetworkCm02ActionPtr action;
  while ((xbt_heap_size(p_actionHeap) > 0)
         && (double_equals(xbt_heap_maxkey(p_actionHeap), now, sg_surf_precision))) {
    action = (NetworkCm02ActionPtr) xbt_heap_pop(p_actionHeap);
    XBT_DEBUG("Something happened to action %p", action);
#ifdef HAVE_TRACING
    if (TRACE_is_enabled()) {
      int n = lmm_get_number_of_cnst_from_var(p_maxminSystem, action->getVariable());
      int i;
      for (i = 0; i < n; i++){
        lmm_constraint_t constraint = lmm_get_cnst_from_var(p_maxminSystem,
                                                            action->getVariable(),
                                                            i);
        NetworkCm02LinkPtr link = static_cast<NetworkCm02LinkPtr>(lmm_constraint_id(constraint));
        TRACE_surf_link_set_utilization(link->getName(),
                                        action->getCategory(),
                                        (lmm_variable_getvalue(action->getVariable())*
                                            lmm_get_cnst_weight_from_var(p_maxminSystem,
                                                action->getVariable(),
                                                i)),
                                        action->getLastUpdate(),
                                        now - action->getLastUpdate());
      }
    }
#endif

    // if I am wearing a latency hat
    if (action->getHat() == LATENCY) {
      XBT_DEBUG("Latency paid for action %p. Activating", action);
      lmm_update_variable_weight(p_maxminSystem, action->getVariable(), action->m_weight);
      action->heapRemove(p_actionHeap);
      action->refreshLastUpdate();

        // if I am wearing a max_duration or normal hat
    } else if (action->getHat() == MAX_DURATION ||
        action->getHat() == NORMAL) {
        // no need to communicate anymore
        // assume that flows that reached max_duration have remaining of 0
      XBT_DEBUG("Action %p finished", action);
      action->setRemains(0);
      action->finish();
      action->setState(SURF_ACTION_DONE);
      action->heapRemove(p_actionHeap);

      action->gapRemove();
    }
  }
  return;
}
Esempio n. 2
0
/*********
 * Model *
 *********/
void CpuModel::updateActionsStateLazy(double now, double /*delta*/)
{
  CpuAction *action;
  while ((xbt_heap_size(getActionHeap()) > 0)
         && (double_equals(xbt_heap_maxkey(getActionHeap()), now, sg_surf_precision))) {
    action = static_cast<CpuAction*>(xbt_heap_pop(getActionHeap()));
    XBT_CDEBUG(surf_kernel, "Something happened to action %p", action);
    if (TRACE_is_enabled()) {
      Cpu *cpu = static_cast<Cpu*>(lmm_constraint_id(lmm_get_cnst_from_var(getMaxminSystem(), action->getVariable(), 0)));
      TRACE_surf_host_set_utilization(cpu->getName(), action->getCategory(),
                                      lmm_variable_getvalue(action->getVariable()),
                                      action->getLastUpdate(),
                                      now - action->getLastUpdate());
    }

    action->finish();
    XBT_CDEBUG(surf_kernel, "Action %p finished", action);

    /* set the remains to 0 due to precision problems when updating the remaining amount */
    action->setRemains(0);
    action->setState(SURF_ACTION_DONE);
    action->heapRemove(getActionHeap()); //FIXME: strange call since action was already popped
  }
  if (TRACE_is_enabled()) {
    //defining the last timestamp that we can safely dump to trace file
    //without losing the event ascending order (considering all CPU's)
    double smaller = -1;
    ActionList *actionSet = getRunningActionSet();
    for(ActionList::iterator it(actionSet->begin()), itend(actionSet->end())
       ; it != itend ; ++it) {
      action = static_cast<CpuAction*>(&*it);
        if (smaller < 0) {
          smaller = action->getLastUpdate();
          continue;
        }
        if (action->getLastUpdate() < smaller) {
          smaller = action->getLastUpdate();
        }
    }
    if (smaller > 0) {
      TRACE_last_timestamp_to_dump = smaller;
    }
  }
  return;
}
Esempio n. 3
0
void generic_update_actions_state_lazy(double now, double delta, surf_model_t model)
{
  surf_action_lmm_t action;
  while ((xbt_heap_size(model->model_private->action_heap) > 0)
         && (double_equals(xbt_heap_maxkey(model->model_private->action_heap), now))) {
    action = xbt_heap_pop(model->model_private->action_heap);
    XBT_DEBUG("Something happened to action %p", action);
#ifdef HAVE_TRACING
    if (TRACE_is_enabled()) {
      if(model == surf_cpu_model){
      surf_resource_t cpu =
          lmm_constraint_id(lmm_get_cnst_from_var
                            (model->model_private->maxmin_system,
                             action->variable, 0));
      TRACE_surf_host_set_utilization(cpu->name,
                                      ((surf_action_t)action)->category,
                                      lmm_variable_getvalue(action->variable),
                                      action->last_update,
                                      now - action->last_update);
      }
      else{
        int n = lmm_get_number_of_cnst_from_var(model->model_private->maxmin_system, action->variable);
        unsigned int i;
        for (i = 0; i < n; i++){
          lmm_constraint_t constraint = lmm_get_cnst_from_var(model->model_private->maxmin_system,
                                                              action->variable,
                                                              i);
          link_CM02_t link = lmm_constraint_id(constraint);
          TRACE_surf_link_set_utilization(link->lmm_resource.generic_resource.name,
                                          ((surf_action_t)action)->category,
                                          (lmm_variable_getvalue(action->variable)*
                                              lmm_get_cnst_weight_from_var(model->model_private->maxmin_system,
                                                  action->variable,
                                                  i)),
                                          action->last_update,
                                          now - action->last_update);
        }
      }
    }
#endif

    if(model == surf_cpu_model){
      action->generic_action.finish = surf_get_clock();

      update_resource_energy(model, action);

      /* set the remains to 0 due to precision problems when updating the remaining amount */
      action->generic_action.remains = 0;
      surf_action_state_set((surf_action_t) action, SURF_ACTION_DONE);
      surf_action_lmm_heap_remove(model->model_private->action_heap,action); //FIXME: strange call since action was already popped
    }
    else{
      // if I am wearing a latency hat
      if (action->hat == LATENCY) {
        XBT_DEBUG("Latency paid for action %p. Activating", action);
        lmm_update_variable_weight(model->model_private->maxmin_system, action->variable,
            ((surf_action_network_CM02_t)(action))->weight);
        surf_action_lmm_heap_remove(model->model_private->action_heap,action);
        action->last_update = surf_get_clock();

        // if I am wearing a max_duration or normal hat
      } else if (action->hat == MAX_DURATION ||
          action->hat == NORMAL) {
        // no need to communicate anymore
        // assume that flows that reached max_duration have remaining of 0
      	action->generic_action.finish = surf_get_clock();
     	XBT_DEBUG("Action %p finished", action);
  	action->generic_action.remains = 0;
        ((surf_action_t)action)->finish = surf_get_clock();
        model->action_state_set((surf_action_t) action,
                                             SURF_ACTION_DONE);
        surf_action_lmm_heap_remove(model->model_private->action_heap,action);

        if (model->gap_remove && model == surf_network_model)
          model->gap_remove(action);
      }
    }
  }
#ifdef HAVE_TRACING
  if (TRACE_is_enabled() && model == surf_cpu_model) {
    //defining the last timestamp that we can safely dump to trace file
    //without losing the event ascending order (considering all CPU's)
    double smaller = -1;
    xbt_swag_t running_actions = model->states.running_action_set;
    xbt_swag_foreach(action, running_actions) {
        if (smaller < 0) {
          smaller = action->last_update;
          continue;
        }
        if (action->last_update < smaller) {
          smaller = action->last_update;
        }
    }
    if (smaller > 0) {
      TRACE_last_timestamp_to_dump = smaller;
    }
  }
Esempio n. 4
0
void AsDijkstra::getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_cbarg_t route, double *lat)
{
  getRouteCheckParams(src, dst);
  int src_id = src->id();
  int dst_id = dst->id();

  int *pred_arr = nullptr;
  sg_platf_route_cbarg_t e_route;
  int size = 0;
  xbt_dynar_t nodes = xbt_graph_get_nodes(routeGraph_);

  /* Use the graph_node id mapping set to quickly find the nodes */
  graph_node_map_element_t src_elm = nodeMapSearch(src_id);
  graph_node_map_element_t dst_elm = nodeMapSearch(dst_id);

  int src_node_id = ((graph_node_data_t) xbt_graph_node_get_data(src_elm->node))->graph_id;
  int dst_node_id = ((graph_node_data_t) xbt_graph_node_get_data(dst_elm->node))->graph_id;

  /* if the src and dst are the same */
  if (src_node_id == dst_node_id) {

    xbt_node_t node_s_v = xbt_dynar_get_as(nodes, src_node_id, xbt_node_t);
    xbt_node_t node_e_v = xbt_dynar_get_as(nodes, dst_node_id, xbt_node_t);
    xbt_edge_t edge = xbt_graph_get_edge(routeGraph_, node_s_v, node_e_v);

    if (edge == nullptr)
      THROWF(arg_error, 0, "No route from '%s' to '%s'", src->name(), dst->name());

    e_route = (sg_platf_route_cbarg_t) xbt_graph_edge_get_data(edge);

    for (auto link: *e_route->link_list) {
      route->link_list->insert(route->link_list->begin(), link);
      if (lat)
        *lat += static_cast<Link*>(link)->getLatency();
    }

  }

  route_cache_element_t elm = nullptr;
  if (routeCache_) {  /* cache mode  */
    elm = (route_cache_element_t) xbt_dict_get_or_null_ext(routeCache_, (char *) (&src_id), sizeof(int));
  }

  if (elm) {                    /* cached mode and cache hit */
    pred_arr = elm->pred_arr;
  } else {                      /* not cached mode, or cache miss */

    int nr_nodes = xbt_dynar_length(nodes);
    double * cost_arr = xbt_new0(double, nr_nodes);      /* link cost from src to other hosts */
    pred_arr = xbt_new0(int, nr_nodes); /* predecessors in path from src */
    xbt_heap_t pqueue = xbt_heap_new(nr_nodes, xbt_free_f);

    /* initialize */
    cost_arr[src_node_id] = 0.0;

    for (int i = 0; i < nr_nodes; i++) {
      if (i != src_node_id) {
        cost_arr[i] = DBL_MAX;
      }

      pred_arr[i] = 0;

      /* initialize priority queue */
      int *nodeid = xbt_new0(int, 1);
      *nodeid = i;
      xbt_heap_push(pqueue, nodeid, cost_arr[i]);

    }

    /* apply dijkstra using the indexes from the graph's node array */
    while (xbt_heap_size(pqueue) > 0) {
      int *v_id = (int *) xbt_heap_pop(pqueue);
      xbt_node_t v_node = xbt_dynar_get_as(nodes, *v_id, xbt_node_t);
      xbt_edge_t edge = nullptr;
      unsigned int cursor;

      xbt_dynar_foreach(xbt_graph_node_get_outedges(v_node), cursor, edge) {
        xbt_node_t u_node = xbt_graph_edge_get_target(edge);
        graph_node_data_t data = (graph_node_data_t) xbt_graph_node_get_data(u_node);
        int u_id = data->graph_id;
        sg_platf_route_cbarg_t tmp_e_route = (sg_platf_route_cbarg_t) xbt_graph_edge_get_data(edge);
        int cost_v_u = tmp_e_route->link_list->size();    /* count of links, old model assume 1 */

        if (cost_v_u + cost_arr[*v_id] < cost_arr[u_id]) {
          pred_arr[u_id] = *v_id;
          cost_arr[u_id] = cost_v_u + cost_arr[*v_id];
          int *nodeid = xbt_new0(int, 1);
          *nodeid = u_id;
          xbt_heap_push(pqueue, nodeid, cost_arr[u_id]);
        }
      }

      /* free item popped from pqueue */
      xbt_free(v_id);
    }