瀏覽代碼

win32 fixes, still some details todo: rwlocks, mutex_trylock and a few sync builtins

Samuel Thibault 15 年之前
父節點
當前提交
ef1d89deed

+ 28 - 2
acinclude.m4

@@ -9,7 +9,7 @@ AC_DEFUN([STARPU_CHECK_SYNC_BUILTINS], [
 			[ac_cv_have_sync_builtins=yes],
 			[ac_cv_have_sync_builtins=yes],
 			[ac_cv_have_sync_builtins=no])])
 			[ac_cv_have_sync_builtins=no])])
   if test $ac_cv_have_sync_builtins = yes; then
   if test $ac_cv_have_sync_builtins = yes; then
-    AC_DEFINE(HAVE_SYNC_BUILTINS, 1,
+    AC_DEFINE(STARPU_HAVE_SYNC_BUILTINS, 1,
 	      [Define to 1 if the target supports __sync_*_compare_and_swap])
 	      [Define to 1 if the target supports __sync_*_compare_and_swap])
   fi])
   fi])
 
 
@@ -22,6 +22,32 @@ AC_DEFUN([STARPU_CHECK_SYNC_FETCH_AND_ADD], [
 			[ac_cv_have_sync_fetch_and_add=yes],
 			[ac_cv_have_sync_fetch_and_add=yes],
 			[ac_cv_have_sync_fetch_and_add=no])])
 			[ac_cv_have_sync_fetch_and_add=no])])
   if test $ac_cv_have_sync_fetch_and_add = yes; then
   if test $ac_cv_have_sync_fetch_and_add = yes; then
-    AC_DEFINE(HAVE_SYNC_FETCH_AND_ADD, 1,
+    AC_DEFINE(STARPU_HAVE_SYNC_FETCH_AND_ADD, 1,
 	      [Define to 1 if the target supports __sync_fetch_and_add])
 	      [Define to 1 if the target supports __sync_fetch_and_add])
   fi])
   fi])
+
+dnl Check whether the target supports __sync_fetch_and_or.
+AC_DEFUN([STARPU_CHECK_SYNC_FETCH_AND_OR], [
+  AC_CACHE_CHECK([whether the target supports __sync_fetch_and_or],
+		 ac_cv_have_sync_fetch_and_or, [
+  AC_LINK_IFELSE([AC_LANG_PROGRAM([int foo, bar;],
+			[bar = __sync_fetch_and_or(&foo, 1);])],
+			[ac_cv_have_sync_fetch_and_or=yes],
+			[ac_cv_have_sync_fetch_and_or=no])])
+  if test $ac_cv_have_sync_fetch_and_or = yes; then
+    AC_DEFINE(STARPU_HAVE_SYNC_FETCH_AND_OR, 1,
+	      [Define to 1 if the target supports __sync_fetch_and_or])
+  fi])
+
+dnl Check whether the target supports __sync_lock_test_and_set.
+AC_DEFUN([STARPU_CHECK_SYNC_LOCK_TEST_AND_SET], [
+  AC_CACHE_CHECK([whether the target supports __sync_lock_test_and_set],
+		 ac_cv_have_sync_lock_test_and_set, [
+  AC_LINK_IFELSE([AC_LANG_PROGRAM([int foo, bar;],
+			[bar = __sync_lock_test_and_set(&foo, 1);])],
+			[ac_cv_have_sync_lock_test_and_set=yes],
+			[ac_cv_have_sync_lock_test_and_set=no])])
+  if test $ac_cv_have_sync_lock_test_and_set = yes; then
+    AC_DEFINE(STARPU_HAVE_SYNC_LOCK_TEST_AND_SET, 1,
+	      [Define to 1 if the target supports __sync_lock_test_and_set])
+  fi])

+ 16 - 2
configure.ac

@@ -51,9 +51,17 @@ esac
 AC_DEFINE_UNQUOTED(STARPUDIR, "$PWD", [location of StarPU sources])
 AC_DEFINE_UNQUOTED(STARPUDIR, "$PWD", [location of StarPU sources])
 AC_SUBST(STARPUDIR, $PWD)
 AC_SUBST(STARPUDIR, $PWD)
 
 
