Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'mc'
authorGabriel Corona <gabriel.corona@loria.fr>
Fri, 4 Apr 2014 13:19:43 +0000 (15:19 +0200)
committerGabriel Corona <gabriel.corona@loria.fr>
Fri, 4 Apr 2014 13:19:43 +0000 (15:19 +0200)
19 files changed:
src/bindings/java/surf.i
src/msg/msg_io.c
src/simix/smx_context.c
src/simix/smx_context_thread.c
src/simix/smx_global.c
src/simix/smx_io.c
src/simix/smx_private.h
src/smpi/smpi_bench.c
src/surf/cpu_cas01.hpp
src/surf/cpu_interface.hpp
src/surf/cpu_ti.hpp
src/surf/storage_interface.hpp
src/surf/storage_n11.hpp
src/surf/surf_interface.cpp
src/surf/surf_interface.hpp
src/surf/workstation_interface.cpp
src/xbt/win32_ucontext.c
src/xbt/xbt_main.c
src/xbt/xbt_os_thread.c

index fe5a852..1553e77 100644 (file)
@@ -93,6 +93,7 @@ public:
   void updateLatency(double value, double date=surf_get_clock());
 };
 
+%nodefaultctor Action;
 class Action {
 public:
   Model *getModel();
@@ -101,6 +102,7 @@ public:
   void setBound(double bound);
 };
 
