From: Samuel Thibault Date: Wed, 1 Jan 2020 14:01:22 +0000 (+0000) Subject: hurd-mem X-Git-Tag: archive/raspbian/2.1.0+dfsg-3+rpi1^2~1 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=2d069466d1bc591a1b64229c50c6c380be15b01d;p=hwloc.git hurd-mem commit ba162341dfe5d1ac55fc1c0a7facf9f0b4e41939 Author: Samuel Thibault Date: Wed Jan 1 13:54:22 2020 +0100 mach: Fix header detection on GNU Mach Signed-off-by: Samuel Thibault commit aaae2bfe787b3733c1fc1b6a5821105c0c8bf7d6 Author: Samuel Thibault Date: Wed Jan 1 14:03:26 2020 +0100 bsd: Make hwloc_get_sysctl able to return 64bit values Signed-off-by: Samuel Thibault commit e93445ab422b2640adcdb7c7daff211cb93a5d1f Author: Samuel Thibault Date: Wed Jan 1 14:28:13 2020 +0100 local_memory: Factorize and generalize memory size retrieval Signed-off-by: Samuel Thibault Gbp-Pq: Name hurd-mem --- diff --git a/config/hwloc.m4 b/config/hwloc.m4 index 82a7d38..930cb00 100644 --- a/config/hwloc.m4 +++ b/config/hwloc.m4 @@ -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 ]]) - 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 #endif diff --git a/hwloc/topology-freebsd.c b/hwloc/topology-freebsd.c index a4a7147..bbf72f3 100644 --- a/hwloc/topology-freebsd.c +++ b/hwloc/topology-freebsd.c @@ -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; diff --git a/hwloc/topology-netbsd.c b/hwloc/topology-netbsd.c index 96921d8..0233bb5 100644 --- a/hwloc/topology-netbsd.c +++ b/hwloc/topology-netbsd.c @@ -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; diff --git a/hwloc/topology-noos.c b/hwloc/topology-noos.c index 174b6fd..2658750 100644 --- a/hwloc/topology-noos.c +++ b/hwloc/topology-noos.c @@ -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; } diff --git a/hwloc/topology-windows.c b/hwloc/topology-windows.c index 22521aa..915d7d8 100644 --- a/hwloc/topology-windows.c +++ b/hwloc/topology-windows.c @@ -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; +} diff --git a/hwloc/topology.c b/hwloc/topology.c index 8d37619..6d56ee0 100644 --- a/hwloc/topology.c +++ b/hwloc/topology.c @@ -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 #endif +#ifdef HAVE_MACH_INIT_H +#include +#endif #ifdef HAVE_MACH_MACH_HOST_H #include #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 */ /* diff --git a/include/hwloc/rename.h b/include/hwloc/rename.h index a23738d..0dad63d 100644 --- a/include/hwloc/rename.h +++ b/include/hwloc/rename.h @@ -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) diff --git a/include/private/private.h b/include/private/private.h index 5f87893..84d95bb 100644 --- a/include/private/private.h +++ b/include/private/private.h @@ -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);