All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mark Kettenis <mark.kettenis@xs4all.nl>
To: intel-gfx@lists.freedesktop.org
Cc: Mark Kettenis <kettenis@openbsd.org>
Subject: [PATCH xf86-video-intel] sna: Use a more portable way to determine total RAM size
Date: Tue, 26 Mar 2013 20:50:53 +0100	[thread overview]
Message-ID: <1364327453-22572-1-git-send-email-mark.kettenis@xs4all.nl> (raw)

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(-)

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
-- 
1.8.1.2

             reply	other threads:[~2013-03-26 19:50 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-26 19:50 Mark Kettenis [this message]
2013-03-26 20:20 ` [PATCH xf86-video-intel] sna: Use a more portable way to determine total RAM size Chris Wilson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1364327453-22572-1-git-send-email-mark.kettenis@xs4all.nl \
    --to=mark.kettenis@xs4all.nl \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=kettenis@openbsd.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.