-AC_SEARCH_LIBS([pthread_create],[pthread],,AC_MSG_ERROR([pthread library unavailable]))
+AC_CHECK_LIB([pthread], [pthread_create])
+case "$target" in
+*-*-mingw*) CPPFLAGS+=" -I$PWD/include/pthread-win32 " ;;
+esac
+AC_COMPILE_IFELSE(
+  AC_LANG_PROGRAM([[
+    #include <pthread.h>
+  ]], [[ pthread_t t; pthread_create(&t, NULL, NULL, NULL); ]]),,
+  AC_MSG_ERROR([pthread_create unavailable]))
 AC_SEARCH_LIBS([sqrt],[m],,AC_MSG_ERROR([math library unavailable]))
 AC_SEARCH_LIBS([sqrt],[m],,AC_MSG_ERROR([math library unavailable]))
-AC_SEARCH_LIBS([sysconf],[c],,AC_MSG_ERROR([sysconf unavailable]))
+AC_CHECK_FUNCS([sysconf])
 
 
 AC_CHECK_FUNC([pthread_spin_lock], have_pthread_spin_lock=yes, have_pthread_spin_lock=no)
 AC_CHECK_FUNC([pthread_spin_lock], have_pthread_spin_lock=yes, have_pthread_spin_lock=no)
 if test x$have_pthread_spin_lock = xyes; then
 if test x$have_pthread_spin_lock = xyes; then
@@ -82,6 +90,12 @@ STARPU_CHECK_SYNC_BUILTINS
 # This defines HAVE_SYNC_FETCH_AND_ADD
 # This defines HAVE_SYNC_FETCH_AND_ADD
 STARPU_CHECK_SYNC_FETCH_AND_ADD
 STARPU_CHECK_SYNC_FETCH_AND_ADD
 
 
+# This defines HAVE_SYNC_FETCH_AND_OR
+STARPU_CHECK_SYNC_FETCH_AND_OR
+
+# This defines HAVE_SYNC_LOCK_TEST_AND_SET
+STARPU_CHECK_SYNC_LOCK_TEST_AND_SET
+
 CPPFLAGS="${CPPFLAGS} -D_GNU_SOURCE "
 CPPFLAGS="${CPPFLAGS} -D_GNU_SOURCE "
 
 
 AC_SEARCH_LIBS([set_mempolicy],[numa],[enable_libnuma=yes],[enable_libnuma=no])
 AC_SEARCH_LIBS([set_mempolicy],[numa],[enable_libnuma=yes],[enable_libnuma=no])

+ 332 - 0
include/pthread-win32/pthread.h

