From dc10b18c714179c01a542972832c13f779d0997a Mon Sep 17 00:00:00 2001 From: Matthias von Faber Date: Fri, 26 Jul 2024 13:56:17 +0200 Subject: [PATCH] QNX: Fix physical memory detection On QNX 7.1, this was returning an uninitialized value due to failing sysctl. Use the accumulated size of all "ram" areas from the asinfo array in the syspage instead. Also fixes build on QNX 8.0. Signed-off-by: Matthias von Faber --- os/os-qnx.h | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/os/os-qnx.h b/os/os-qnx.h index 447c9957be..8ae9695ec8 100755 --- a/os/os-qnx.h +++ b/os/os-qnx.h @@ -9,7 +9,7 @@ #include #include #include -#include +#include #include #include #include @@ -71,11 +71,17 @@ static inline int blockdev_invalidate_cache(struct fio_file *f) static inline unsigned long long os_phys_mem(void) { - int mib[2] = { CTL_HW, HW_PHYSMEM64 }; - uint64_t mem; - size_t len = sizeof(mem); + uint64_t mem = 0; + const char *const strings = SYSPAGE_ENTRY(strings)->data; + const struct asinfo_entry *const begin = SYSPAGE_ENTRY(asinfo); + const struct asinfo_entry *const end = begin + SYSPAGE_ENTRY_SIZE(asinfo) / SYSPAGE_ELEMENT_SIZE(asinfo); - sysctl(mib, 2, &mem, &len, NULL, 0); + assert(SYSPAGE_ELEMENT_SIZE(asinfo) == sizeof(struct asinfo_entry)); + + for (const struct asinfo_entry *e = begin; e < end; ++e) { + if (!strcmp(strings + e->name, "ram")) + mem += e->end - e->start + 1; + } return mem; }