Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Modify MSG_file_open() implementation
[simgrid.git] / src / simix / smx_user.c
index 016f7ab..61ffbfe 100644 (file)
@@ -1,6 +1,7 @@
 /* smx_user.c - public interface to simix                                   */
 
-/* Copyright (c) 2010-2012. Da SimGrid team. All rights reserved.          */
+/* Copyright (c) 2010-2014. The SimGrid Team.
+ * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
@@ -14,11 +15,11 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix);
 
 /* generate strings from the enumeration values */
 static const char* simcall_names[] = {
-SIMCALL_LIST(SIMCALL_STRING_TYPE, SIMCALL_SEP_COMMA)
+#include "simcalls_generated_string.c"
 [SIMCALL_NONE] = "NONE"
 };
 
-SIMCALL_LIST(SIMCALL_FUNC, SIMCALL_SEP_NOTHING)
+#include "simcalls_generated_body.c"
 
 /**
  * \ingroup simix_host_management
@@ -44,6 +45,28 @@ const char* simcall_host_get_name(smx_host_t host)
   return simcall_BODY_host_get_name(host);
 }
 
+/**
+ * \ingroup simix_host_management
+ * \brief Start the host if it is off
+ *
+ * \param host A SIMIX host
+ */
+void simcall_host_on(smx_host_t host)
+{
+  simcall_BODY_host_on(host);
+}
+
+/**
+ * \ingroup simix_host_management
+ * \brief Stop the host if it is on
+ *
+ * \param host A SIMIX host
+ */
+void simcall_host_off(smx_host_t host)
+{
+  simcall_BODY_host_off(host);
+}
+
 /**
  * \ingroup simix_host_management
  * \brief Returns a dict of the properties assigned to a host.
@@ -82,6 +105,31 @@ double simcall_host_get_speed(smx_host_t host)
   return simcall_BODY_host_get_speed(host);
 }
 
+/**
+ * \ingroup simix_host_management
+ * \brief Returns the number of core of the processor.
+ *
+ * \param host A SIMIX host
+ * \return The number of core
+ */
+int simcall_host_get_core(smx_host_t host)
+{
+  return simcall_BODY_host_get_core(host);
+}
+
+/**
+ * \ingroup simix_host_management
+ * \brief Returns the list of processes attached to the host.
+ *
+ * \param host A SIMIX host
+ * \return the swag of attached processes
+ */
+xbt_swag_t simcall_host_get_process_list(smx_host_t host)
+{
+  return simcall_BODY_host_get_process_list(host);
+}
+
+
 /**
  * \ingroup simix_host_management
  * \brief Returns the available speed of the processor.
@@ -108,29 +156,67 @@ int simcall_host_get_state(smx_host_t host)
 
 /**
  * \ingroup simix_host_management
- * \brief Returns the user data associated to a host.
+ * \brief Returns the power peak of a host.
+ *
+ * \param host A SIMIX host
+ * \return the current power peak value (double)
+ */
+double simcall_host_get_current_power_peak(smx_host_t host)
+{
+  return simcall_BODY_host_get_current_power_peak(host);
+}
+
+/**
+ * \ingroup simix_host_management
+ * \brief Returns one power peak (in flops/s) of a host at a given pstate
+ *
+ * \param host A SIMIX host
+ * \param pstate_index pstate to test
+ * \return the current power peak value (double) for pstate_index
+ */
+double simcall_host_get_power_peak_at(smx_host_t host, int pstate_index)
+{
+  return simcall_BODY_host_get_power_peak_at(host, pstate_index);
+}
+
+/**
+ * \ingroup simix_host_management
+ * \brief Returns the number of power states for a host.
+ *
+ * \param host A SIMIX host
+ * \return the number of power states
+ */
+int simcall_host_get_nb_pstates(smx_host_t host)
+{
+  return simcall_BODY_host_get_nb_pstates(host);
+}
+
+/**
+ * \ingroup simix_host_management
+ * \brief Sets a new power peak for a host.
  *
- * \param host SIMIX host
- * \return the user data of this host
+ * \param host A SIMIX host
+ * \param pstate_index The pstate to which the CPU power will be set
+ * \return void
  */
