libcilkrts: GNU Hurd port, and some code cleanup/consolidation (was: Cilk Library)

Thomas Schwinge thomas@codesourcery.com
Mon Sep 29 18:14:00 GMT 2014


Hi!

On Wed, 9 Oct 2013 18:32:11 +0000, "Iyer, Balaji V" <balaji.v.iyer@intel.com> wrote:
> [libcilkrts]

Currently, by means of the libcilkrts/configure.tgt file that has been
added during patch review, libcilkrts is attempted to be built for all
*-*-gnu* system, but it has actually only been ported to GNU/Linux.  This
is Debian bug <http://bugs.debian.org/734973>.  Here is a basic GNU Hurd
port, and some code cleanup/consolidation.  Tested on x86 GNU/Hurd, and
x86_64 GNU/Linux is in progress.  OK for trunk once testing completed?

commit ca8d437e22c659aa6a8d2d57afd9e3944f9b33ce
Author: Thomas Schwinge <thomas@codesourcery.com>
Date:   Sun Sep 21 20:35:49 2014 +0200

    libcilkrts: GNU Hurd port, and some code cleanup/consolidation.
    
    	libcilkrts/
    	* runtime/cilk_malloc.c: Consider __GLIBC__ next to __linux__.
    	* runtime/os-unix.c: Basic port for __GNU__.  Apply some code
    	cleanup/consolidation.
---
 libcilkrts/runtime/cilk_malloc.c |  2 +-
 libcilkrts/runtime/os-unix.c     | 45 +++++++++++++++++++---------------------
 2 files changed, 22 insertions(+), 25 deletions(-)

diff --git libcilkrts/runtime/cilk_malloc.c libcilkrts/runtime/cilk_malloc.c
index 9d02c52..d3de756 100644
--- libcilkrts/runtime/cilk_malloc.c
+++ libcilkrts/runtime/cilk_malloc.c
@@ -39,7 +39,7 @@
 #include "cilk_malloc.h"
 
 #include <stdlib.h>
-#if defined _WIN32 || defined _WIN64 || defined __linux__
+#if defined _WIN32 || defined _WIN64 || defined __GLIBC__ || defined __linux__
 #include <malloc.h>
 #define HAS_MEMALIGN 1
 #endif
diff --git libcilkrts/runtime/os-unix.c libcilkrts/runtime/os-unix.c
index 229c438..70acb14 100644
--- libcilkrts/runtime/os-unix.c
+++ libcilkrts/runtime/os-unix.c
@@ -47,12 +47,6 @@
 #elif defined __APPLE__
 #   include <sys/sysctl.h>
     // Uses sysconf(_SC_NPROCESSORS_ONLN) in verbose output
-#elif defined  __DragonFly__
-// No additional include files
-#elif defined  __FreeBSD__
-// No additional include files
-#elif defined __CYGWIN__
-// Cygwin on Windows - no additional include files
 #elif defined  __VXWORKS__
 #   include <vxWorks.h>   
 #   include <vxCpuLib.h>   
@@ -60,6 +54,9 @@
 // Solaris
 #elif defined __sun__ && defined __svr4__
 #   include <sched.h>
+#elif defined __CYGWIN__ || defined __DragonFly__ || defined __FreeBSD__ \
+  || defined __GNU__
+// No additional include files.
 #else
 #   error "Unsupported OS"
 #endif
@@ -349,7 +346,12 @@ static int linux_get_affinity_count (int tid)
 
 COMMON_SYSDEP int __cilkrts_hardware_cpu_count(void)
 {
-#if defined __ANDROID__ || (defined(__sun__) && defined(__svr4__))
+#if defined __ANDROID__ \
+  || defined __CYGWIN__ \
+  || defined __DragonFly__ \
+  || defined __FreeBSD__ \
+  || defined __GNU__ \
+  || (defined (__sun__) && defined (__svr4__))
     return sysconf (_SC_NPROCESSORS_ONLN);
 #elif defined __MIC__
     /// HACK: Usually, the 3rd and 4th hyperthreads are not beneficial
@@ -369,16 +371,10 @@ COMMON_SYSDEP int __cilkrts_hardware_cpu_count(void)
     assert((unsigned)count == count);
 
     return count;
-#elif defined  __FreeBSD__ || defined __CYGWIN__ || defined __DragonFly__
-    int ncores = sysconf(_SC_NPROCESSORS_ONLN);
-
-    return ncores;
-    // Just get the number of processors
-//    return sysconf(_SC_NPROCESSORS_ONLN);
 #elif defined  __VXWORKS__
     return __builtin_popcount( vxCpuEnabledGet() );
 #else
-#error "Unknown architecture"
+# error "Unsupported architecture"
 #endif
 }
 
@@ -393,13 +389,16 @@ COMMON_SYSDEP void __cilkrts_sleep(void)
 
 COMMON_SYSDEP void __cilkrts_yield(void)
 {
-#if __APPLE__ || __FreeBSD__ || __VXWORKS__
-    // On MacOS, call sched_yield to yield quantum.  I'm not sure why we
+#if defined (__ANDROID__) \
+  || __APPLE__ \
+  || defined (__DragonFly__) \
+  || __FreeBSD__ \
+  || defined (__GNU__) \
+  || (defined (__sun__) && defined (__svr4__)) \
+  || __VXWORKS__
+    // Call sched_yield to yield quantum.  I'm not sure why we
     // don't do this on Linux also.
     sched_yield();
-#elif defined(__DragonFly__)
-    // On DragonFly BSD, call sched_yield to yield quantum.
-    sched_yield();
 #elif defined(__MIC__)
     // On MIC, pthread_yield() really trashes things.  Arch's measurements
     // showed that calling _mm_delay_32() (or doing nothing) was a better
@@ -407,14 +406,12 @@ COMMON_SYSDEP void __cilkrts_yield(void)
     // giving up the processor and latency starting up when work becomes
     // available
     _mm_delay_32(1024);
-#elif defined(__ANDROID__) || (defined(__sun__) && defined(__svr4__))
-    // On Android and Solaris, call sched_yield to yield quantum.  I'm not
-    // sure why we don't do this on Linux also.
-    sched_yield();
-#else
+#elif defined __linux__
     // On Linux, call pthread_yield (which in turn will call sched_yield)
     // to yield quantum.
     pthread_yield();
+#else
+# error "Unsupported architecture"
 #endif
 }
 

Grüße,
 Thomas
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 472 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20140929/2578e9b4/attachment.sig>


More information about the Gcc-patches mailing list