+%nodefaultctor CpuAction;
 class CpuAction : public Action {
 public:
 %extend {
index 3b77073..3f7e1f8 100644 (file)
@@ -322,7 +322,7 @@ msg_error_t MSG_file_rcopy (msg_file_t file, msg_host_t host, const char* fullpa
   /* Find the real host destination where the file will be physically stored */
   xbt_dict_cursor_t cursor = NULL;
   char *mount_name, *storage_name, *file_mount_name, *host_name_dest;
-  msg_storage_t storage_dest;
+  msg_storage_t storage_dest = NULL;
   msg_host_t host_dest;
   size_t longest_prefix_length = 0;
 
index 0bfad29..186b123 100644 (file)
 #include "simgrid/sg_config.h"
 #include "internal_config.h"
 #include "simgrid/modelchecker.h"
+
+
+#ifdef _WIN32
+#include <windows.h>
+#else
 #include <sys/mman.h>
+#endif
+
+#ifdef __MINGW32__ 
+#define _aligned_malloc __mingw_aligned_malloc 
+#define _aligned_free  __mingw_aligned_free 
+#endif //MINGW
+
+
 
 #ifdef HAVE_VALGRIND_VALGRIND_H
 # include <valgrind/valgrind.h>
@@ -119,14 +132,19 @@ void *SIMIX_context_stack_new(void)
     char *alloc = xbt_malloc0(size + xbt_pagesize);
     stack = alloc - ((uintptr_t)alloc & (xbt_pagesize - 1)) + xbt_pagesize;
     *((void **)stack - 1) = alloc;
-#else
+#elif !defined(WIN32)
     if (posix_memalign(&stack, xbt_pagesize, size) != 0)
       xbt_die("Failed to allocate stack.");
+#else
+       stack = _aligned_malloc(size, xbt_pagesize);
 #endif
+
+#ifndef WIN32
     if (mprotect(stack, smx_context_guard_size, PROT_NONE) == -1) {
       XBT_WARN("Failed to protect stack: %s", strerror(errno));
       /* That's not fatal, pursue anyway. */
     }
+#endif
     stack = (char *)stack + smx_context_guard_size;
   } else {
     stack = xbt_malloc0(smx_context_stack_size);
@@ -154,6 +172,7 @@ void SIMIX_context_stack_delete(void *stack)
   VALGRIND_STACK_DEREGISTER(valgrind_stack_id);
 #endif
 
+#ifndef WIN32
   if (smx_context_guard_size > 0 && !MC_is_active()) {
     stack = (char *)stack - smx_context_guard_size;
     if (mprotect(stack, smx_context_guard_size,
@@ -166,6 +185,8 @@ void SIMIX_context_stack_delete(void *stack)
     stack = *((void **)stack - 1);
 #endif
   }
+#endif
+
   xbt_free(stack);
 }
 
index ee35dfd..fbde818 100644 (file)
@@ -152,14 +152,14 @@ static void smx_ctx_thread_stop(smx_context_t pcontext)
 static void *smx_ctx_thread_wrapper(void *param)
 {
   smx_ctx_thread_t context = (smx_ctx_thread_t) param;
-
+#ifndef WIN32
   /* Install alternate signal stack, for SIGSEGV handler. */
   stack_t stack;
   stack.ss_sp = sigsegv_stack;
   stack.ss_size = sizeof sigsegv_stack;
   stack.ss_flags = 0;
   sigaltstack(&stack, NULL);
-
+#endif
   /* Tell the maestro we are starting, and wait for its green light */
   xbt_os_sem_release(context->end);
   xbt_os_sem_acquire(context->begin);
index 71a85a4..a169f8d 100644 (file)
@@ -40,6 +40,7 @@ static void _XBT_CALL inthandler(int ignored)
   exit(1);
 }
 
+#ifndef WIN32
 static void _XBT_CALL segvhandler(int signum, siginfo_t *siginfo, void *context)
 {
   if (siginfo->si_signo == SIGSEGV && siginfo->si_code == SEGV_ACCERR) {
@@ -103,6 +104,7 @@ static void install_segvhandler(void)
   }
 }
 
+#endif
 /********************************* SIMIX **************************************/
 
 XBT_INLINE double SIMIX_timer_next(void)
@@ -160,9 +162,10 @@ void SIMIX_global_init(int *argc, char **argv)
     /* Prepare to display some more info when dying on Ctrl-C pressing */
     signal(SIGINT, inthandler);
 
+#ifndef WIN32
     /* Install SEGV handler */
     install_segvhandler();
-
+#endif
     /* register a function to be called by SURF after the environment creation */
     sg_platf_init();
     sg_platf_postparse_add_cb(SIMIX_post_create_environment);
index 10b39e9..969991b 100644 (file)
@@ -201,11 +201,9 @@ int SIMIX_file_unlink(smx_process_t process, smx_file_t fd)
            sg_host_name(host));
   }
 
-  if (surf_workstation_unlink(host, fd->surf_file)){
-    xbt_free(fd);
-    return 1;
-  } else
-    return 0;
+  int res = surf_workstation_unlink(host, fd->surf_file);
+  xbt_free(fd);
+  return !!res;
 }
 
 sg_size_t SIMIX_pre_file_get_size(smx_simcall_t simcall, smx_file_t fd)
index db37ffb..1cb5514 100644 (file)
@@ -209,7 +209,9 @@ typedef struct s_smx_action {
 void SIMIX_context_mod_init(void);
 void SIMIX_context_mod_exit(void);
 
+#ifndef WIN32
 XBT_PUBLIC_DATA(char sigsegv_stack[SIGSTKSZ]);
+#endif
 
 /* We are using the bottom of the stack to save some information, like the
  * valgrind_stack_id. Define smx_context_usable_stack_size to give the remaining
index 9bd3882..f7464db 100644 (file)
@@ -574,7 +574,6 @@ void* smpi_shared_set_call(const char* func, const char* input, void* data) {
 
 
 
-#ifndef WIN32
 #define TOPAGE(addr) (void *)(((unsigned long)(addr) / xbt_pagesize) * xbt_pagesize)
 
 
@@ -763,5 +762,3 @@ void smpi_destroy_global_memory_segments(){
 
 }
 
-
-#endif
index 685cd4c..438f3c2 100644 (file)
@@ -81,7 +81,6 @@ class CpuCas01Action: public CpuAction {
   friend CpuActionPtr CpuCas01::execute(double size);
   friend CpuActionPtr CpuCas01::sleep(double duration);
 public:
-  CpuCas01Action() {};
   CpuCas01Action(ModelPtr model, double cost, bool failed, double power, lmm_constraint_t constraint);
 
   ~CpuCas01Action() {};
index 7e2203f..cd953f5 100644 (file)
@@ -213,11 +213,6 @@ public:
 class CpuAction : public Action {
 friend CpuPtr getActionCpu(CpuActionPtr action);
 public:
-  /**
-   * @brief CpuAction constructor
-   */
-  CpuAction() {};
-
   /**
    * @brief CpuAction constructor
    *
index b44ff97..752754a 100644 (file)
@@ -159,7 +159,6 @@ class CpuTiAction: public CpuAction {
   friend void CpuTi::updateRemainingAmount(double now);//FIXME
 
 public:
-  CpuTiAction() {};
   CpuTiAction(CpuTiModelPtr model, double cost, bool failed,
                                 CpuTiPtr cpu);
 
index d0e7df6..357200e 100644 (file)
@@ -262,11 +262,6 @@ typedef enum {
  */
 class StorageAction : public Action {
 public:
-  /**
-   * @brief StorageAction constructor
-   */
-  StorageAction() : m_type(READ) {};//FIXME:REMOVE
-
   /**
    * @brief StorageAction constructor
    *
index 93f4f3a..d479002 100644 (file)
@@ -70,7 +70,6 @@ public:
 
 class StorageN11Action : public StorageAction {
 public:
-       StorageN11Action() {}; //FIXME:REMOVE
   StorageN11Action(ModelPtr model, double cost, bool failed, StoragePtr storage, e_surf_action_storage_type_t type);
   void suspend();
   int unref();
index 93506d6..7cf6ef8 100644 (file)
@@ -759,26 +759,29 @@ const char *surf_action_state_names[6] = {
   "SURF_ACTION_NOT_IN_THE_SYSTEM"
 };
 
-Action::Action()
-: m_refcount(1)
-{}
+void Action::initialize(ModelPtr model, double cost, bool failed,
+                        lmm_variable_t var)
+{
+  m_priority = 1.0;
+  m_refcount = 1;
+  m_remains = cost;
+  m_maxDuration = NO_MAX_DURATION;
+  m_finish = -1.0;
+  m_failed = failed;
+  m_start = surf_get_clock();
+  m_cost = cost;
+  p_model = model;
+  p_data = NULL;
+  p_variable = var;
+  m_lastValue = 0;
+  m_lastUpdate = 0;
+  m_suspended = false;
+  m_hat = NOTSET;
+}
 
 Action::Action(ModelPtr model, double cost, bool failed)
- : m_priority(1.0)
- , m_refcount(1)
- , m_remains(cost)
- , m_maxDuration(NO_MAX_DURATION)
- , m_finish(-1.0)
- , m_failed(failed)
- , m_start(surf_get_clock())
- , m_cost(cost)
- , p_model(model)
- , p_data(NULL)
- , p_variable(NULL)
- , m_lastValue(0)
- , m_lastUpdate(0)
- , m_suspended(false)
 {
+  initialize(model, cost, failed);
   #ifdef HAVE_TRACING
     p_category = NULL;
   #endif
@@ -793,21 +796,8 @@ Action::Action(ModelPtr model, double cost, bool failed)
 }
 
 Action::Action(ModelPtr model, double cost, bool failed, lmm_variable_t var)
- : m_priority(1.0)
- , m_refcount(1)
- , m_remains(cost)
- , m_maxDuration(NO_MAX_DURATION)
- , m_finish(-1.0)
- , m_failed(failed)
- , m_start(surf_get_clock())
- , m_cost(cost)
- , p_model(model)
- , p_data(NULL)
- , p_variable(var)
- , m_lastValue(0)
- , m_lastUpdate(0)
- , m_suspended(false)
 {
+  initialize(model, cost, failed, var);
   #ifdef HAVE_TRACING
     p_category = NULL;
   #endif
index 1b4a4c7..36b1977 100644 (file)
@@ -390,12 +390,14 @@ void surf_action_lmm_update_index_heap(void *action, int i);
  * @details An action is an event generated by a resource (e.g.: a communication for the network)
  */
 class Action : public actionHook, public actionLmmHook {
-public:
+private:
   /**
-   * @brief Action constructor
+   * @brief Common initializations for the constructors
    */
-  Action();
+  void initialize(ModelPtr model, double cost, bool failed,
+                  lmm_variable_t var = NULL);
 
+public:
   /**
    * @brief Action constructor
    * 
index ba19f66..f37bff3 100644 (file)
@@ -284,8 +284,8 @@ int Workstation::unlink(surf_file_t fd) {
       // Remove the file from storage
       xbt_dict_remove(st->p_content, fd->name);
 
-      free(fd->name);
-      free(fd->mount);
+      xbt_free(fd->name);
+      xbt_free(fd->mount);
       xbt_free(fd);
       return MSG_OK;
     }
index 560b06c..b538e09 100644 (file)
 /* 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. */
 
-/*\r
- *      win32-ucontext: Unix ucontext_t operations on Windows platforms\r
- *      Copyright(C) 2007 Panagiotis E. Hadjidoukas\r
- *\r
- *      Contact Email: phadjido@cs.uoi.gr, xdoukas@ceid.upatras.gr\r
- *\r
- *      win32-ucontext is free software; you can redistribute it and/or\r
- *      modify it under the terms of the GNU Lesser General Public\r
- *      License as published by the Free Software Foundation; either\r
- *      version 2 of the License, or (at your option) any later version.\r
- *\r
- *      win32-ucontext is distributed in the hope that it will be useful,\r
- *      but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
- *      Lesser General Public License for more details.\r
- *\r
- *      You should have received a copy of the GNU Lesser General Public\r
- *      License along with SimGrid in the file LICENSE-LGPL-2.1;\r
- *      if not, write to the Free Software Foundation, Inc.,\r
- *      59 Temple Place - Suite 330, Boston, MA 02111-1307, USA\r
- */  \r
-    \r
-#include "win32_ucontext.h"\r
-\r
-int getcontext(ucontext_t * ucp) \r
-{\r
-  int ret;\r
-  \r
-      /* Retrieve the full machine context */ \r
-      ucp->uc_mcontext.ContextFlags = CONTEXT_FULL | CONTEXT_DEBUG_REGISTERS;\r
-  ret = GetThreadContext(GetCurrentThread(), &ucp->uc_mcontext);\r
-  return (ret == 0) ? -1 : 0;\r
-}\r
-\r
-int setcontext(const ucontext_t * ucp) \r
-{\r
-  int ret;\r
-  \r
-      /* Restore the full machine context (already set) */ \r
-      ret = SetThreadContext(GetCurrentThread(), &ucp->uc_mcontext);\r
-  return (ret == 0) ? -1 : 0;\r
-}\r
-\r
-int makecontext(ucontext_t * ucp, void (*func) (), int argc, ...) \r
-{\r
-  int i;\r
-  va_list ap;\r
-  char *sp;\r
-\r
-   /* Stack grows down */\r
-      sp = (char *) (size_t) ucp->uc_stack.ss_sp + ucp->uc_stack.ss_size;\r
-  \r
-      /* Reserve stack space for the arguments (maximum possible: argc*(8 bytes per argument)) */ \r
-      sp -= argc * sizeof(void*);\r
-  if (sp < (char *) ucp->uc_stack.ss_sp) {\r
-    \r
-        /* errno = ENOMEM; */ \r
-        return -1;\r
-  }\r
-  \r
-      /* Set the instruction and the stack pointer */\r
-  #ifdef _I_X86_\r
-  ucp->uc_mcontext.Eip = (DWORD) func;\r
-  ucp->uc_mcontext.Esp = (DWORD) sp - sizeof(void*);\r
-  #endif\r
-  #ifdef _IA64_\r
-  #  error "_IA64_"\r
-  #endif\r
-  #ifdef _AMD64_\r
-  ucp->uc_mcontext.Rip = (DWORD64) func;\r
-  ucp->uc_mcontext.Rsp = (DWORD64) sp - sizeof(void*);\r
-  #endif\r
-\r
-      /* Save/Restore the full machine context */ \r
-      ucp->uc_mcontext.ContextFlags = CONTEXT_FULL | CONTEXT_DEBUG_REGISTERS;\r
-  \r
-      /* Copy the arguments */ \r
-      va_start(ap, argc);\r
-  for (i = 0; i < argc; i++) {\r
-    memcpy(sp, ap, sizeof(void*));\r
-    ap += sizeof(void*);\r
-    sp += sizeof(void*);\r
-  }\r
-  va_end(ap);\r
-  return 0;\r
-}\r
-\r
-int swapcontext(ucontext_t * oucp, const ucontext_t * ucp) \r
-{\r
-  int ret;\r
-  if ((oucp == NULL) || (ucp == NULL)) {\r
-    \r
-        /*errno = EINVAL; */ \r
-        return -1;\r
-  }\r
-  ret = getcontext(oucp);\r
-  if (ret == 0) {\r
-    ret = setcontext(ucp);\r
-  }\r
-  return ret;\r
-}\r
-\r
+/*
+ *      win32-ucontext: Unix ucontext_t operations on Windows platforms
+ *      Copyright(C) 2007 Panagiotis E. Hadjidoukas
+ *
+ *      Contact Email: phadjido@cs.uoi.gr, xdoukas@ceid.upatras.gr
+ *
+ *      win32-ucontext is free software; you can redistribute it and/or
+ *      modify it under the terms of the GNU Lesser General Public
+ *      License as published by the Free Software Foundation; either
+ *      version 2 of the License, or (at your option) any later version.
+ *
+ *      win32-ucontext is distributed in the hope that it will be useful,
+ *      but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *      Lesser General Public License for more details.
+ *
+ *      You should have received a copy of the GNU Lesser General Public
+ *      License along with SimGrid in the file LICENSE-LGPL-2.1;
+ *      if not, write to the Free Software Foundation, Inc.,
+ *      59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ */  
+    
+#include "xbt/win32_ucontext.h"
+
+int getcontext(ucontext_t * ucp) 
+{
+  int ret;
+  
+      /* Retrieve the full machine context */ 
+      ucp->uc_mcontext.ContextFlags = CONTEXT_FULL | CONTEXT_DEBUG_REGISTERS;
+  ret = GetThreadContext(GetCurrentThread(), &ucp->uc_mcontext);
+  return (ret == 0) ? -1 : 0;
+}
+
+int setcontext(const ucontext_t * ucp) 
+{
+  int ret;
+  
+      /* Restore the full machine context (already set) */ 
+      ret = SetThreadContext(GetCurrentThread(), &ucp->uc_mcontext);
+  return (ret == 0) ? -1 : 0;
+}
+
+int makecontext(ucontext_t * ucp, void (*func) (), int argc, ...) 
+{
+  int i;
+  va_list ap;
+  char *sp;
+
+   /* Stack grows down */
+      sp = (char *) (size_t) ucp->uc_stack.ss_sp + ucp->uc_stack.ss_size;
+  
+      /* Reserve stack space for the arguments (maximum possible: argc*(8 bytes per argument)) */ 
+      sp -= argc * sizeof(void*);
+  if (sp < (char *) ucp->uc_stack.ss_sp) {
+    
+        /* errno = ENOMEM; */ 
+        return -1;
+  }
+  
+      /* Set the instruction and the stack pointer */
+  #ifdef _I_X86_
+  ucp->uc_mcontext.Eip = (DWORD) func;
+  ucp->uc_mcontext.Esp = (DWORD) sp - sizeof(void*);
+  #endif
+  #ifdef _IA64_
+  #  error "_IA64_"
+  #endif
+  #ifdef _AMD64_
+  ucp->uc_mcontext.Rip = (DWORD64) func;
+  ucp->uc_mcontext.Rsp = (DWORD64) sp - sizeof(void*);
+  #endif
+
+      /* Save/Restore the full machine context */ 
+      ucp->uc_mcontext.ContextFlags = CONTEXT_FULL | CONTEXT_DEBUG_REGISTERS;
+  
+      /* Copy the arguments */ 
+      va_start(ap, argc);
+  for (i = 0; i < argc; i++) {
+    memcpy(sp, ap, sizeof(void*));
+    ap += sizeof(void*);
+    sp += sizeof(void*);
+  }
+  va_end(ap);
+  return 0;
+}
+
+int swapcontext(ucontext_t * oucp, const ucontext_t * ucp) 
+{
+  int ret;
+  if ((oucp == NULL) || (ucp == NULL)) {
+    
+        /*errno = EINVAL; */ 
+        return -1;
+  }
+  ret = getcontext(oucp);
+  if (ret == 0) {
+    ret = setcontext(ucp);
+  }
+  return ret;
+}
+
index 30c1a84..3af5c03 100644 (file)
@@ -85,9 +85,13 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason,
 
 static void xbt_preinit(void) {
   unsigned int seed = 2147483647;
-
+#ifndef WIN32
   xbt_pagesize = sysconf(_SC_PAGESIZE);
-
+#else
+  SYSTEM_INFO si;
+  GetSystemInfo(&si);
+  xbt_pagesize = si.dwPageSize;
+#endif
 #ifdef MMALLOC_WANT_OVERRIDE_LEGACY
   mmalloc_preinit();
 #endif
index f295495..c9dd691 100644 (file)
@@ -232,10 +232,14 @@ void xbt_os_thread_setstacksize(int stack_size)
 
 void xbt_os_thread_setguardsize(int guard_size)
 {
+#ifdef WIN32
+  THROW_UNIMPLEMENTED; //pthread_attr_setguardsize is not implemented in pthread.h on windows
+#else
   size_t sz = guard_size;
   int res = pthread_attr_setguardsize(&thread_attr, sz);
   if (res)
     XBT_WARN("pthread_attr_setguardsize failed (%d) for size: %zd", res, sz);
+#endif
 }
 
 const char *xbt_os_thread_name(xbt_os_thread_t t)