aboutsummaryrefslogtreecommitdiff
path: root/libiberty/physmem.c
diff options
context:
space:
mode:
authorDJ Delorie <dj@redhat.com>2003-02-21 22:12:51 +0000
committerDJ Delorie <dj@redhat.com>2003-02-21 22:12:51 +0000
commit192cbe66da32ca3c98fbb862fe47804e5e3204f3 (patch)
treebc42b4c97c3983da8e8ac7dd4886d01557cf5f66 /libiberty/physmem.c
parent1bbd6057d5fcd0f7d1cfa12e3536a4040ded0ed7 (diff)
downloadgdb-192cbe66da32ca3c98fbb862fe47804e5e3204f3.zip
gdb-192cbe66da32ca3c98fbb862fe47804e5e3204f3.tar.gz
gdb-192cbe66da32ca3c98fbb862fe47804e5e3204f3.tar.bz2
merge from gcc
Diffstat (limited to 'libiberty/physmem.c')
-rw-r--r--libiberty/physmem.c100
1 files changed, 96 insertions, 4 deletions
diff --git a/libiberty/physmem.c b/libiberty/physmem.c
index 6954261..2011f02 100644
--- a/libiberty/physmem.c
+++ b/libiberty/physmem.c
@@ -1,5 +1,5 @@
/* Calculate the size of physical memory.
- Copyright 2000, 2001 Free Software Foundation, Inc.
+ Copyright 2000, 2001, 2003 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
along with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
-/* Written by Paul Eggert. */
+/* Written by Paul Eggert and Jim Meyering. */
#if HAVE_CONFIG_H
# include <config.h>
@@ -29,6 +29,21 @@
# include <sys/pstat.h>
#endif
+#if HAVE_SYS_SYSMP_H
+#include <sys/sysmp.h>
+#endif
+
+#if HAVE_SYS_SYSINFO_H && HAVE_MACHINE_HAL_SYSINFO_H
+# include <sys/sysinfo.h>
+# include <machine/hal_sysinfo.h>
+#endif
+
+#if HAVE_SYS_TABLE_H
+# include <sys/table.h>
+#endif
+
+#include "libiberty.h"
+
/* Return the total amount of physical memory. */
double
physmem_total ()
@@ -43,7 +58,7 @@ physmem_total ()
#endif
#if HAVE_PSTAT_GETSTATIC
- {
+ { /* This works on hpux11. */
struct pst_static pss;
if (0 <= pstat_getstatic (&pss, sizeof pss, 1, 0))
{
@@ -55,6 +70,34 @@ physmem_total ()
}
#endif
+#if HAVE_SYSMP && defined MP_SAGET && defined MPSA_RMINFO && defined _SC_PAGESIZE
+ { /* This works on irix6. */
+ struct rminfo realmem;
+ if (sysmp(MP_SAGET, MPSA_RMINFO, &realmem, sizeof(realmem)) == 0)
+ {
+ double pagesize = sysconf (_SC_PAGESIZE);
+ double pages = realmem.physmem;
+ if (0 <= pages && 0 <= pagesize)
+ return pages * pagesize;
+ }
+ }
+#endif
+
+#if HAVE_GETSYSINFO
+ { /* This works on Tru64 UNIX V4/5. */
+ int physmem;
+
+ if (getsysinfo (GSI_PHYSMEM, (caddr_t) &physmem, sizeof (physmem),
+ NULL, NULL, NULL) == 1)
+ {
+ double kbytes = physmem;
+
+ if (0 <= kbytes)
+ return kbytes * 1024.0;
+ }
+ }
+#endif
+
/* Return 0 if we can't determine the value. */
return 0;
}
@@ -73,7 +116,7 @@ physmem_available ()
#endif
#if HAVE_PSTAT_GETSTATIC && HAVE_PSTAT_GETDYNAMIC
- {
+ { /* This works on hpux11. */
struct pst_static pss;
struct pst_dynamic psd;
if (0 <= pstat_getstatic (&pss, sizeof pss, 1, 0)
@@ -87,6 +130,55 @@ physmem_available ()
}
#endif
+#if HAVE_SYSMP && defined MP_SAGET && defined MPSA_RMINFO && defined _SC_PAGESIZE
+ { /* This works on irix6. */
+ struct rminfo realmem;
+ if (sysmp(MP_SAGET, MPSA_RMINFO, &realmem, sizeof(realmem)) == 0)
+ {
+ double pagesize = sysconf (_SC_PAGESIZE);
+ double pages = realmem.availrmem;
+ if (0 <= pages && 0 <= pagesize)
+ return pages * pagesize;
+ }
+ }
+#endif
+
+#if HAVE_TABLE && HAVE_SYS_TABLE_H
+ { /* This works on Tru64 UNIX V4/5. */
+ struct tbl_vmstats vmstats;
+
+ if (table (TBL_VMSTATS, 0, &vmstats, 1, sizeof (vmstats)) == 1)
+ {
+ double pages = vmstats.free_count;
+ double pagesize = vmstats.pagesize;
+
+ if (0 <= pages && 0 <= pagesize)
+ return pages * pagesize;
+ }
+ }
+#endif
+
/* Guess 25% of physical memory. */
return physmem_total () / 4;
}
+
+
+#if DEBUG
+
+# include <stdio.h>
+# include <stdlib.h>
+
+int
+main ()
+{
+ printf ("%12.f %12.f\n", physmem_total (), physmem_available ());
+ exit (0);
+}
+
+#endif /* DEBUG */
+
+/*
+Local Variables:
+compile-command: "gcc -DDEBUG -DHAVE_CONFIG_H -I.. -g -O -Wall -W physmem.c"
+End:
+*/