@@ -0,0 +1,332 @@
+/*
+ * StarPU
+ * Copyright (C) INRIA 2010 (see AUTHORS file)
+ *
+ * This program 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.1 of the License, or (at
+ * your option) any later version.
+ *
+ * This program 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 in COPYING.LGPL for more details.
+ */
+
+/* This is a minimal pthread implementation based on windows functions.
+ * It is *not* intended to be complete - just complete enough to get
+ * StarPU running.
+ */
+
+#ifndef __STARPU_PTHREAD_H__
+#define __STARPU_PTHREAD_H__
+
+/* TODO:
+ * pthread_rwlock_*
+ * pthread_mutex_trylock
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+#include <windows.h>
+#undef interface
+#include <stdio.h>
+#include <errno.h>
+
+#ifdef __CYGWIN32__
+#include <sys/cygwin.h>
+#define setSystemErrno() errno = cygwin_internal(CW_GET_ERRNO_FROM_WINERROR, (GetLastError())
+#else
+#define setSystemErrno() errno = EIO
+#endif
+#define winPthreadAssertWindows(expr) do { if (!(expr)) { setSystemErrno(); return -1; } } while (0)
+#define winPthreadAssert(expr) do { if (!(expr)) return -1; } while (0)
+
+/***********
+ * threads *
+ ***********/
+
+typedef DWORD pthread_attr_t;
+typedef HANDLE pthread_t;
+
+static inline pthread_t pthread_self(void) {
+  return GetCurrentThread();
+}
+
+static inline int pthread_attr_init (pthread_attr_t *attr) {
+  *attr = 0;
+  return 0;
+}
+
+#define PTHREAD_CREATE_DETACHED 1
+static inline int pthread_attr_setdetachstate (pthread_attr_t *attr, int yes) {
+  /* not supported, ignore */
+  return 0;
+}
+
+static inline int pthread_attr_setstacksize (pthread_attr_t *attr, size_t stacksize) {
+  /* not supported, ignore */
+  return 0;
+}
+
+static inline int pthread_attr_destroy (pthread_attr_t *attr) {
+  return 0;
+}
+
+/* "real" cleanup handling not yet implemented */
+typedef struct {
+  void (*routine) (void *);
+  void *arg;
+} __pthread_cleanup_handler;
+
+void pthread_cleanup_push (void (*routine) (void *), void *arg);
+#define pthread_cleanup_push(routine, arg) do { \
+  __pthread_cleanup_handler __cleanup_handler = {routine, arg};
+
+void pthread_cleanup_pop (int execute);
+#define pthread_cleanup_pop(execute) \
+  if (execute) __cleanup_handler.routine(__cleanup_handler.arg); \
+} while (0);
+
+static inline int pthread_create (
+  pthread_t *thread, const pthread_attr_t *attr,
+  void * (*fun) (void *), void *arg
+) {
+  if (attr && *attr) {
+    errno = EINVAL;
+    return -1;
+  }
+  winPthreadAssertWindows(*thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) fun, arg, 0, NULL));
+  return 0;
+}
+
+static inline int pthread_setcancelstate (int state, int *oldstate) {
+  /* not yet implemented :( */
+  return 0;
+}
+
+static inline int pthread_cancel (pthread_t thread) {
+  /* This is quite harsh :( */
+  winPthreadAssertWindows(TerminateThread(thread, 0));
+  return 0;
+}
+
+static inline void pthread_exit (void *res) {
+  ExitThread((DWORD) res);
+}
+
+static inline int pthread_join (pthread_t thread, void **res) {
+  DWORD _res;
+
+  while (1) {
+    if (GetExitCodeThread(thread, &_res)) {
+      if (res) *res = (void *)_res;
+      return 0;
+    }
+    winPthreadAssertWindows(GetLastError() == STILL_ACTIVE);
+    Sleep(1);
+  }
+}
+
+/***********
+ * mutexes *
+ ***********/
+
+#define PTHREAD_MUTEX_INITIALIZER NULL
+#define PTHREAD_RWLOCK_INITIALIZER NULL
+typedef HANDLE pthread_mutex_t;
+typedef HANDLE pthread_rwlock_t;
+#define PTHREAD_MUTEX_RECURSIVE 1
+typedef int pthread_mutexattr_t;
+
+static inline int pthread_mutexattr_init(pthread_mutexattr_t *attr) {
+  *attr = PTHREAD_MUTEX_RECURSIVE;
+  return 0;
+}
+
+static inline int pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type) {
+  if (type != PTHREAD_MUTEX_RECURSIVE)
+    return EINVAL;
+  *attr = type;
+  return 0;
+}
+
+static inline int pthread_mutex_init (pthread_mutex_t *mutex, pthread_mutexattr_t *attr) {
+  if (attr && *attr!=PTHREAD_MUTEX_RECURSIVE) {
+    errno = EINVAL;
+    return -1;
+  }
+  winPthreadAssertWindows(*mutex = CreateMutex(NULL, FALSE, NULL));
+  return 0;
+}
+
+static inline int pthread_mutex_unlock (pthread_mutex_t *mutex) {
+  winPthreadAssertWindows(ReleaseMutex(*mutex));
+  return 0;
+}
+
+static inline int pthread_mutex_lock (pthread_mutex_t *mutex) {
+  volatile pthread_mutex_t *vmutex = mutex;
+  if (!*vmutex) {
+    HANDLE mutex_init_mutex;
+    winPthreadAssertWindows((mutex_init_mutex = CreateMutex(NULL, FALSE, "BRLTTY mutex init")));
+    winPthreadAssert(!pthread_mutex_lock(&mutex_init_mutex));
+    if (!*vmutex)
+      winPthreadAssert(!pthread_mutex_init((pthread_mutex_t *) vmutex,NULL));
+    winPthreadAssert(!pthread_mutex_unlock(&mutex_init_mutex));
+    winPthreadAssertWindows(CloseHandle(mutex_init_mutex));
+  }
+again:
+  switch (WaitForSingleObject(*vmutex, INFINITE)) {
+    default:
+    case WAIT_FAILED:
+      setSystemErrno();
+      return -1;
+    case WAIT_ABANDONED:
+    case WAIT_OBJECT_0:
+      return 0;
+    case WAIT_TIMEOUT:
+      goto again;
+  }
+}
+
+static inline int pthread_mutex_destroy (pthread_mutex_t *mutex) {
+  winPthreadAssertWindows(CloseHandle(*mutex));
+  return 0;
+}
+
+/**************
+ * conditions *
+ **************/
+
+typedef struct {
+  HANDLE sem;
+  volatile unsigned nbwait;
+} pthread_cond_t;
+#define PTHREAD_COND_INITIALIZER { NULL, 0}
+
+struct timespec {
+  time_t  tv_sec;  /* Seconds */
+  long    tv_nsec; /* Nanoseconds */
+};
+
+typedef unsigned pthread_condattr_t;
+
+static inline int pthread_cond_init (pthread_cond_t *cond, const pthread_condattr_t *attr) {
+  if (attr) {
+    errno = EINVAL;
+    return -1;
+  }
+  winPthreadAssertWindows(cond->sem = CreateSemaphore(NULL, 1, 1, NULL));
+  cond->nbwait = 0;
+  return 0;
+}
+
+static inline int pthread_cond_timedwait (pthread_cond_t *cond, pthread_mutex_t *mutex, const struct timespec *time) {
+  cond->nbwait++;
+  winPthreadAssert(pthread_mutex_unlock(mutex));
+again:
+  switch (WaitForSingleObject(cond->sem, time->tv_sec*1000+time->tv_nsec/1000)) {
+    default:
+    case WAIT_FAILED:
+      setSystemErrno();
+      return -1;
+    case WAIT_TIMEOUT:
+      goto again;
+    case WAIT_ABANDONED:
+    case WAIT_OBJECT_0:
+      break;
+  }
+  winPthreadAssert(pthread_mutex_lock(mutex));
+  cond->nbwait--;
+  return 0;
+}
+
+static inline int pthread_cond_wait (pthread_cond_t *cond, pthread_mutex_t *mutex) {
+  cond->nbwait++;
+  winPthreadAssert(pthread_mutex_unlock(mutex));
+again:
+  switch (WaitForSingleObject(cond->sem, INFINITE)) {
+    case WAIT_FAILED:
+      setSystemErrno();
+      return -1;
+    case WAIT_TIMEOUT:
+      goto again;
+    case WAIT_ABANDONED:
+    case WAIT_OBJECT_0:
+      break;
+  }
+  winPthreadAssert(pthread_mutex_lock(mutex));
+  cond->nbwait--;
+  return 0;
+}
+
+static inline int pthread_cond_signal (pthread_cond_t *cond) {
+  if (cond->nbwait)
+    ReleaseSemaphore(cond->sem, 1, NULL);
+  return 0;
+}
+
+static inline int pthread_cond_broadcast (pthread_cond_t *cond) {
+  ReleaseSemaphore(cond->sem, cond->nbwait, NULL);
+  return 0;
+}
+
+static inline int pthread_cond_destroy (pthread_cond_t *cond) {
+  winPthreadAssertWindows(CloseHandle(cond->sem));
+  return 0;
+}
+
+/*******
+ * TLS *
+ *******/
+
+typedef DWORD pthread_key_t;
+#define PTHREAD_ONCE_INIT {PTHREAD_MUTEX_INITIALIZER, 0}
+typedef struct {
+  pthread_mutex_t mutex;
+  unsigned done;
+} pthread_once_t;
+
+static inline int pthread_once (pthread_once_t *once, void (*oncefun)(void)) {
+  pthread_mutex_lock(&once->mutex);
+  if (!once->done) {
+    oncefun();
+    once->done = 1;
+  }
+  pthread_mutex_unlock(&once->mutex);
+  return 0;
+}
+
+static inline int pthread_key_create (pthread_key_t *key, void (*freefun)(void *)) {
+  DWORD res;
+  winPthreadAssertWindows((res = TlsAlloc()) != 0xFFFFFFFF);
+  *key = res;
+  return 0;
+}
+
+static inline int pthread_key_delete (pthread_key_t key) {
+  winPthreadAssertWindows(TlsFree(key));
+  return 0;
+}
+
+static inline void *pthread_getspecific (pthread_key_t key) {
+  void * res = TlsGetValue(key);
+  if (!res)
+    errno = EIO;
+  return res;
+}
+
+static inline int pthread_setspecific (pthread_key_t key, const void *data) {
+  winPthreadAssertWindows(TlsSetValue(key, (LPVOID) data));
+  return 0;
+}
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* __STARPU_PTHREAD_H__ */

