Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Change sg_storage_size_t to sg_size_t and fix surf network bug
[simgrid.git] / src / surf / surf_interface.cpp
index 96da59f..9f9f50c 100644 (file)
@@ -1,6 +1,8 @@
 #include "surf.hpp"
 #include "workstation.hpp"
+#include "vm_workstation.hpp"
 #include "network.hpp"
+#include "surf_routing_cluster.hpp"
 #include "instr/instr_private.h"
 
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_kernel);
@@ -18,6 +20,10 @@ static WorkstationCLM03Ptr get_casted_workstation(surf_resource_t resource){
   return dynamic_cast<WorkstationCLM03Ptr>(static_cast<ResourcePtr>(surf_workstation_resource_priv(resource)));
 }
 
+static WorkstationVM2013Ptr get_casted_vm_workstation(surf_resource_t resource){
+  return dynamic_cast<WorkstationVM2013Ptr>(static_cast<ResourcePtr>(surf_workstation_resource_priv(resource)));
+}
+
 char *surf_routing_edge_name(sg_routing_edge_t edge){
   return edge->p_name;
 }
@@ -86,6 +92,9 @@ double surf_solve(double max_date)
   tmgr_trace_event_t event = NULL;
   unsigned int iter;
 
+  if(!host_that_restart)
+    host_that_restart = xbt_dynar_new(sizeof(char*), NULL);
+
   if (max_date != -1.0 && max_date != NOW) {
     surf_min = max_date - NOW;
   }
@@ -93,17 +102,17 @@ double surf_solve(double max_date)
   XBT_DEBUG("Looking for next action end for all models except NS3");
 
   if (surf_mins == NULL) {
-    surf_mins = xbt_new(double, xbt_dynar_length(model_list));
+    surf_mins = xbt_new(double, xbt_dynar_length(model_list_invoke));
   }
   surf_min_index = 0;
 
   /* sequential version */
