[Git][ghc/ghc][wip/T14781] 5 commits: Add test for #16167

Ben Gamari gitlab at gitlab.haskell.org
Sun May 10 18:40:44 UTC 2020



Ben Gamari pushed to branch wip/T14781 at Glasgow Haskell Compiler / GHC


Commits:
9d97f4b5 by nineonine at 2020-05-08T15:30:03-04:00
Add test for #16167

- - - - -
aa318338 by Ryan Scott at 2020-05-08T15:30:04-04:00
Bump exceptions submodule so that dist-boot is .gitignore'd

`exceptions` is a stage-0 boot library as of commit
30272412fa437ab8e7a8035db94a278e10513413, which means that building
`exceptions` in a GHC tree will generate a `dist-boot` directory.
However, this directory was not specified in `exceptions`'
`.gitignore` file, which causes it to dirty up the current `git`
working directory.

Accordingly, this bumps the `exceptions` submodule to commit
ghc/packages/exceptions at 23c0b8a50d7592af37ca09beeec16b93080df98f,
which adds `dist-boot` to the `.gitignore` file.

- - - - -
ea86360f by Ömer Sinan Ağacan at 2020-05-08T15:30:30-04:00
Linker.c: initialize n_symbols of ObjectCode with other fields

- - - - -
3c15cd45 by Ben Gamari at 2020-05-10T14:40:37-04:00
rts: Teach getNumProcessors to return available processors

Previously we would report the number of physical processors, which
can be quite wrong in a containerized setting. Now we rather return how
many processors are in our affinity mask when possible.

I also refactored the code to prefer platform-specific since this will
report logical CPUs instead of physical (using
`machdep.cpu.thread_count` on Darwin and `cpuset_getaffinity` on FreeBSD).

Fixes #14781.

- - - - -
ce8bca8d by Ben Gamari at 2020-05-10T14:40:37-04:00
rts: Drop compatibility shims for Windows Vista

We can now assume that the thread and processor group interfaces are
available.

- - - - -


8 changed files:

- configure.ac
- libraries/exceptions
- rts/Linker.c
- rts/posix/OSThreads.c
- rts/win32/OSThreads.c
- + testsuite/tests/driver/T16167.hs
- + testsuite/tests/driver/T16167.stdout
- testsuite/tests/driver/all.T


Changes:

=====================================
configure.ac
=====================================
@@ -964,7 +964,7 @@ FP_CHECK_FUNC([GetModuleFileName],
 
 dnl ** check for more functions
 dnl ** The following have been verified to be used in ghc/, but might be used somewhere else, too.
-AC_CHECK_FUNCS([getclock getrusage gettimeofday setitimer siginterrupt sysconf times ctime_r sched_setaffinity setlocale])
+AC_CHECK_FUNCS([getclock getrusage gettimeofday setitimer siginterrupt sysconf times ctime_r sched_setaffinity sched_getaffinity setlocale])
 
 dnl ** On OS X 10.4 (at least), time.h doesn't declare ctime_r if
 dnl ** _POSIX_C_SOURCE is defined


=====================================
libraries/exceptions
=====================================
@@ -1 +1 @@
-Subproject commit fe4166f8d23d8288ef2cbbf9e36118b6b99e0d7d
+Subproject commit 23c0b8a50d7592af37ca09beeec16b93080df98f


=====================================
rts/Linker.c
=====================================
@@ -1326,6 +1326,7 @@ mkOc( pathchar *path, char *image, int imageSize,
    setOcInitialStatus( oc );
 
    oc->fileSize          = imageSize;
+   oc->n_symbols         = 0;
    oc->symbols           = NULL;
    oc->n_sections        = 0;
    oc->sections          = NULL;


=====================================
rts/posix/OSThreads.c
=====================================
@@ -240,26 +240,50 @@ forkOS_createThread ( HsStablePtr entry )
 
 void freeThreadingResources (void) { /* nothing */ }
 
+// Get the number of logical CPU cores available to us. Note that this is
+// different from the number of physical cores (see #14781).
 uint32_t
 getNumberOfProcessors (void)
 {
     static uint32_t nproc = 0;
 
     if (nproc == 0) {
-#if defined(HAVE_SYSCONF) && defined(_SC_NPROCESSORS_ONLN)
-        nproc = sysconf(_SC_NPROCESSORS_ONLN);
-#elif defined(HAVE_SYSCONF) && defined(_SC_NPROCESSORS_CONF)
-        nproc = sysconf(_SC_NPROCESSORS_CONF);
-#elif defined(darwin_HOST_OS)
+#if defined(HAVE_SCHED_GETAFFINITY)
+        cpu_set_t mask;
+        CPU_ZERO(&mask);
+        if (sched_getaffinity(0, sizeof(mask), &mask) == 0) {
+            for (int i = 0; i < CPU_SETSIZE; i++) {
+                if (CPU_ISSET(i, &mask))
+                    nproc++;
+            }
+            return nproc;
+        }
+#endif
+
+#if defined(darwin_HOST_OS)
         size_t size = sizeof(uint32_t);
-        if(sysctlbyname("hw.logicalcpu",&nproc,&size,NULL,0) != 0) {
+        if (sysctlbyname("machdep.cpu.thread_count",&nproc,&size,NULL,0) != 0) {
+            if (sysctlbyname("hw.logicalcpu",&nproc,&size,NULL,0) != 0) {
+                if (sysctlbyname("hw.ncpu",&nproc,&size,NULL,0) != 0)
+                    nproc = 1;
+            }
+        }
+#elif defined(freebsd_HOST_OS)
+        cpuset_t mask;
+        CPU_ZERO(&mask);
+        if(cpuset_getaffinity(CPU_LEVEL_CPUSET, CPU_WHICH_PID, -1, sizeof(mask), &mask) == 0) {
+            return CPU_COUNT(&mask);
+        } else {
+            size_t size = sizeof(uint32_t);
             if(sysctlbyname("hw.ncpu",&nproc,&size,NULL,0) != 0)
                 nproc = 1;
         }
-#elif defined(freebsd_HOST_OS)
-        size_t size = sizeof(uint32_t);
-        if(sysctlbyname("hw.ncpu",&nproc,&size,NULL,0) != 0)
-            nproc = 1;
+#elif defined(HAVE_SYSCONF) && defined(_SC_NPROCESSORS_ONLN)
+        // N.B. This is the number of physical processors.
+        nproc = sysconf(_SC_NPROCESSORS_ONLN);
+#elif defined(HAVE_SYSCONF) && defined(_SC_NPROCESSORS_CONF)
+        // N.B. This is the number of physical processors.
+        nproc = sysconf(_SC_NPROCESSORS_CONF);
 #else
         nproc = 1;
 #endif


=====================================
rts/win32/OSThreads.c
=====================================
@@ -252,17 +252,6 @@ forkOS_createThread ( HsStablePtr entry )
                            (unsigned*)&pId) == 0);
 }
 
-#if defined(x86_64_HOST_ARCH)
-/* We still support Windows Vista, so we can't depend on it
-   and must manually resolve these. */
-typedef DWORD(WINAPI *GetItemCountProc)(WORD);
-typedef DWORD(WINAPI *GetGroupCountProc)(void);
-typedef BOOL(WINAPI *SetThreadGroupAffinityProc)(HANDLE, const GROUP_AFFINITY*, PGROUP_AFFINITY);
-#if !defined(ALL_PROCESSOR_GROUPS)
-#define ALL_PROCESSOR_GROUPS 0xffff
-#endif
-#endif
-
 void freeThreadingResources (void)
 {
     if (cpuGroupCache)
@@ -310,13 +299,6 @@ getNumberOfProcessorsGroups (void)
 #if defined(x86_64_HOST_ARCH)
     if (!n_groups)
     {
-        /* We still support Windows Vista. Which means we can't rely
-           on the API being available. So we'll have to resolve manually.  */
-        HMODULE kernel = GetModuleHandleW(L"kernel32");
-
-        GetGroupCountProc GetActiveProcessorGroupCount
-          = (GetGroupCountProc)(void*)
-               GetProcAddress(kernel, "GetActiveProcessorGroupCount");
         n_groups = GetActiveProcessorGroupCount();
 
         IF_DEBUG(scheduler, debugBelch("[*] Number of processor groups detected: %u\n", n_groups));
@@ -346,21 +328,10 @@ getProcessorsDistribution (void)
         cpuGroupDistCache = malloc(n_groups * sizeof(uint8_t));
         memset(cpuGroupDistCache, MAXIMUM_PROCESSORS, n_groups * sizeof(uint8_t));
 
-        /* We still support Windows Vista. Which means we can't rely
-        on the API being available. So we'll have to resolve manually.  */
-        HMODULE kernel = GetModuleHandleW(L"kernel32");
-
-        GetItemCountProc  GetActiveProcessorCount
-          = (GetItemCountProc)(void*)
-               GetProcAddress(kernel, "GetActiveProcessorCount");
-
-        if (GetActiveProcessorCount)
+        for (int i = 0; i < n_groups; i++)
         {
-            for (int i = 0; i < n_groups; i++)
-            {
-                cpuGroupDistCache[i] = GetActiveProcessorCount(i);
-                IF_DEBUG(scheduler, debugBelch("[*] Number of active processors in group %u detected: %u\n", i, cpuGroupDistCache[i]));
-            }
+            cpuGroupDistCache[i] = GetActiveProcessorCount(i);
+            IF_DEBUG(scheduler, debugBelch("[*] Number of active processors in group %u detected: %u\n", i, cpuGroupDistCache[i]));
         }
     }
 
@@ -449,14 +420,7 @@ getNumberOfProcessors (void)
     static uint32_t nproc = 0;
 
 #if defined(x86_64_HOST_ARCH)
-    /* We still support Windows Vista. Which means we can't rely
-       on the API being available. So we'll have to resolve manually.  */
-    HMODULE kernel = GetModuleHandleW(L"kernel32");
-
-    GetItemCountProc GetActiveProcessorCount
-      = (GetItemCountProc)(void*)
-          GetProcAddress(kernel, "GetActiveProcessorCount");
-    if (GetActiveProcessorCount && !nproc)
+    if (!nproc)
     {
         nproc = GetActiveProcessorCount(ALL_PROCESSOR_GROUPS);
 
@@ -517,21 +481,11 @@ setThreadAffinity (uint32_t n, uint32_t m) // cap N of M
         mask[group] |= 1 << ix;
     }
 
-#if defined(x86_64_HOST_ARCH)
-    /* We still support Windows Vista. Which means we can't rely
-       on the API being available. So we'll have to resolve manually.  */
-    HMODULE kernel = GetModuleHandleW(L"kernel32");
-
-    SetThreadGroupAffinityProc SetThreadGroupAffinity
-      = (SetThreadGroupAffinityProc)(void*)
-          GetProcAddress(kernel, "SetThreadGroupAffinity");
-#endif
-
     for (i = 0; i < n_groups; i++)
     {
 #if defined(x86_64_HOST_ARCH)
         // If we support the new API, use it.
-        if (mask[i] > 0 && SetThreadGroupAffinity)
+        if (mask[i] > 0)
         {
             GROUP_AFFINITY hGroup;
             ZeroMemory(&hGroup, sizeof(hGroup));


=====================================
testsuite/tests/driver/T16167.hs
=====================================
@@ -0,0 +1 @@
+module f


=====================================
testsuite/tests/driver/T16167.stdout
=====================================
@@ -0,0 +1 @@
+{"span": {"file": "T16167.hs","startLine": 1,"startCol": 8,"endLine": 1,"endCol": 9},"doc": "parse error on input \u2018f\u2019","severity": "SevError","reason": null}


=====================================
testsuite/tests/driver/all.T
=====================================
@@ -261,6 +261,8 @@ test('T12955', normal, makefile_test, [])
 test('T12971', [when(opsys('mingw32'), expect_broken(17945)), ignore_stdout], makefile_test, [])
 test('json', normal, compile_fail, ['-ddump-json'])
 test('json2', normalise_version('base','ghc-prim'), compile, ['-ddump-types -ddump-json'])
+test('T16167', exit_code(1), run_command, 
+     ['{compiler} -x hs -e ":set prog T16167.hs" -ddump-json T16167.hs'])
 test('T13604', [], makefile_test, [])
 test('T13604a', [], makefile_test, [])
 # omitting hpc and profasm because they affect the



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/8332ea70d330e8eb9a085337229f8454ea411e1c...ce8bca8d5388bfb92e6765d3703c20e62d37781c

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/8332ea70d330e8eb9a085337229f8454ea411e1c...ce8bca8d5388bfb92e6765d3703c20e62d37781c
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20200510/b2848a71/attachment-0001.html>


More information about the ghc-commits mailing list