Explorar el Código

use pthread_setaffinity_np instead of sched_setaffinity

Cédric Augonnet hace 16 años
padre
commit
14a1ca0c43
Se han modificado 2 ficheros con 13 adiciones y 3 borrados
  1. 2 2
      configure.ac
  2. 11 1
      src/core/workers.c

+ 2 - 2
configure.ac

@@ -51,10 +51,10 @@ AC_SEARCH_LIBS([pthread_create],[pthread],,AC_MSG_ERROR([pthread library unavail
 AC_SEARCH_LIBS([sqrt],[m],,AC_MSG_ERROR([math library unavailable]))
 AC_SEARCH_LIBS([sysconf],[c],,AC_MSG_ERROR([sysconf unavailable]))
 
-AC_CHECK_FUNC(sched_setaffinity,
+# yes, that's non portable, but it's still better than sched_setaffinity
+AC_CHECK_FUNC(pthread_setaffinity_np,
 	[], [AC_DEFINE(DONTBIND, [1], [Threads are not bound on a CPU])])
 
-
 # There is no posix_memalign on Mac OS X
 AC_CHECK_FUNC(posix_memalign, have_posix_memalign=yes, have_posix_memalign=no)
 if test x$have_posix_memalign = xyes; then

+ 11 - 1
src/core/workers.c

@@ -186,11 +186,21 @@ static void init_machine_config(struct machine_config_s *config,
 void bind_thread_on_cpu(unsigned coreid)
 {
 #ifndef DONTBIND
+	int ret;
+
 	/* fix the thread on the correct cpu */
 	cpu_set_t aff_mask;
 	CPU_ZERO(&aff_mask);
 	CPU_SET(coreid, &aff_mask);
-	sched_setaffinity(0, sizeof(aff_mask), &aff_mask);
+
+	pthread_t self = pthread_self();
+
+	ret = pthread_setaffinity_np(self, sizeof(aff_mask), &aff_mask);
+	if (ret)
+	{
+		perror("pthread_setaffinity_np");
+		STARPU_ASSERT(0);
+	}
 #endif
 }