-void* simcall_host_get_data(smx_host_t host)
+void simcall_host_set_power_peak_at(smx_host_t host, int pstate_index)
 {
-  return simcall_BODY_host_get_data(host);
+       simcall_BODY_host_set_power_peak_at(host, pstate_index);
 }
 
 /**
  * \ingroup simix_host_management
- * \brief Sets the user data associated to a host.
+ * \brief Returns the total energy consumed by the host (in Joules)
  *
- * The host must not have previous user data associated to it.
  * \param host A SIMIX host
- * \param data The user data to set
+ * \return the energy consumed by the host (double)
  */
-void simcall_host_set_data(smx_host_t host, void *data)
+double simcall_host_get_consumed_energy(smx_host_t host)
 {
-  simcall_host_set_data(host, data);
+  return simcall_BODY_host_get_consumed_energy(host);
 }
 
+
 /**
  * \ingroup simix_host_management
  * \brief Creates an action that executes some computation of an host.
@@ -142,18 +228,19 @@ void simcall_host_set_data(smx_host_t host, void *data)
  * \param host SIMIX host where the action will be executed
  * \param computation_amount amount Computation amount (in bytes)
  * \param priority computation priority
+ * \param bound
+ * \param affinity_mask
  * \return A new SIMIX execution action
  */
-
 smx_action_t simcall_host_execute(const char *name, smx_host_t host,
                                     double computation_amount,
-                                    double priority)
+                                    double priority, double bound, unsigned long affinity_mask)
 {
   /* checking for infinite values */
   xbt_assert(isfinite(computation_amount), "computation_amount is not finite!");
   xbt_assert(isfinite(priority), "priority is not finite!");
   
-  return simcall_BODY_host_execute(name, host, computation_amount, priority);
+  return simcall_BODY_host_execute(name, host, computation_amount, priority, bound, affinity_mask);
 }
 
 /**
@@ -263,6 +350,33 @@ void simcall_host_execution_set_priority(smx_action_t execution, double priority
   simcall_BODY_host_execution_set_priority(execution, priority);
 }
 
+/**
+ * \ingroup simix_host_management
+ * \brief Changes the capping (the maximum CPU utilization) of an execution action.
+ *
+ * This functions changes the capping only. It calls a surf function.
+ * \param execution The execution action
+ * \param bound The new bound
+ */
+void simcall_host_execution_set_bound(smx_action_t execution, double bound)
+{
+  simcall_BODY_host_execution_set_bound(execution, bound);
+}
+
+/**
+ * \ingroup simix_host_management
+ * \brief Changes the CPU affinity of an execution action.
+ *
+ * This functions changes the CPU affinity of an execution action. See taskset(1) on Linux.
+ * \param execution The execution action
+ * \param host Host
+ * \param mask Affinity mask
+ */
+void simcall_host_execution_set_affinity(smx_action_t execution, smx_host_t host, unsigned long mask)
+{
+  simcall_BODY_host_execution_set_affinity(execution, host, mask);
+}
+
 /**
  * \ingroup simix_host_management
  * \brief Waits for the completion of an execution action and destroy it.
@@ -277,61 +391,166 @@ e_smx_state_t simcall_host_execution_wait(smx_action_t execution)
 
 /**
  * \ingroup simix_vm_management
- * \brief Returns a dict of the properties assigned to a host.
+ * \brief Create a VM on the given physical host.
  *
- * \param host A host
- * \return The properties of this host
+ * \param name VM name
+ * \param host Physical host
+ *
+ * \return The host object of the VM
+ */
+void* simcall_vm_create(const char *name, smx_host_t phys_host){
+  /* will jump to SIMIX_pre_vm_create() in src/simix/smx_smurf_private.h */
+  return simcall_BODY_vm_create(name, phys_host);
+}
+
+/**
+ * \ingroup simix_vm_management
+ * \brief Start the given VM to the given physical host
+ *
+ * \param vm VM
+ */
+void simcall_vm_start(smx_host_t vm)
+{
+  /* will jump to SIMIX_pre_vm_start in src/simix/smx_smurf_private.h */
+  simcall_BODY_vm_start(vm);
+}
+
+/**
+ * \ingroup simix_vm_management
+ * \brief Get the state of the given VM
+ *
+ * \param vm VM
+ * \return The state of the VM
+ */
+int simcall_vm_get_state(smx_host_t vm)
+{
+  /* will jump to SIMIX_pre_vm_get_state in src/simix/smx_smurf_private.h */
+  return simcall_BODY_vm_get_state(vm);
+}
+
+/**
+ * \ingroup simix_vm_management
+ * \brief Get the name of the physical host on which the given VM runs.
+ *
+ * \param vm VM
+ * \return The name of the physical host
  */