+ 66 - 0
include/pthread-win32/semaphore.h

@@ -0,0 +1,66 @@
+/*
+ * StarPU
+ * Copyright (C) INRIA 2010 (see AUTHORS file)
+ *
+ * This program 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.1 of the License, or (at
+ * your option) any later version.
+ *
+ * This program 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 in COPYING.LGPL for more details.
+ */
+
+/* This is a minimal pthread implementation based on windows functions.
+ * It is *not* intended to be complete - just complete enough to get
+ * StarPU running.
+ */
+
+#ifndef __STARPU_SEMAPHORE_H__
+#define __STARPU_SEMAPHORE_H__
+
+#include "pthread.h"
+
+/**************
+ * semaphores *
+ **************/
+
+typedef HANDLE sem_t;
+
+static inline int sem_init(sem_t *sem, int pshared, unsigned int value) {
+  winPthreadAssertWindows(*sem = CreateSemaphore(NULL, value, MAXLONG, NULL));
+  return 0;
+}
+
+static inline int do_sem_wait(sem_t *sem, DWORD timeout) {
+  switch (WaitForSingleObject(*sem, timeout)) {
+    default:
+    case WAIT_FAILED:
+      setSystemErrno();
+      return -1;
+    case WAIT_TIMEOUT:
+      errno = EAGAIN;
+      return -1;
+    case WAIT_ABANDONED:
+    case WAIT_OBJECT_0:
+      return 0;
+  }
+}
+
+#define sem_wait(sem) do_sem_wait(sem, INFINITE)
+#define sem_trywait(sem) do_sem_wait(sem, 0)
+
+static inline int sem_post(sem_t *sem) {
+  winPthreadAssertWindows(ReleaseSemaphore(*sem, 0, NULL));
+  return 0;
+}
+
+static inline int sem_destroy(sem_t *sem) {
+  winPthreadAssertWindows(CloseHandle(*sem));
+  return 0;
+}
+
+#endif /* __STARPU_SEMAPHORE_H__ */

