Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
handle modifications of the DTD in surf
[simgrid.git] / src / surf / workstation.c
index 31afbfa..ed841dc 100644 (file)
@@ -227,12 +227,51 @@ static double ws_get_speed(void *workstation, double load)
       get_speed(workstation, load);
 }
 
+static int ws_get_core(void *workstation)
+{
+  return surf_cpu_model->extension.cpu.
+      get_core(workstation);
+}
+
+
+
 static double ws_get_available_speed(void *workstation)
 {
   return surf_cpu_model->extension.cpu.
       get_available_speed(workstation);
 }
 
+static double ws_get_current_power_peak(void *workstation)
+{
+  return surf_cpu_model->extension.cpu.
+      get_current_power_peak(workstation);
+}
+
+static double ws_get_power_peak_at(void *workstation, int pstate_index)
+{
+  return surf_cpu_model->extension.cpu.
+      get_power_peak_at(workstation, pstate_index);
+}
+
+static int ws_get_nb_pstates(void *workstation)
+{
+  return surf_cpu_model->extension.cpu.
+      get_nb_pstates(workstation);
+}
+
+static void ws_set_power_peak_at(void *workstation, int pstate_index)
+{
+  surf_cpu_model->extension.cpu.
+      set_power_peak_at(workstation, pstate_index);
+}
+
+static double ws_get_consumed_energy(void *workstation)
+{
+  return surf_cpu_model->extension.cpu.
+      get_consumed_energy(workstation);
+}
+
+
 static surf_action_t ws_execute_parallel_task(int workstation_nb,
                                               void **workstation_list,
                                               double *computation_amount,
@@ -305,7 +344,7 @@ static xbt_dict_t ws_get_properties(const void *ws)
   return surf_resource_properties(surf_cpu_resource_priv(ws));
 }
 
