void updateLatency(double value, double date=surf_get_clock());
};
+%nodefaultctor Action;
class Action {
public:
Model *getModel();
void setBound(double bound);
};
+%nodefaultctor CpuAction;
class CpuAction : public Action {
public:
%extend {
/* 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;
#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>
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);
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,
stack = *((void **)stack - 1);
#endif
}
+#endif
+
xbt_free(stack);
}
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);
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) {
}
}
+#endif
/********************************* SIMIX **************************************/
XBT_INLINE double SIMIX_timer_next(void)
/* 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);
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)
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
-#ifndef WIN32
#define TOPAGE(addr) (void *)(((unsigned long)(addr) / xbt_pagesize) * xbt_pagesize)
}
-
-#endif
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() {};
class CpuAction : public Action {
friend CpuPtr getActionCpu(CpuActionPtr action);
public:
- /**
- * @brief CpuAction constructor
- */
- CpuAction() {};
-
/**
* @brief CpuAction constructor
*
friend void CpuTi::updateRemainingAmount(double now);//FIXME
public:
- CpuTiAction() {};
CpuTiAction(CpuTiModelPtr model, double cost, bool failed,
CpuTiPtr cpu);
*/
class StorageAction : public Action {
public:
- /**
- * @brief StorageAction constructor
- */
- StorageAction() : m_type(READ) {};//FIXME:REMOVE
-
/**
* @brief StorageAction constructor
*
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();
"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
}
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
* @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
*
// 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;
}
/* 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;
+}
+
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
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)