+ 49 - 2
include/starpu-util.h

@@ -50,13 +50,60 @@ extern "C" {
 #define STARPU_UNLIKELY(expr)          (__builtin_expect(!!(expr),0))
 #define STARPU_UNLIKELY(expr)          (__builtin_expect(!!(expr),0))
 #define STARPU_LIKELY(expr)            (__builtin_expect(!!(expr),1))
 #define STARPU_LIKELY(expr)            (__builtin_expect(!!(expr),1))
 
 
-#ifdef HAVE_SYNC_FETCH_AND_ADD
+#if defined(__i386__) || defined(__x86_64__)
+static inline unsigned starpu_cmpxchg(unsigned *ptr, unsigned next) {
+	unsigned tmp = *ptr;
+	__asm__ __volatile__("lock cmpxchgl %2,%1": "+a" (tmp), "+m" (*ptr) : "q" (next) : "memory");
+	return tmp;
+}
+static inline unsigned starpu_xchg(unsigned *ptr, unsigned next) {
+	/* Note: xchg is always locked already */
+	__asm__ __volatile__("xchgl %1,%0": "+m" (*ptr), "+q" (next) : : "memory");
+	return next;
+}
+#define STARPU_HAVE_XCHG
+#endif
+
+#define STARPU_ATOMIC_SOMETHING(name,expr) \
+static inline unsigned starpu_atomic_##name(unsigned *ptr, unsigned value) { \
+	unsigned old, next; \
+	while (1) { \
+		old = *ptr; \
+		next = expr; \
+		if (starpu_cmpxchg(ptr, next) == old) \
+			break; \
+	}; \
+	return old + value; \
+}
+
+#ifdef STARPU_HAVE_SYNC_FETCH_AND_ADD
 #define STARPU_ATOMIC_ADD(ptr, value)  (__sync_fetch_and_add ((ptr), (value)) + (value))
 #define STARPU_ATOMIC_ADD(ptr, value)  (__sync_fetch_and_add ((ptr), (value)) + (value))
-#define STARPU_ATOMIC_OR(ptr, value)  (__sync_fetch_and_or ((ptr), (value)))
+#elif defined(STARPU_HAVE_XCHG)
+STARPU_ATOMIC_SOMETHING(add, old + value)
+#define STARPU_ATOMIC_ADD(ptr, value) starpu_atomic_add(ptr, value)
 #else
 #else
 #error __sync_fetch_and_add is not available
 #error __sync_fetch_and_add is not available
 #endif
 #endif
 
 