-static storage_t find_storage_on_mount_list(void *workstation,const char* storage)
+static storage_t find_storage_on_mount_list(void *workstation,const char* mount)
 {
   storage_t st = NULL;
   s_mount_t mnt;
@@ -313,16 +352,16 @@ static storage_t find_storage_on_mount_list(void *workstation,const char* storag
   workstation_CLM03_t ws = (workstation_CLM03_t) surf_workstation_resource_priv(workstation);
   xbt_dynar_t storage_list = ws->storage;
 
-  XBT_DEBUG("Search for storage name '%s' on '%s'",storage,ws->generic_resource.name);
+  XBT_DEBUG("Search for storage name '%s' on '%s'",mount,ws->generic_resource.name);
   xbt_dynar_foreach(storage_list,cursor,mnt)
   {
     XBT_DEBUG("See '%s'",mnt.name);
-    if(!strcmp(storage,mnt.name)){
-      st = mnt.id;
+    if(!strcmp(mount,mnt.name)){
+      st = mnt.storage;
       break;
     }
   }
-  if(!st) xbt_die("Can't find mount '%s' for '%s'",storage,ws->generic_resource.name);
+  if(!st) xbt_die("Can't find mount '%s' for '%s'",mount,ws->generic_resource.name);
   return st;
 }
 
@@ -337,36 +376,57 @@ static surf_action_t ws_action_open(void *workstation, const char* mount,
 
 static surf_action_t ws_action_close(void *workstation, surf_file_t fd)
 {
-  storage_t st = find_storage_on_mount_list(workstation, fd->storage);
+  storage_t st = find_storage_on_mount_list(workstation, fd->mount);
   XBT_DEBUG("CLOSE on disk '%s'",st->generic_resource.name);
   surf_model_t model = st->generic_resource.model;
   return model->extension.storage.close(st, fd);
 }
 
-static surf_action_t ws_action_read(void *workstation, void* ptr, size_t size,
-                                    size_t nmemb, surf_file_t fd)
+static surf_action_t ws_action_read(void *workstation, size_t size,
+                                    surf_file_t fd)
 {
-  storage_t st = find_storage_on_mount_list(workstation, fd->storage);
+  storage_t st = find_storage_on_mount_list(workstation, fd->mount);
   XBT_DEBUG("READ on disk '%s'",st->generic_resource.name);
   surf_model_t model = st->generic_resource.model;
-  return model->extension.storage.read(st, ptr, (double)size, nmemb, fd);
+  return model->extension.storage.read(st, size, fd);
 }
 
-static surf_action_t ws_action_write(void *workstation, const void* ptr,
-                                     size_t size, size_t nmemb, surf_file_t fd)
+static surf_action_t ws_action_write(void *workstation, size_t size, 
+                                     surf_file_t fd)
 {
-  storage_t st = find_storage_on_mount_list(workstation, fd->storage);
+  storage_t st = find_storage_on_mount_list(workstation, fd->mount);
   XBT_DEBUG("WRITE on disk '%s'",st->generic_resource.name);
   surf_model_t model = st->generic_resource.model;
-  return model->extension.storage.write(st,  ptr, size, nmemb, fd);
+  return model->extension.storage.write(st, size, fd);
 }
 
-static surf_action_t ws_action_unlink(void *workstation, surf_file_t fd)
+static int ws_file_unlink(void *workstation, surf_file_t fd)
 {
-  storage_t st = find_storage_on_mount_list(workstation, fd->storage);
-  XBT_DEBUG("UNLINK on disk '%s'",st->generic_resource.name);
-  surf_model_t model = st->generic_resource.model;
-  return model->extension.storage.unlink(st, fd);
+  if (!fd){
+    XBT_WARN("No such file descriptor. Impossible to unlink");
+    return 0;
+  } else {
+//    XBT_INFO("%s %zu", fd->storage, fd->size);
+    storage_t st = find_storage_on_mount_list(workstation, fd->mount);
+    xbt_dict_t content_dict = (st)->content;
+    /* Check if the file is on this storage */
+    if (!xbt_dict_get_or_null(content_dict, fd->name)){
+      XBT_WARN("File %s is not on disk %s. Impossible to unlink", fd->name,
+          st->generic_resource.name);
+      return 0;
+    } else {
+      XBT_DEBUG("UNLINK on disk '%s'",st->generic_resource.name);
+      st->used_size -= fd->size;
+
+      // Remove the file from storage
+      xbt_dict_remove(content_dict,fd->name);
+
+      free(fd->name);
+      free(fd->mount);
+      xbt_free(fd);
+      return 1;
+    }
+  }
 }
 
 static surf_action_t ws_action_ls(void *workstation, const char* mount,
@@ -417,9 +477,15 @@ static void surf_workstation_model_init_internal(void)
   surf_workstation_model->extension.workstation.execute = ws_execute;
   surf_workstation_model->extension.workstation.sleep = ws_action_sleep;
   surf_workstation_model->extension.workstation.get_state = ws_get_state;
+  surf_workstation_model->extension.workstation.get_core = ws_get_core;
   surf_workstation_model->extension.workstation.get_speed = ws_get_speed;
   surf_workstation_model->extension.workstation.get_available_speed =
       ws_get_available_speed;
+  surf_workstation_model->extension.workstation.get_current_power_peak = ws_get_current_power_peak;
+  surf_workstation_model->extension.workstation.get_power_peak_at = ws_get_power_peak_at;
+  surf_workstation_model->extension.workstation.get_nb_pstates = ws_get_nb_pstates;
+  surf_workstation_model->extension.workstation.set_power_peak_at = ws_set_power_peak_at;
+  surf_workstation_model->extension.workstation.get_consumed_energy = ws_get_consumed_energy;
 
   surf_workstation_model->extension.workstation.communicate =
       ws_communicate;
@@ -439,7 +505,7 @@ static void surf_workstation_model_init_internal(void)
   surf_workstation_model->extension.workstation.close = ws_action_close;
   surf_workstation_model->extension.workstation.read = ws_action_read;
   surf_workstation_model->extension.workstation.write = ws_action_write;
-  surf_workstation_model->extension.workstation.unlink = ws_action_unlink;
+  surf_workstation_model->extension.workstation.unlink = ws_file_unlink;
   surf_workstation_model->extension.workstation.ls = ws_action_ls;
   surf_workstation_model->extension.workstation.get_size = ws_file_get_size;
 }