X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=rts%2Fposix%2FOSThreads.c;h=324701d40d84f3a981e8aa67a98a438633fa881e;hb=f50be7e999d666670c4ca0910c8a3065ea2f2411;hp=1b85fd41f871ddc0edb37eded24b08674bda3824;hpb=ebb1d38825c6eafeb1e1ff9885b1557e7d065e49;p=ghc-hetmet.git diff --git a/rts/posix/OSThreads.c b/rts/posix/OSThreads.c index 1b85fd4..324701d 100644 --- a/rts/posix/OSThreads.c +++ b/rts/posix/OSThreads.c @@ -23,6 +23,11 @@ #include #endif +#if defined(darwin_HOST_OS) +#include +#include +#endif + #if !defined(HAVE_PTHREAD_H) #error pthreads.h is required for the threaded RTS on Posix platforms #endif @@ -35,6 +40,10 @@ #include #endif +#if defined(darwin_HOST_OS) +#include +#endif + /* * This (allegedly) OS threads independent layer was initially * abstracted away from code that used Pthreads, so the functions @@ -198,6 +207,10 @@ getNumberOfProcessors (void) nproc = sysconf(_SC_NPROCESSORS_ONLN); #elif defined(HAVE_SYSCONF) && defined(_SC_NPROCESSORS_CONF) nproc = sysconf(_SC_NPROCESSORS_CONF); +#elif defined(darwin_HOST_OS) + size_t size = sizeof(nat); + if(0 != sysctlbyname("hw.ncpu",&nproc,&size,NULL,0)) + nproc = 1; #else nproc = 1; #endif @@ -206,13 +219,13 @@ getNumberOfProcessors (void) return nproc; } +#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) // Schedules the thread to run on CPU n of m. m may be less than the // number of physical CPUs, in which case, the thread will be allowed // to run on CPU n, n+m, n+2m etc. void setThreadAffinity (nat n, nat m) { -#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) nat nproc; cpu_set_t cs; nat i; @@ -220,12 +233,33 @@ setThreadAffinity (nat n, nat m) nproc = getNumberOfProcessors(); CPU_ZERO(&cs); for (i = n; i < nproc; i+=m) { - CPU_SET(n, &cs); + CPU_SET(i, &cs); } sched_setaffinity(0, sizeof(cpu_set_t), &cs); -#endif } +#elif defined(darwin_HOST_OS) && defined(THREAD_AFFINITY_POLICY) +// Schedules the current thread in the affinity set identified by tag n. +void +setThreadAffinity (nat n, nat m GNUC3_ATTRIBUTE(__unused__)) +{ + thread_affinity_policy_data_t policy; + + policy.affinity_tag = n; + thread_policy_set(mach_thread_self(), + THREAD_AFFINITY_POLICY, + (thread_policy_t) &policy, + THREAD_AFFINITY_POLICY_COUNT); +} + +#else +void +setThreadAffinity (nat n GNUC3_ATTRIBUTE(__unused__), + nat m GNUC3_ATTRIBUTE(__unused__)) +{ +} +#endif + #else /* !defined(THREADED_RTS) */ int