+#ifdef STARPU_HAVE_SYNC_FETCH_AND_OR
+#define STARPU_ATOMIC_OR(ptr, value)  (__sync_fetch_and_or ((ptr), (value)))
+#elif defined(STARPU_HAVE_XCHG)
+STARPU_ATOMIC_SOMETHING(or, old | value)
+#define STARPU_ATOMIC_OR(ptr, value) starpu_atomic_or(ptr, value)
+#else
+#error __sync_fetch_and_or is not available
+#endif
+
+#ifdef STARPU_HAVE_SYNC_LOCK_TEST_AND_SET
+#define STARPU_TEST_AND_SET(ptr, value) (__sync_lock_test_and_set ((ptr), (value)))
+#define STARPU_RELEASE(ptr) (__sync_lock_release ((ptr)))
+#elif defined(STARPU_HAVE_XCHG)
+#define STARPU_TEST_AND_SET(ptr, value) (starpu_xchg((ptr), (value)))
+#define STARPU_RELEASE(ptr) (starpu_xchg((ptr), 0))
+#else
+#error __sync_lock_test_and_set is not available
+#endif
+
 #ifdef USE_CUDA
 #ifdef USE_CUDA
 
 
 #define CUBLAS_REPORT_ERROR(status) 					\
 #define CUBLAS_REPORT_ERROR(status) 					\

+ 4 - 2
include/starpu_config.h.in

@@ -21,8 +21,10 @@
 
 
 #undef HAVE_MALLOC_H
 #undef HAVE_MALLOC_H
 
 
-#undef HAVE_SYNC_BUILTINS
-#undef HAVE_SYNC_FETCH_AND_ADD
+#undef STARPU_HAVE_SYNC_BUILTINS
+#undef STARPU_HAVE_SYNC_FETCH_AND_ADD
+#undef STARPU_HAVE_SYNC_FETCH_AND_OR
+#undef STARPU_HAVE_SYNC_LOCK_TEST_AND_SET
 
 
 #undef MODEL_DEBUG
 #undef MODEL_DEBUG
 #undef STARPU_NO_ASSERT
 #undef STARPU_NO_ASSERT

+ 4 - 2
src/common/fxt.c

@@ -16,10 +16,10 @@
 
 
 #include <starpu.h>
 #include <starpu.h>
 #include <common/config.h>
 #include <common/config.h>
-#include <common/fxt.h>
-
 #ifdef USE_FXT
 #ifdef USE_FXT
 
 
+#include <common/fxt.h>
+
 #define PROF_BUFFER_SIZE  (8*1024*1024)
 #define PROF_BUFFER_SIZE  (8*1024*1024)
 
 
 static char PROF_FILE_USER[128];
 static char PROF_FILE_USER[128];
@@ -99,5 +99,7 @@ void fxt_register_thread(unsigned cpuid)
 
 
 void starpu_trace_user_event(unsigned code __attribute__((unused)))
 void starpu_trace_user_event(unsigned code __attribute__((unused)))
 {
 {
+#ifdef USE_FXT
 	TRACE_USER_EVENT(code);
 	TRACE_USER_EVENT(code);
+#endif
 }
 }

+ 1 - 1
src/common/fxt.h

@@ -23,7 +23,6 @@
 #endif
 #endif
 
 
 #include <unistd.h>
 #include <unistd.h>
-#include <sys/syscall.h> /* pour les définitions de SYS_xxx */
 
 
 #include <string.h>
 #include <string.h>
 #include <sys/types.h>
 #include <sys/types.h>
@@ -87,6 +86,7 @@
 #define FUT_USER_EVENT		0x5132
 #define FUT_USER_EVENT		0x5132
 
 
 #ifdef USE_FXT
 #ifdef USE_FXT
+#include <sys/syscall.h> /* pour les définitions de SYS_xxx */
 #include <fxt/fxt.h>
 #include <fxt/fxt.h>
 #include <fxt/fut.h>
 #include <fxt/fut.h>
 
 

+ 2 - 2
src/common/rwlock.c

@@ -24,13 +24,13 @@ static void _take_busy_lock(rw_lock *lock)
 {
 {
 	uint32_t prev;
 	uint32_t prev;
 	do {
 	do {
-		prev = __sync_lock_test_and_set(&lock->busy, 1);
+		prev = STARPU_TEST_AND_SET(&lock->busy, 1);
 	} while (prev);
 	} while (prev);
 }
 }
 
 
 static void _release_busy_lock(rw_lock *lock)
 static void _release_busy_lock(rw_lock *lock)
 {
 {
-	lock->busy = 0;
+	STARPU_RELEASE(&lock->busy);
 }
 }
 
 
 void init_rw_lock(rw_lock *lock)
 void init_rw_lock(rw_lock *lock)

