QNX: Fix physical memory detection
authorMatthias von Faber <mvf@gmx.eu>
Fri, 26 Jul 2024 11:56:17 +0000 (13:56 +0200)
committerMatthias von Faber <mvf@gmx.eu>
Fri, 26 Jul 2024 11:56:33 +0000 (13:56 +0200)
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 <mvf@gmx.eu>
os/os-qnx.h

index 447c9957bee32999e0bea7b6fd4a7d0b60ff38c4..8ae9695ec8f79c2ae83c308b21ee2735590e24c6 100755 (executable)
@@ -9,7 +9,7 @@
 #include <sys/statvfs.h>
 #include <sys/ioctl.h>
 #include <sys/utsname.h>
-#include <sys/sysctl.h>
+#include <sys/syspage.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/dcmd_cam.h>
@@ -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;
 }