]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libgomp: call numa_available first when using libnuma
authorTobias Burnus <tobias@codesourcery.com>
Thu, 17 Aug 2023 13:20:55 +0000 (15:20 +0200)
committerTobias Burnus <tobias@codesourcery.com>
Thu, 17 Aug 2023 13:20:55 +0000 (15:20 +0200)
The documentation requires that numa_available() is called and only
when successful, other libnuma function may be called. Internally,
it does a syscall to get_mempolicy with flag=0 (which would return
the default policy if mode were not NULL). If this returns -1 (and
not 0) and errno == ENOSYS, the Linux kernel does not have the
get_mempolicy syscall function; if so, numa_available() returns -1
(otherwise: 0).

libgomp/

PR libgomp/111024
* allocator.c (gomp_init_libnuma): Call numa_available; if
not available or not returning 0, disable libnuma usage.

libgomp/allocator.c

index 90f2dcb60d64b97d68a8280d58cc82587ba5370a..b4e50e2ad72a72513d21b65648c27a5ff249b481 100644 (file)
@@ -118,6 +118,17 @@ gomp_init_libnuma (void)
        dlclose (handle);
       return;
     }
+  if (handle)
+    {
+      int (*numa_available) (void);
+      numa_available
+       = (__typeof (numa_available)) dlsym (handle, "numa_available");
+      if (!numa_available || numa_available () != 0)
+       {
+         dlclose (handle);
+         handle = NULL;
+       }
+    }
   if (!handle)
     {
       __atomic_store_n (&libnuma_data, data, MEMMODEL_RELEASE);