+ 4 - 3
src/common/starpu-spinlock.c

@@ -16,6 +16,7 @@
 
 
 #include <common/starpu-spinlock.h>
 #include <common/starpu-spinlock.h>
 #include <common/config.h>
 #include <common/config.h>
+#include <starpu-util.h>
 
 
 int starpu_spin_init(starpu_spinlock_t *lock)
 int starpu_spin_init(starpu_spinlock_t *lock)
 {
 {
@@ -44,7 +45,7 @@ int starpu_spin_lock(starpu_spinlock_t *lock)
 #else
 #else
 	uint32_t prev;
 	uint32_t prev;
 	do {
 	do {
-		prev = __sync_lock_test_and_set(&lock->taken, 1);
+		prev = STARPU_TEST_AND_SET(&lock->taken, 1);
 	} while (prev);
 	} while (prev);
 	return 0;
 	return 0;
 #endif
 #endif
@@ -56,7 +57,7 @@ int starpu_spin_trylock(starpu_spinlock_t *lock)
 	return pthread_spin_trylock(&lock->lock);
 	return pthread_spin_trylock(&lock->lock);
 #else
 #else
 	uint32_t prev;
 	uint32_t prev;
-	prev = __sync_lock_test_and_set(&lock->taken, 1);
+	prev = STARPU_TEST_AND_SET(&lock->taken, 1);
 	return (prev == 0)?0:EBUSY;
 	return (prev == 0)?0:EBUSY;
 #endif
 #endif
 }
 }
@@ -66,7 +67,7 @@ int starpu_spin_unlock(starpu_spinlock_t *lock)
 #ifdef HAVE_PTHREAD_SPIN_LOCK
 #ifdef HAVE_PTHREAD_SPIN_LOCK
 	return pthread_spin_unlock(&lock->lock);
 	return pthread_spin_unlock(&lock->lock);
 #else
 #else
-	__sync_lock_release(&lock->taken);
+	STARPU_RELEASE(&lock->taken);
 	return 0;
 	return 0;
 #endif
 #endif
 }
 }

+ 1 - 1
src/common/starpu-spinlock.h

@@ -26,7 +26,7 @@ typedef struct starpu_spinlock_s {
 	pthread_spinlock_t lock;
 	pthread_spinlock_t lock;
 #else
 #else
 	/* we only have a trivial implementation yet ! */
 	/* we only have a trivial implementation yet ! */
-	volatile uint32_t taken __attribute__ ((aligned(16)));
+	uint32_t taken __attribute__ ((aligned(16)));
 #endif
 #endif
 } starpu_spinlock_t;
 } starpu_spinlock_t;
 
 

+ 5 - 0
src/core/perfmodel/perfmodel_history.c

@@ -392,6 +392,7 @@ static void load_history_based_model(struct starpu_perfmodel_t *model, unsigned
  * the performance model files */
  * the performance model files */
 int starpu_list_models(void)
 int starpu_list_models(void)
 {
 {
+#ifdef DT_REG
         char path[256];
         char path[256];
         DIR *dp;
         DIR *dp;
         struct dirent *ep;
         struct dirent *ep;
@@ -414,6 +415,10 @@ int starpu_list_models(void)
                 perror ("Couldn't open the directory");
                 perror ("Couldn't open the directory");
                 return 1;
                 return 1;
         }
         }
+#else
+	perror ("not supported\n");
+	return 1;
+#endif
 }
 }
 
 
 /* This function is intended to be used by external tools that should read the
 /* This function is intended to be used by external tools that should read the

+ 3 - 3
src/core/policies/random-policy.c

@@ -44,13 +44,13 @@ static int _random_push_task(struct jobq_s *q __attribute__ ((unused)), job_t ta
 		alpha_sum += queue_array[worker]->alpha;
 		alpha_sum += queue_array[worker]->alpha;
 	}
 	}
 
 
-	double rand = starpu_drand48()*alpha_sum;
-//	fprintf(stderr, "my rand is %e\n", rand);
+	double random = starpu_drand48()*alpha_sum;
+//	fprintf(stderr, "my rand is %e\n", random);
 
 
 	double alpha = 0.0;
 	double alpha = 0.0;
 	for (worker = 0; worker < nworkers; worker++)
 	for (worker = 0; worker < nworkers; worker++)
 	{
 	{
-		if (alpha + queue_array[worker]->alpha > rand) {
+		if (alpha + queue_array[worker]->alpha > random) {
 			/* we found the worker */
 			/* we found the worker */
 			selected = worker;
 			selected = worker;
 			break;
 			break;

