hurd-mem
authorSamuel Thibault <sthibault@debian.org>
Tue, 3 Mar 2020 11:32:28 +0000 (11:32 +0000)
committerSamuel Thibault <sthibault@debian.org>
Tue, 3 Mar 2020 11:32:28 +0000 (11:32 +0000)
commit ba162341dfe5d1ac55fc1c0a7facf9f0b4e41939
Author: Samuel Thibault <samuel.thibault@ens-lyon.org>
Date:   Wed Jan 1 13:54:22 2020 +0100

    mach: Fix header detection on GNU Mach

Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
commit aaae2bfe787b3733c1fc1b6a5821105c0c8bf7d6
Author: Samuel Thibault <samuel.thibault@ens-lyon.org>
Date:   Wed Jan 1 14:03:26 2020 +0100

    bsd: Make hwloc_get_sysctl able to return 64bit values

Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
commit e93445ab422b2640adcdb7c7daff211cb93a5d1f
Author: Samuel Thibault <samuel.thibault@ens-lyon.org>
Date:   Wed Jan 1 14:28:13 2020 +0100

    local_memory: Factorize and generalize memory size retrieval

Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Gbp-Pq: Name hurd-mem

config/hwloc.m4
hwloc/topology-freebsd.c
hwloc/topology-netbsd.c
hwloc/topology-noos.c
hwloc/topology-windows.c
hwloc/topology.c
include/hwloc/rename.h
include/private/private.h

index 82a7d38480f03361f0dd7ba6f100a7dd86432b7e..930cb00967179fa9718d1576ef2eebf82b69c53c 100644 (file)
@@ -1,7 +1,7 @@
 dnl -*- Autoconf -*-
 dnl
 dnl Copyright © 2009-2019 Inria.  All rights reserved.
-dnl Copyright © 2009-2012, 2015-2017 Université Bordeaux
+dnl Copyright © 2009-2012, 2015-2017, 2020 Université Bordeaux
 dnl Copyright © 2004-2005 The Trustees of Indiana University and Indiana
 dnl                         University Research and Technology
 dnl                         Corporation.  All rights reserved.