-  xbt_dynar_foreach(model_list, iter, model) {
+  xbt_dynar_foreach(model_list_invoke, iter, model) {
     surf_share_resources(static_cast<ModelPtr>(model));
   }
 
   unsigned i;
-  for (i = 0; i < xbt_dynar_length(model_list); i++) {
+  for (i = 0; i < xbt_dynar_length(model_list_invoke); i++) {
     if ((surf_min < 0.0 || surf_mins[i] < surf_min)
         && surf_mins[i] >= 0.0) {
       surf_min = surf_mins[i];
@@ -147,7 +156,7 @@ double surf_solve(double max_date)
             tmgr_history_get_next_event_leq(history, next_event_date,
                                             &value,
                                             (void **) &resource))) {
-      if (resource->isUsed()) {
+      if (resource->isUsed() || xbt_dict_get_or_null(watched_hosts_lib, resource->m_name)) {
         surf_min = next_event_date - NOW;
         XBT_DEBUG
             ("This event will modify model state. Next event set to %f",
@@ -156,7 +165,7 @@ double surf_solve(double max_date)
       /* update state of model_obj according to new value. Does not touch lmm.
          It will be modified if needed when updating actions */
       XBT_DEBUG("Calling update_resource_state for resource %s with min %lf",
-             resource->p_model->m_name.c_str(), surf_min);
+             resource->m_name, surf_min);
       resource->updateState(event, value, next_event_date);
     }
   } while (1);
@@ -172,7 +181,7 @@ double surf_solve(double max_date)
   XBT_DEBUG("Duration set to %f", surf_min);
 
   NOW = NOW + surf_min;
-
+  /* FIXME: model_list or model_list_invoke? revisit here later */
   /* sequential version */
   xbt_dynar_foreach(model_list, iter, model) {
     surf_update_actions_state(model);
@@ -199,6 +208,21 @@ void routing_get_route_and_latency(sg_routing_edge_t src, sg_routing_edge_t dst,
  * MODEL *
  *********/
 
+surf_model_t surf_resource_model(const void *host, int level) {
+  /* If level is SURF_WKS_LEVEL, ws is a workstation_CLM03 object. It has
+   * surf_resource at the generic_resource field. */
+  ResourcePtr ws = static_cast<ResourcePtr>(xbt_lib_get_level((xbt_dictelm_t) host, level));
+  return ws->p_model;
+}
+
+void *surf_as_cluster_get_backbone(AS_t as){
+  return static_cast<AsClusterPtr>(as)->p_backbone;
+}
+
+void surf_as_cluster_set_backbone(AS_t as, void* backbone){
+  static_cast<AsClusterPtr>(as)->p_backbone = dynamic_cast<NetworkCm02LinkPtr>(static_cast<ResourcePtr>(backbone));
+}
+
 const char *surf_model_name(surf_model_t model){
   return model->m_name.c_str();
 }
@@ -237,8 +261,12 @@ xbt_dynar_t surf_workstation_model_get_route(surf_workstation_model_t model,
   return model->getRoute(get_casted_workstation(src), get_casted_workstation(dst));
 }
 
+void surf_vm_workstation_model_create(const char *name, surf_resource_t ind_phys_host){
+  surf_vm_workstation_model->createResource(name, ind_phys_host);
+}
+
 surf_action_t surf_network_model_communicate(surf_network_model_t model, sg_routing_edge_t src, sg_routing_edge_t dst, double size, double rate){
-  model->communicate(src, dst, size, rate);
+  return model->communicate(src, dst, size, rate);
 }
 
 const char *surf_resource_name(surf_cpp_resource_t resource){
@@ -246,13 +274,17 @@ const char *surf_resource_name(surf_cpp_resource_t resource){
 }
 
 xbt_dict_t surf_resource_get_properties(surf_cpp_resource_t resource){
-  return resource->m_properties;
+  return resource->getProperties();
 }
 
 e_surf_resource_state_t surf_resource_get_state(surf_cpp_resource_t resource){
   return resource->getState();
 }
 
+void surf_resource_set_state(surf_cpp_resource_t resource, e_surf_resource_state_t state){
+  resource->setState(state);
+}
+
 surf_action_t surf_workstation_sleep(surf_resource_t resource, double duration){
   return get_casted_workstation(resource)->sleep(duration);
 }
@@ -273,6 +305,30 @@ surf_action_t surf_workstation_execute(surf_resource_t resource, double size){
   return get_casted_workstation(resource)->execute(size);
 }
 
+double surf_workstation_get_current_power_peak(surf_resource_t resource){
+  return get_casted_workstation(resource)->getCurrentPowerPeak();
+}
+
+double surf_workstation_get_power_peak_at(surf_resource_t resource, int pstate_index){
+  return get_casted_workstation(resource)->getPowerPeakAt(pstate_index);
+}
+
+int surf_workstation_get_nb_pstates(surf_resource_t resource){
+  return get_casted_workstation(resource)->getNbPstates();
+}
+
+void surf_workstation_set_power_peak_at(surf_resource_t resource, int pstate_index){
+  return get_casted_workstation(resource)->setPowerPeakAt(pstate_index);
+}
+
+double surf_workstation_get_consumed_energy(surf_resource_t resource){
+  return get_casted_workstation(resource)->getConsumedEnergy();
+}
+
+xbt_dict_t surf_workstation_get_storage_list(surf_resource_t workstation){
+  return get_casted_workstation(workstation)->getStorageList();
+}
+
 surf_action_t surf_workstation_open(surf_resource_t workstation, const char* mount, const char* path){
   return get_casted_workstation(workstation)->open(mount, path);
 }
@@ -293,24 +349,96 @@ size_t surf_workstation_get_size(surf_resource_t workstation, surf_file_t fd){
   return get_casted_workstation(workstation)->getSize(fd);
 }
 
-surf_action_t surf_workstation_read(surf_resource_t resource, void *ptr, size_t size, surf_file_t fd){
-  return get_casted_workstation(resource)->read(ptr, size, fd);
+surf_action_t surf_workstation_read(surf_resource_t resource, surf_file_t fd, sg_size_t size){
+  return get_casted_workstation(resource)->read(fd, size);
+}
+
+surf_action_t surf_workstation_write(surf_resource_t resource, surf_file_t fd, sg_size_t size){
+  return get_casted_workstation(resource)->write(fd, size);
+}
+
+xbt_dynar_t surf_workstation_get_info(surf_resource_t resource, surf_file_t fd){
+  return get_casted_workstation(resource)->getInfo(fd);
+}
+
+sg_size_t surf_workstation_get_free_size(surf_resource_t resource, const char* name){
+  return get_casted_workstation(resource)->getFreeSize(name);
+}
+
+sg_size_t surf_workstation_get_used_size(surf_resource_t resource, const char* name){
+  return get_casted_workstation(resource)->getUsedSize(name);
 }
 
-surf_action_t surf_workstation_write(surf_resource_t resource, const void *ptr, size_t size, surf_file_t fd){
-  return get_casted_workstation(resource)->write(ptr, size, fd);
+xbt_dynar_t surf_workstation_get_vms(surf_resource_t resource){
+  return get_casted_workstation(resource)->getVms();
 }
 
-int surf_network_link_is_shared(surf_network_link_t link){
-  return link->isShared();
+void surf_workstation_get_params(surf_resource_t resource, ws_params_t params){
+  get_casted_workstation(resource)->getParams(params);
 }
 
-double surf_network_link_get_bandwidth(surf_network_link_t link){
-  return link->getBandwidth();
+void surf_workstation_set_params(surf_resource_t resource, ws_params_t params){
+  get_casted_workstation(resource)->setParams(params);
 }
 
-double surf_network_link_get_latency(surf_network_link_t link){
-  return link->getLatency();
+void surf_vm_workstation_destroy(surf_resource_t resource){
+  delete get_casted_vm_workstation(resource);
+}
+
+void surf_vm_workstation_suspend(surf_resource_t resource){
+  get_casted_vm_workstation(resource)->suspend();
+}
+
+void surf_vm_workstation_resume(surf_resource_t resource){
+  get_casted_vm_workstation(resource)->resume();
+}
+
+void surf_vm_workstation_save(surf_resource_t resource){
+  get_casted_vm_workstation(resource)->save();
+}
+
+void surf_vm_workstation_restore(surf_resource_t resource){
+  get_casted_vm_workstation(resource)->restore();
+}
+
+void surf_vm_workstation_migrate(surf_resource_t resource, surf_resource_t ind_vm_ws_dest){
+  get_casted_vm_workstation(resource)->migrate(ind_vm_ws_dest);
+}
+
+surf_resource_t surf_vm_workstation_get_pm(surf_resource_t resource){
+  return get_casted_vm_workstation(resource)->getPm();
+}
+
+void surf_vm_workstation_set_bound(surf_resource_t resource, double bound){
+  return get_casted_vm_workstation(resource)->setBound(bound);
+}
+
+void surf_vm_workstation_set_affinity(surf_resource_t resource, surf_resource_t cpu, unsigned long mask){
+  return get_casted_vm_workstation(resource)->setAffinity(dynamic_cast<CpuLmmPtr>(get_casted_cpu(cpu)), mask);
+}
+
+int surf_network_link_is_shared(surf_cpp_resource_t link){
+  return dynamic_cast<NetworkCm02LinkPtr>(link)->isShared();
+}
+
+double surf_network_link_get_bandwidth(surf_cpp_resource_t link){
+  return dynamic_cast<NetworkCm02LinkPtr>(link)->getBandwidth();
+}
+
+double surf_network_link_get_latency(surf_cpp_resource_t link){
+  return dynamic_cast<NetworkCm02LinkPtr>(link)->getLatency();
+}
+
+xbt_dict_t surf_storage_get_content(surf_resource_t resource){
+  return dynamic_cast<StoragePtr>(static_cast<ResourcePtr>(surf_storage_resource_priv(resource)))->getContent();
+}
+
+sg_size_t surf_storage_get_size(surf_resource_t resource){
+  return dynamic_cast<StoragePtr>(static_cast<ResourcePtr>(surf_storage_resource_priv(resource)))->getSize();
+}
+
+void surf_storage_rename(surf_resource_t resource, const char* src, const char* dest){
+  dynamic_cast<StoragePtr>(static_cast<ResourcePtr>(surf_storage_resource_priv(resource)))->rename(src, dest);
 }
 
 surf_action_t surf_cpu_execute(surf_resource_t cpu, double size){
@@ -330,7 +458,7 @@ double surf_action_get_finish_time(surf_action_t action){
 }
 
 double surf_action_get_remains(surf_action_t action){
-  return action->m_remains;
+  return action->getRemains();
 }
 
 void surf_action_unref(surf_action_t action){
@@ -342,7 +470,7 @@ void surf_action_suspend(surf_action_t action){
 }
 
 void surf_action_resume(surf_action_t action){
-  action->suspend();
+  action->resume();
 }
 
 void surf_action_cancel(surf_action_t action){
@@ -373,10 +501,20 @@ int surf_action_get_cost(surf_action_t action){
   return action->m_cost;
 }
 
-surf_file_t surf_storage_action_get_file(surf_storage_action_lmm_t action){
-  return action->p_file;
+void surf_cpu_action_set_affinity(surf_action_t action, surf_resource_t cpu, unsigned long mask) {
+  dynamic_cast<CpuActionLmmPtr>(action)->setAffinity( dynamic_cast<CpuLmmPtr>(get_casted_cpu(cpu)), mask);
+}
+
+void surf_cpu_action_set_bound(surf_action_t action, double bound) {
+  dynamic_cast<CpuActionLmmPtr>(action)->setBound(bound);
 }
 
-xbt_dict_t surf_storage_action_get_ls_dict(surf_storage_action_lmm_t action){
-  return action->p_lsDict;
+surf_file_t surf_storage_action_get_file(surf_action_t action){
+  return dynamic_cast<StorageActionPtr>(action)->p_file;
 }
+
+xbt_dict_t surf_storage_action_get_ls_dict(surf_action_t action){
+  return dynamic_cast<StorageActionPtr>(action)->p_lsDict;
+}
+
+