+ 20 - 3
src/core/topology.c

@@ -25,6 +25,10 @@
 #ifdef HAVE_HWLOC
 #ifdef HAVE_HWLOC
 #include <hwloc.h>
 #include <hwloc.h>
 #endif
 #endif
+
+#if defined(__MINGW32__) || defined(__CYGWIN__)
+#include <windows.h>
+#endif
 		
 		
 static unsigned topology_is_initialized = 0;
 static unsigned topology_is_initialized = 0;
 
 
@@ -135,8 +139,15 @@ static void _starpu_init_topology(struct machine_config_s *config)
 			config->cpu_depth = hwloc_get_type_depth(config->hwtopology, HWLOC_OBJ_PROC);
 			config->cpu_depth = hwloc_get_type_depth(config->hwtopology, HWLOC_OBJ_PROC);
 
 
 		config->nhwcpus = hwloc_get_nbobjs_by_depth(config->hwtopology, config->cpu_depth);
 		config->nhwcpus = hwloc_get_nbobjs_by_depth(config->hwtopology, config->cpu_depth);
-#else
+#elif defined(__MINGW32__) || defined(__CYGWIN__)
+		SYSTEM_INFO sysinfo;
+		GetSystemInfo(&sysinfo);
+		config->nhwcpus += sysinfo.dwNumberOfProcessors;
+#elif defined(HAVE_SYSCONF)
 		config->nhwcpus = sysconf(_SC_NPROCESSORS_ONLN);
 		config->nhwcpus = sysconf(_SC_NPROCESSORS_ONLN);
+#else
+#warning no way to know number of cores, assuming 1
+		config->nhwcpus = 1;
 #endif
 #endif
 	
 	
 		topology_is_initialized = 1;
 		topology_is_initialized = 1;
@@ -404,9 +415,8 @@ static inline int _starpu_get_next_bindid(struct machine_config_s *config,
 
 
 void _starpu_bind_thread_on_cpu(struct machine_config_s *config __attribute__((unused)), unsigned cpuid)
 void _starpu_bind_thread_on_cpu(struct machine_config_s *config __attribute__((unused)), unsigned cpuid)
 {
 {
-	int ret;
-
 #ifdef HAVE_HWLOC
 #ifdef HAVE_HWLOC
+	int ret;
 	_starpu_init_topology(config);
 	_starpu_init_topology(config);
 
 
 	hwloc_obj_t obj = hwloc_get_obj_by_depth(config->hwtopology, config->cpu_depth, cpuid);
 	hwloc_obj_t obj = hwloc_get_obj_by_depth(config->hwtopology, config->cpu_depth, cpuid);
@@ -420,6 +430,7 @@ void _starpu_bind_thread_on_cpu(struct machine_config_s *config __attribute__((u
 	}
 	}
 
 
 #elif defined(HAVE_PTHREAD_SETAFFINITY_NP)
 #elif defined(HAVE_PTHREAD_SETAFFINITY_NP)
+	int ret;
 	/* fix the thread on the correct cpu */
 	/* fix the thread on the correct cpu */
 	cpu_set_t aff_mask;
 	cpu_set_t aff_mask;
 	CPU_ZERO(&aff_mask);
 	CPU_ZERO(&aff_mask);
@@ -434,6 +445,12 @@ void _starpu_bind_thread_on_cpu(struct machine_config_s *config __attribute__((u
 		STARPU_ABORT();
 		STARPU_ABORT();
 	}
 	}
 
 
+#elif defined(__MINGW32__) || defined(__CYGWIN__)
+	DWORD mask = 1 << cpuid;
+	if (!SetThreadAffinityMask(GetCurrentThread(), mask)) {
+		fprintf(stderr,"SetThreadMaskAffinity(%lx) failed\n", mask);
+		STARPU_ABORT();
+	}
 #else
 #else
 #warning no CPU binding support
 #warning no CPU binding support
 #endif
 #endif