-void* simcall_vm_ws_create(const char *name, smx_host_t phys_host){
-  return simcall_BODY_vm_ws_create(name, phys_host);
+void *simcall_vm_get_pm(smx_host_t vm)
+{
+  /* will jump to SIMIX_pre_vm_migrate in src/simix/smx_smurf_private.h */
+  return simcall_BODY_vm_get_pm(vm);
+}
+
+void simcall_vm_set_bound(smx_host_t vm, double bound)
+{
+  /* will jump to SIMIX_pre_vm_set_bound in src/simix/smx_smurf_private.h */
+  simcall_BODY_vm_set_bound(vm, bound);
+}
+
+void simcall_vm_set_affinity(smx_host_t vm, smx_host_t pm, unsigned long mask)
+{
+  /* will jump to SIMIX_pre_vm_set_affinity in src/simix/smx_smurf_private.h */
+  simcall_BODY_vm_set_affinity(vm, pm, mask);
 }
 
-void simcall_vm_start(smx_host_t vm) {
-  simcall_BODY_set_vm_state(vm, msg_vm_state_running);
+void simcall_host_get_params(smx_host_t vm, ws_params_t params)
+{
+  /* will jump to SIMIX_pre_host_get_params in src/simix/smx_smurf_private.h */
+  simcall_BODY_host_get_params(vm, params);
 }
 
-void simcall_vm_migrate(smx_host_t vm, smx_host_t dst_phys)
+void simcall_host_set_params(smx_host_t vm, ws_params_t params)
 {
-  /* will jump to SIMIX_pre_vm_migrate */
-  simcall_BODY_vm_migrate(vm, dst_phys);
+  /* will jump to SIMIX_pre_host_set_params in src/simix/smx_smurf_private.h */
+  simcall_BODY_host_set_params(vm, params);
 }
 
-const char *simcall_vm_get_phys_host(smx_host_t vm)
+/**
+ * \ingroup simix_vm_management
+ * \brief Migrate the given VM to the given physical host
+ *
+ * \param vm VM
+ * \param host Destination physical host
+ */
+void simcall_vm_migrate(smx_host_t vm, smx_host_t host)
 {
-  /* will jump to SIMIX_pre_vm_migrate */
-  simcall_BODY_vm_get_phys_host(vm);
+  /* will jump to SIMIX_pre_vm_migrate in src/simix/smx_smurf_private.h */
+  simcall_BODY_vm_migrate(vm, host);
 }
 
+/**
+ * \ingroup simix_vm_management
+ * \brief Suspend the given VM
+ *
+ * \param vm VM
+ */
 void simcall_vm_suspend(smx_host_t vm)
 {
-  /* will jump to SIMIX_pre_vm_suspend */
+  /* will jump to SIMIX_pre_vm_suspend in src/simix/smx_smurf_private.h */
   simcall_BODY_vm_suspend(vm);
 }
 
+/**
+ * \ingroup simix_vm_management
+ * \brief Resume the given VM
+ *
+ * \param vm VM
+ */
 void simcall_vm_resume(smx_host_t vm)
 {
-  /*
-   * simcall_BODY_ is defined in src/simix/smx_smurf_private.h.
-   * This function will jump to SIMIX_pre_vm_resume.
-   **/
+  /* will jump to SIMIX_pre_vm_resume in src/simix/smx_smurf_private.h */
   simcall_BODY_vm_resume(vm);
 }
 
+/**
+ * \ingroup simix_vm_management
+ * \brief Save the given VM
+ *
+ * \param vm VM
+ */
+void simcall_vm_save(smx_host_t vm)
+{
+  /* will jump to SIMIX_pre_vm_save in src/simix/smx_smurf_private.h */
+  simcall_BODY_vm_save(vm);
+}
+
+/**
+ * \ingroup simix_vm_management
+ * \brief Restore the given VM
+ *
+ * \param vm VM
+ */
+void simcall_vm_restore(smx_host_t vm)
+{
+  /* will jump to SIMIX_pre_vm_restore in src/simix/smx_smurf_private.h */
+  simcall_BODY_vm_restore(vm);
+}
+
+/**
+ * \ingroup simix_vm_management
+ * \brief Shutdown the given VM
+ *
+ * \param vm VM
+ */
 void simcall_vm_shutdown(smx_host_t vm)
 {
-  /* will jump to SIMIX_pre_vm_shutdown */
+  /* will jump to SIMIX_pre_vm_shutdown in src/simix/smx_smurf_private.h */
   simcall_BODY_vm_shutdown(vm);
 }
 
+/**
+ * \ingroup simix_vm_management
+ * \brief Destroy the given VM
+ *
+ * \param vm VM
+ */
 void simcall_vm_destroy(smx_host_t vm)
 {
-  /*
-   * simcall_BODY_ is defined in src/simix/smx_smurf_private.h.
-   * This function will jump to SIMIX_pre_vm_destroy.
-   **/
+   /* will jump to SIMIX_pre_vm_destroy in src/simix/smx_smurf_private.h */
   simcall_BODY_vm_destroy(vm);
 }
 
+
 /**
  * \ingroup simix_process_management
  * \brief Creates and runs a new SIMIX process.
@@ -665,17 +884,10 @@ smx_rdv_t simcall_rdv_get_by_name(const char *name)
 {
   xbt_assert(name != NULL, "Invalid parameter for simcall_rdv_get_by_name (name is NULL)");
 
-  /* FIXME: this is a horrible lost of performance, so we hack it out by
+  /* FIXME: this is a horrible loss of performance, so we hack it out by
    * skipping the simcall (for now). It works in parallel, it won't work on
    * distributed but probably we will change MSG for that. */
 
-  /*
-  smx_simcall_t simcall = simcall_mine();
-  simcall->call = SIMCALL_RDV_GEY_BY_NAME;
-  simcall->rdv_get_by_name.name = name;
-  SIMIX_simcall_push(simcall->issuer);
-  return simcall->rdv_get_by_name.result;*/
-
   return SIMIX_rdv_get_by_name(name);
 }
 
@@ -730,9 +942,11 @@ void simcall_comm_send(smx_rdv_t rdv, double task_size, double rate,
 
   if (MC_is_active()) {
     /* the model-checker wants two separate simcalls */
-    smx_action_t comm = simcall_comm_isend(rdv, task_size, rate,
+    smx_action_t comm = NULL; /* MC needs the comm to be set to NULL during the simcall */
+    comm = simcall_comm_isend(rdv, task_size, rate,
         src_buff, src_buff_size, match_fun, NULL, data, 0);
     simcall_comm_wait(comm, timeout);
+    comm = NULL;
   }
   else {
     simcall_BODY_comm_send(rdv, task_size, rate, src_buff, src_buff_size,
@@ -760,39 +974,43 @@ smx_action_t simcall_comm_isend(smx_rdv_t rdv, double task_size, double rate,
                                  src_buff_size, match_fun,
                                  clean_fun, data, detached);
 }
+
 /**
  * \ingroup simix_comm_management
  */
 void simcall_comm_recv(smx_rdv_t rdv, void *dst_buff, size_t * dst_buff_size,
-                         int (*match_fun)(void *, void *, smx_action_t), void *data, double timeout)
+                       int (*match_fun)(void *, void *, smx_action_t),
+                       void *data, double timeout, double rate)
 {
   xbt_assert(isfinite(timeout), "timeout is not finite!");
   xbt_assert(rdv, "No rendez-vous point defined for recv");
 
   if (MC_is_active()) {
     /* the model-checker wants two separate simcalls */
-    smx_action_t comm = simcall_comm_irecv(rdv, dst_buff, dst_buff_size,
-        match_fun, data);
+    smx_action_t comm = NULL; /* MC needs the comm to be set to NULL during the simcall */
+    comm = simcall_comm_irecv(rdv, dst_buff, dst_buff_size,
+                              match_fun, data, rate);
     simcall_comm_wait(comm, timeout);
+    comm = NULL;
   }
   else {
     simcall_BODY_comm_recv(rdv, dst_buff, dst_buff_size,
-                           match_fun, data, timeout);
+                           match_fun, data, timeout, rate);
   }
 }
 /**
  * \ingroup simix_comm_management
  */
 smx_action_t simcall_comm_irecv(smx_rdv_t rdv, void *dst_buff, size_t *dst_buff_size,
-                                  int (*match_fun)(void *, void *, smx_action_t), void *data)
+                                int (*match_fun)(void *, void *, smx_action_t),
+                                void *data, double rate)
 {
   xbt_assert(rdv, "No rendez-vous point defined for irecv");
 
-  return simcall_BODY_comm_irecv(rdv, dst_buff, dst_buff_size, 
-                                 match_fun, data);
+  return simcall_BODY_comm_irecv(rdv, dst_buff, dst_buff_size,
+                                 match_fun, data, rate);
 }
 
-
 /**
  * \ingroup simix_comm_management
  */
@@ -804,22 +1022,6 @@ smx_action_t simcall_comm_iprobe(smx_rdv_t rdv, int src, int tag,
   return simcall_BODY_comm_iprobe(rdv, src, tag, match_fun, data);
 }
 
-void simcall_comm_destroy(smx_action_t comm)
-{
-  xbt_assert(comm, "Invalid parameter");
-
-  /* FIXME remove this simcall type: comms are auto-destroyed now */
-
-  /*
-  smx_simcall_t simcall = simcall_mine();
-
-  simcall->call = SIMCALL_COMM_DESTROY;
-  simcall->comm_destroy.comm = comm;
-
-  SIMIX_simcall_push(simcall->issuer);
-  */
-}
-
 /**
  * \ingroup simix_comm_management
  */
@@ -1063,7 +1265,7 @@ smx_sem_t simcall_sem_init(int capacity)
  */
 void simcall_sem_destroy(smx_sem_t sem)
 {
-  simcall_sem_destroy(sem);
+  simcall_BODY_sem_destroy(sem);
 }
 
 /**
@@ -1116,63 +1318,161 @@ int simcall_sem_get_capacity(smx_sem_t sem)
  * \ingroup simix_file_management
  *
  */
-double simcall_file_read(void* ptr, size_t size, size_t nmemb, smx_file_t stream)
+sg_size_t simcall_file_read(smx_file_t fd, sg_size_t size)
 {
-  return simcall_BODY_file_read(ptr, size, nmemb, stream);
+  return simcall_BODY_file_read(fd, size);
 }
 
 /**
  * \ingroup simix_file_management
  *
  */
-size_t simcall_file_write(const void* ptr, size_t size, size_t nmemb, smx_file_t stream)
+sg_size_t simcall_file_write(smx_file_t fd, sg_size_t size)
 {
-  return simcall_BODY_file_write(ptr, size, nmemb, stream);
+  return simcall_BODY_file_write(fd, size);
 }
 
 /**
  * \ingroup simix_file_management
  * \brief
  */
-smx_file_t simcall_file_open(const char* mount, const char* path, const char* mode)
+smx_file_t simcall_file_open(const char* fullpath)
 {
-  return simcall_BODY_file_open(mount, path, mode);
+  return simcall_BODY_file_open(fullpath);
 }
 
 /**
  * \ingroup simix_file_management
  *
  */
-int simcall_file_close(smx_file_t fp)
+int simcall_file_close(smx_file_t fd)
 {
-  return simcall_BODY_file_close(fp);  
+  return simcall_BODY_file_close(fd);
 }
 
 /**
  * \ingroup simix_file_management
  *
  */
-int simcall_file_stat(smx_file_t fd, s_file_stat_t *buf)
+int simcall_file_unlink(smx_file_t fd)
 {
-  return simcall_BODY_file_stat(fd, buf);
+  return simcall_BODY_file_unlink(fd);
 }
 
 /**
  * \ingroup simix_file_management
  *
  */
-int simcall_file_unlink(smx_file_t fd)
+xbt_dict_t simcall_file_ls(const char* mount, const char* path)
 {
-  return simcall_BODY_file_unlink(fd);
+  return simcall_BODY_file_ls(mount, path);
+}
+/**
+ * \ingroup simix_file_management
+ *
+ */
+sg_size_t simcall_file_get_size(smx_file_t fd){
+  return simcall_BODY_file_get_size(fd);
 }
 
 /**
  * \ingroup simix_file_management
  *
  */
-xbt_dict_t simcall_file_ls(const char* mount, const char* path)
+sg_size_t simcall_file_tell(smx_file_t fd){
+  return simcall_BODY_file_tell(fd);
+}
+
+/**
+ * \ingroup simix_file_management
+ *
+ */
+xbt_dynar_t simcall_file_get_info(smx_file_t fd)
 {
-  return simcall_BODY_file_ls(mount, path);
+  return simcall_BODY_file_get_info(fd);
+}
+
+/**
+ * \ingroup simix_file_management
+ *
+ */
+int simcall_file_seek(smx_file_t fd, sg_size_t offset, int origin){
+  return simcall_BODY_file_seek(fd, offset, origin);
+}
+
+/**
+ * \ingroup simix_file_management
+ *
+ */
+void simcall_storage_file_rename(smx_storage_t storage, const char* src,  const char* dest)
+{
+  return simcall_BODY_storage_file_rename(storage, src, dest);
+}
+
+/**
+ * \ingroup simix_storage_management
+ * \brief Returns the free space size on a given storage element.
+ * \param storage name
+ * \return Return the free space size on a given storage element (as sg_size_t)
+ */
+sg_size_t simcall_storage_get_free_size (const char* name){
+  return simcall_BODY_storage_get_free_size(name);
+}
+
+/**
+ * \ingroup simix_storage_management
+ * \brief Returns the used space size on a given storage element.
+ * \param storage name
+ * \return Return the used space size on a given storage element (as sg_size_t)
+ */
+sg_size_t simcall_storage_get_used_size (const char* name){
+  return simcall_BODY_storage_get_used_size(name);
+}
+
+/**
+ * \ingroup simix_storage_management
+ * \brief Returns the list of storages mounted on an host.
+ * \param host A SIMIX host
+ * \return a dict containing all storages mounted on the host
+ */
+xbt_dict_t simcall_host_get_mounted_storage_list(smx_host_t host)
+{
+  return simcall_BODY_host_get_mounted_storage_list(host);
+}
+
+/**
+ * \ingroup simix_storage_management
+ * \brief Returns the list of storages attached to an host.
+ * \param host A SIMIX host
+ * \return a dict containing all storages attached to the host
+ */
+xbt_dynar_t simcall_host_get_attached_storage_list(smx_host_t host)
+{
+  return simcall_BODY_host_get_attached_storage_list(host);
+}
+
+/**
+ * \ingroup simix_storage_management
+ * \brief Returns a dict of the properties assigned to a storage element.
+ *
+ * \param storage A storage element
+ * \return The properties of this storage element
+ */
+xbt_dict_t simcall_storage_get_properties(smx_storage_t storage)
+{
+  return simcall_BODY_storage_get_properties(storage);
+}
+
+/**
+ * \ingroup simix_storage_management
+ * \brief Returns a dict containing the content of a storage element.
+ *
+ * \param storage A storage element
+ * \return The content of this storage element as a dict (full path file => size)
+ */
+xbt_dict_t simcall_storage_get_content(smx_storage_t storage)
+{
+  return simcall_BODY_storage_get_content(storage);
 }
 
 #ifdef HAVE_MC
@@ -1186,6 +1486,12 @@ int simcall_mc_compare_snapshots(void *s1, void *s2){
   return simcall_BODY_mc_compare_snapshots(s1, s2);
 }
 
+int simcall_mc_random(int min, int max)
+{
+  return simcall_BODY_mc_random(min, max);
+}
+
+
 #endif /* HAVE_MC */
 
 /* ****************************************************************************************** */