@@ -470,14 +470,15 @@ EOF])
                _SC_PAGE_SIZE,
                _SC_LARGE_PAGESIZE],,[:],[[#include <unistd.h>]])
 
-    AC_HAVE_HEADERS([mach/mach_host.h])
-    AC_HAVE_HEADERS([mach/mach_init.h], [
+    AC_HAVE_HEADERS([mach/mach_init.h])
+    AC_HAVE_HEADERS([mach_init.h])
+    AC_HAVE_HEADERS([mach/mach_host.h], [
       AC_CHECK_FUNCS([host_info])
     ])
 
     AC_CHECK_HEADERS([sys/param.h])
     AC_CHECK_HEADERS([sys/sysctl.h], [
-      AC_CHECK_DECLS([CTL_HW, HW_NCPU],,,[[
+      AC_CHECK_DECLS([CTL_HW, HW_NCPU, HW_REALMEM64, HW_MEMSIZE64, HW_PHYSMEM64, HW_USERMEM64, HW_REALMEM, HW_MEMSIZE, HW_PHYSMEM, HW_USERMEM],,,[[
       #if HAVE_SYS_PARAM_H
       #include <sys/param.h>
       #endif
index a4a7147eb3a6b0ece67490479a4918ca99118b57..bbf72f397de98df3623eb9dfe9fe6062c3a4b586 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Copyright © 2009 CNRS
  * Copyright © 2009-2019 Inria.  All rights reserved.
- * Copyright © 2009-2010, 2012 Université Bordeaux
+ * Copyright © 2009-2010, 2012, 2020 Université Bordeaux
  * Copyright © 2011 Cisco Systems, Inc.  All rights reserved.
  * See COPYING in top-level directory.
  */
@@ -164,20 +164,6 @@ hwloc_freebsd_get_thread_cpubind(hwloc_topology_t topology __hwloc_attribute_unu
 #endif
 #endif
 
-#if (defined HAVE_SYSCTL) && (defined HAVE_SYS_SYSCTL_H)
-static void
-hwloc_freebsd_node_meminfo_info(struct hwloc_topology *topology)
-{
-       int mib[2] = { CTL_HW, HW_PHYSMEM };
-       unsigned long physmem;
-       size_t len = sizeof(physmem);
-       sysctl(mib, 2, &physmem, &len, NULL, 0);
-       topology->machine_memory.local_memory = physmem;
-       /* we don't know anything about NUMA nodes in this backend.
-        * let another backend or the core move that memory to the right NUMA node */
-}
-#endif
-
 static int
 hwloc_look_freebsd(struct hwloc_backend *backend, struct hwloc_disc_status *dstatus)
 {
@@ -188,6 +174,7 @@ hwloc_look_freebsd(struct hwloc_backend *backend, struct hwloc_disc_status *dsta
    */
 
   struct hwloc_topology *topology = backend->topology;
+  int64_t memsize;
 
   assert(dstatus->phase == HWLOC_DISC_PHASE_CPU);
 
@@ -202,10 +189,11 @@ hwloc_look_freebsd(struct hwloc_backend *backend, struct hwloc_disc_status *dsta
     hwloc_setup_pu_level(topology, nbprocs);
   }
 
+  memsize = hwloc_fallback_memsize();
+  if (memsize > 0)
+    topology->machine_memory.local_memory = memsize;
+
   /* Add FreeBSD specific information */
-#if (defined HAVE_SYSCTL) && (defined HAVE_SYS_SYSCTL_H)
-  hwloc_freebsd_node_meminfo_info(topology);
-#endif
   hwloc_obj_add_info(topology->levels[0][0], "Backend", "FreeBSD");
   hwloc_add_uname_info(topology, NULL);
   return 0;
index 96921d85a5bf1d46600de7a09f8cbb5a1dfc6a71..0233bb5e121f6253ea85e1a0b25a962863ad4251 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Copyright © 2012 Aleksej Saushev, The NetBSD Foundation
  * Copyright © 2009-2019 Inria.  All rights reserved.
- * Copyright © 2009-2010 Université Bordeaux
+ * Copyright © 2009-2010, 2020 Université Bordeaux
  * Copyright © 2011 Cisco Systems, Inc.  All rights reserved.
  * See COPYING in top-level directory.
  */
@@ -133,18 +133,6 @@ hwloc_netbsd_get_thisthread_cpubind(hwloc_topology_t topology, hwloc_bitmap_t hw
   return hwloc_netbsd_get_thread_cpubind(topology, pthread_self(), hwloc_cpuset, flags);
 }
 
-#if (defined HAVE_SYSCTL) && (defined HAVE_SYS_SYSCTL_H)
-static void
-hwloc_netbsd_node_meminfo_info(struct hwloc_topology *topology)
-{
-  int mib[2] = { CTL_HW, HW_PHYSMEM64 };
-  unsigned long physmem;
-  size_t len = sizeof(physmem);
-  sysctl(mib, 2, &physmem, &len, NULL, 0);
-  topology->machine_memory.local_memory = physmem;
-}
-#endif
-
 static int
 hwloc_look_netbsd(struct hwloc_backend *backend, struct hwloc_disc_status *dstatus)
 {
@@ -155,6 +143,7 @@ hwloc_look_netbsd(struct hwloc_backend *backend, struct hwloc_disc_status *dstat
    */
 
   struct hwloc_topology *topology = backend->topology;
+  int64_t memsize;
 
   assert(dstatus->phase == HWLOC_DISC_PHASE_CPU);
 
@@ -169,10 +158,11 @@ hwloc_look_netbsd(struct hwloc_backend *backend, struct hwloc_disc_status *dstat
     hwloc_setup_pu_level(topology, nbprocs);
   }
 
+  memsize = hwloc_fallback_memsize();
+  if (memsize > 0)
+    topology->machine_memory.local_memory = memsize;;
+
   /* Add NetBSD specific information */
-#if (defined HAVE_SYSCTL) && (defined HAVE_SYS_SYSCTL_H)
-  hwloc_netbsd_node_meminfo_info(topology);
-#endif
   hwloc_obj_add_info(topology->levels[0][0], "Backend", "NetBSD");
   hwloc_add_uname_info(topology, NULL);
   return 0;
index 174b6fd8c26a8cb881d154651ef9b67c378df072..2658750aab9574c46159dffafb6f62e784bf2f0e 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Copyright © 2009 CNRS
  * Copyright © 2009-2019 Inria.  All rights reserved.
- * Copyright © 2009-2012 Université Bordeaux
+ * Copyright © 2009-2012, 2020 Université Bordeaux
  * Copyright © 2009-2011 Cisco Systems, Inc.  All rights reserved.
  * See COPYING in top-level directory.
  */
@@ -20,22 +20,27 @@ hwloc_look_noos(struct hwloc_backend *backend, struct hwloc_disc_status *dstatus
    */
 
   struct hwloc_topology *topology = backend->topology;
-  int nbprocs;
+  int64_t memsize;
 
   assert(dstatus->phase == HWLOC_DISC_PHASE_CPU);
 
-  if (topology->levels[0][0]->cpuset)
-    /* somebody discovered things */
-    return -1;
+  if (!topology->levels[0][0]->cpuset) {
+    int nbprocs;
+    /* Nobody (even the x86 backend) created objects yet, setup basic objects */
 
-  nbprocs = hwloc_fallback_nbprocessors(0);
-  if (nbprocs >= 1)
-    topology->support.discovery->pu = 1;
-  else
-    nbprocs = 1;
+    nbprocs = hwloc_fallback_nbprocessors(0);
+    if (nbprocs >= 1)
+      topology->support.discovery->pu = 1;
+    else
+      nbprocs = 1;
+    hwloc_alloc_root_sets(topology->levels[0][0]);
+    hwloc_setup_pu_level(topology, nbprocs);
+  }
+
+  memsize = hwloc_fallback_memsize();
+  if (memsize > 0)
+    topology->machine_memory.local_memory = memsize;;
 
-  hwloc_alloc_root_sets(topology->levels[0][0]);
-  hwloc_setup_pu_level(topology, nbprocs);
   hwloc_add_uname_info(topology, NULL);
   return 0;
 }
index 22521aa31cb8872d8e4435e9f11b6fac750ad1a3..915d7d8061722afc7c2c9290e9e8eb2d0c7a429a 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Copyright © 2009 CNRS
  * Copyright © 2009-2019 Inria.  All rights reserved.
- * Copyright © 2009-2012 Université Bordeaux
+ * Copyright © 2009-2012, 2020 Université Bordeaux
  * Copyright © 2011 Cisco Systems, Inc.  All rights reserved.
  * See COPYING in top-level directory.
  */
@@ -1199,3 +1199,9 @@ hwloc_fallback_nbprocessors(unsigned flags __hwloc_attribute_unused) {
 
   return n;
 }
+
+int64_t
+hwloc_fallback_memsize(void) {
+  /* Unused */
+  return -1;
+}
index 8d376193b392266f2d60376ff39db5db2b667ab2..6d56ee002046cd56aa7c9072ff0a63bc9293c074 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Copyright © 2009 CNRS
  * Copyright © 2009-2019 Inria.  All rights reserved.
- * Copyright © 2009-2012 Université Bordeaux
+ * Copyright © 2009-2012, 2020 Université Bordeaux
  * Copyright © 2009-2011 Cisco Systems, Inc.  All rights reserved.
  * See COPYING in top-level directory.
  */
@@ -33,6 +33,9 @@
 #ifdef HAVE_MACH_MACH_INIT_H
 #include <mach/mach_init.h>
 #endif
+#ifdef HAVE_MACH_INIT_H
+#include <mach_init.h>
+#endif
 #ifdef HAVE_MACH_MACH_HOST_H
 #include <mach/mach_host.h>
 #endif
@@ -123,15 +126,25 @@ int hwloc_get_sysctlbyname(const char *name, int64_t *ret)
 #endif
 
 #if defined(HAVE_SYSCTL)
-int hwloc_get_sysctl(int name[], unsigned namelen, int *ret)
+int hwloc_get_sysctl(int name[], unsigned namelen, int64_t *ret)
 {
-  int n;
+  union {
+    int32_t i32;
+    int64_t i64;
+  } n;
   size_t size = sizeof(n);
   if (sysctl(name, namelen, &n, &size, NULL, 0))
     return -1;
-  if (size != sizeof(n))
-    return -1;
-  *ret = n;
+  switch (size) {
+    case sizeof(n.i32):
+      *ret = n.i32;
+      break;
+    case sizeof(n.i64):
+      *ret = n.i64;
+      break;
+    default:
+      return -1;
+  }
   return 0;
 }
 #endif
@@ -178,8 +191,10 @@ hwloc_fallback_nbprocessors(unsigned flags) {
   n = nn;
 #elif defined(HAVE_SYSCTL) && HAVE_DECL_CTL_HW && HAVE_DECL_HW_NCPU
   static int name[2] = {CTL_HW, HW_NCPU};
-  if (hwloc_get_sysctl(name, sizeof(name)/sizeof(*name), &n))
+  int64_t nn;
+  if (hwloc_get_sysctl(name, sizeof(name)/sizeof(*name), &nn))
     n = -1;
+  n = nn;
 #else
 #ifdef __GNUC__
 #warning No known way to discover number of available processors on this system
@@ -188,6 +203,46 @@ hwloc_fallback_nbprocessors(unsigned flags) {
 #endif
   return n;
 }
+
+int64_t
+hwloc_fallback_memsize(void) {
+  int64_t size;
+#if defined(HAVE_HOST_INFO) && HAVE_HOST_INFO
+  struct host_basic_info info;
+  mach_msg_type_number_t count = HOST_BASIC_INFO_COUNT;
+  host_info(mach_host_self(), HOST_BASIC_INFO, (integer_t*) &info, &count);
+  size = info.memory_size;
+#elif defined(HAVE_SYSCTL) && HAVE_DECL_CTL_HW && (HAVE_DECL_HW_REALMEM64 || HAVE_DECL_HW_MEMSIZE64 || HAVE_DECL_HW_PHYSMEM64 || HAVE_DECL_HW_USERMEM64 || HAVE_DECL_HW_REALMEM || HAVE_DECL_HW_MEMSIZE || HAVE_DECL_HW_PHYSMEM || HAVE_DECL_HW_USERMEM)
+#if HAVE_DECL_HW_MEMSIZE64
+  static int name[2] = {CTL_HW, HW_MEMSIZE64};
+#elif HAVE_DECL_HW_REALMEM64
+  static int name[2] = {CTL_HW, HW_REALMEM64};
+#elif HAVE_DECL_HW_PHYSMEM64
+  static int name[2] = {CTL_HW, HW_PHYSMEM64};
+#elif HAVE_DECL_HW_USERMEM64
+  static int name[2] = {CTL_HW, HW_USERMEM64};
+#elif HAVE_DECL_HW_MEMSIZE
+  static int name[2] = {CTL_HW, HW_MEMSIZE};
+#elif HAVE_DECL_HW_REALMEM
+  static int name[2] = {CTL_HW, HW_REALMEM};
+#elif HAVE_DECL_HW_PHYSMEM
+  static int name[2] = {CTL_HW, HW_PHYSMEM};
+#elif HAVE_DECL_HW_USERMEM
+  static int name[2] = {CTL_HW, HW_USERMEM};
+#endif
+  if (hwloc_get_sysctl(name, sizeof(name)/sizeof(*name), &size))
+    size = -1;
+#elif defined(HAVE_SYSCTLBYNAME)
+  if (hwloc_get_sysctlbyname("hw.memsize", &size) &&
+      hwloc_get_sysctlbyname("hw.realmem", &size) &&
+      hwloc_get_sysctlbyname("hw.physmem", &size) &&
+      hwloc_get_sysctlbyname("hw.usermem", &size))
+      size = -1;
+#else
+  size = -1;
+#endif
+  return size;
+}
 #endif /* !HWLOC_WIN_SYS */
 
 /*
index a23738d0d6d2ef824baf334d84132dc1d4649baa..0dad63d9300461d72382013ff04c0f9f6a62e035 100644 (file)
@@ -709,6 +709,7 @@ extern "C" {
 #define hwloc_get_sysctlbyname HWLOC_NAME(get_sysctlbyname)
 #define hwloc_get_sysctl HWLOC_NAME(get_sysctl)
 #define hwloc_fallback_nbprocessors HWLOC_NAME(fallback_nbprocessors)
+#define hwloc_fallback_memsize HWLOC_NAME(fallback_memsize)
 
 #define hwloc__object_cpusets_compare_first HWLOC_NAME(_object_cpusets_compare_first)
 #define hwloc__reorder_children HWLOC_NAME(_reorder_children)
index 5f8789376b75ccd3edbabefcf818a40cc979887b..84d95bb3065822128bf16eec0e3ce3b962064ee9 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Copyright © 2009      CNRS
  * Copyright © 2009-2019 Inria.  All rights reserved.
- * Copyright © 2009-2012 Université Bordeaux
+ * Copyright © 2009-2012, 2020 Université Bordeaux
  * Copyright © 2009-2011 Cisco Systems, Inc.  All rights reserved.
  *
  * See COPYING in top-level directory.
@@ -224,11 +224,13 @@ struct hwloc_topology {
 extern void hwloc_alloc_root_sets(hwloc_obj_t root);
 extern void hwloc_setup_pu_level(struct hwloc_topology *topology, unsigned nb_pus);
 extern int hwloc_get_sysctlbyname(const char *name, int64_t *n);
-extern int hwloc_get_sysctl(int name[], unsigned namelen, int *n);
+extern int hwloc_get_sysctl(int name[], unsigned namelen, int64_t *n);
 
 /* returns the number of CPU from the OS (only valid if thissystem) */
 #define HWLOC_FALLBACK_NBPROCESSORS_INCLUDE_OFFLINE 1 /* by default we try to get only the online CPUs */
 extern int hwloc_fallback_nbprocessors(unsigned flags);
+/* returns the memory size from the OS (only valid if thissystem) */
+extern int64_t hwloc_fallback_memsize(void);
 
 extern int hwloc__object_cpusets_compare_first(hwloc_obj_t obj1, hwloc_obj_t obj2);
 extern void hwloc__reorder_children(hwloc_obj_t parent);