diff mbox

[xf86-video-intel] sna: Use a more portable way to determine total RAM size

Message ID 1364327453-22572-1-git-send-email-mark.kettenis@xs4all.nl (mailing list archive)
State New, archived
Headers show

Commit Message

Mark Kettenis March 26, 2013, 7:50 p.m. UTC
From: Mark Kettenis <kettenis@openbsd.org>

The sysinfo function is Linux-specific.  sysconf(_SC_PHYS_PAGES), while
not truly portable, is available on many more systems, including Linux,
Solaris, NetBSD, FreeBSD and OpenBSD.  So use that instead.  Verified
that this results in the same value as the sysinfo call on a handful of
Linux systems.

Signed-off-by: Mark Kettenis <kettenis@openbsd.org>
---
 configure.ac   |  1 -
 src/sna/kgem.c | 14 ++++----------
 2 files changed, 4 insertions(+), 11 deletions(-)

Comments

Chris Wilson March 26, 2013, 8:20 p.m. UTC | #1
On Tue, Mar 26, 2013 at 08:50:53PM +0100, Mark Kettenis wrote:
> From: Mark Kettenis <kettenis@openbsd.org>
> 
> The sysinfo function is Linux-specific.  sysconf(_SC_PHYS_PAGES), while
> not truly portable, is available on many more systems, including Linux,
> Solaris, NetBSD, FreeBSD and OpenBSD.  So use that instead.  Verified
> that this results in the same value as the sysinfo call on a handful of
> Linux systems.

I bikeshedded slightly, as I could not see a compelling reason to
completely replace the current code - I know it currently works.

Thanks for the patch, pushed.
-Chris
diff mbox

Patch

diff --git a/configure.ac b/configure.ac
index de3990d..88e2c80 100644
--- a/configure.ac
+++ b/configure.ac
@@ -200,7 +200,6 @@  AC_ARG_ENABLE(sna,
 	      [SNA="$enableval"],
 	      [SNA=auto])
 
-AC_CHECK_HEADERS([sys/sysinfo.h], , SNA=no)
 if test "x$SNA" = "xauto" && pkg-config --exists "xorg-server >= 1.10"; then
 	SNA=yes
 fi
diff --git a/src/sna/kgem.c b/src/sna/kgem.c
index c6ed114..20f774a 100644
--- a/src/sna/kgem.c
+++ b/src/sna/kgem.c
@@ -46,10 +46,6 @@ 
 #include <memcheck.h>
 #endif
 
-#if HAVE_SYS_SYSINFO_H
-#include <sys/sysinfo.h>
-#endif
-
 static struct kgem_bo *
 search_linear_cache(struct kgem *kgem, unsigned int num_pages, unsigned flags);
 
@@ -641,13 +637,11 @@  agp_aperture_size(struct pci_device *dev, unsigned gen)
 static size_t
 total_ram_size(void)
 {
-#if HAVE_SYS_SYSINFO_H
-	struct sysinfo info;
-	if (sysinfo(&info) == 0)
-		return info.totalram * info.mem_unit;
-#endif
-
+#ifdef _SC_PHYS_PAGES
+	return sysconf(_SC_PHYS_PAGES) * sysconf(_SC_PAGE_SIZE);
+#else
 	return 0;
+#endif
 }
 
 static size_t