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.
_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
/*
* 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.
*/
#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)
{
*/
struct hwloc_topology *topology = backend->topology;
+ int64_t memsize;
assert(dstatus->phase == HWLOC_DISC_PHASE_CPU);
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;
/*
* 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.
*/
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)
{
*/
struct hwloc_topology *topology = backend->topology;
+ int64_t memsize;
assert(dstatus->phase == HWLOC_DISC_PHASE_CPU);
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;
/*
* 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.
*/
*/
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;
}
/*
* 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.
*/
return n;
}
+
+int64_t
+hwloc_fallback_memsize(void) {
+ /* Unused */
+ return -1;
+}
/*
* 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.
*/
#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
#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
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
#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 */
/*
#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)
/*
* 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.
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);