]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libiberty/physmem.c
1 /* Calculate the size of physical memory.
2 Copyright 2000, 2001, 2003 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software Foundation,
16 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
18 /* Written by Paul Eggert and Jim Meyering. */
29 # include <sys/pstat.h>
33 #include <sys/sysmp.h>
36 #include "libiberty.h"
38 /* Return the total amount of physical memory. */
42 #if defined _SC_PHYS_PAGES && defined _SC_PAGESIZE
44 double pages
= sysconf (_SC_PHYS_PAGES
);
45 double pagesize
= sysconf (_SC_PAGESIZE
);
46 if (0 <= pages
&& 0 <= pagesize
)
47 return pages
* pagesize
;
51 #if HAVE_PSTAT_GETSTATIC
52 { /* This works on hpux11. */
53 struct pst_static pss
;
54 if (0 <= pstat_getstatic (&pss
, sizeof pss
, 1, 0))
56 double pages
= pss
.physical_memory
;
57 double pagesize
= pss
.page_size
;
58 if (0 <= pages
&& 0 <= pagesize
)
59 return pages
* pagesize
;
64 #if HAVE_SYSMP && defined MP_SAGET && defined MPSA_RMINFO && defined _SC_PAGESIZE
65 { /* This works on irix6. */
66 struct rminfo realmem
;
67 if (sysmp(MP_SAGET
, MPSA_RMINFO
, &realmem
, sizeof(realmem
)) == 0)
69 double pagesize
= sysconf (_SC_PAGESIZE
);
70 double pages
= realmem
.physmem
;
71 if (0 <= pages
&& 0 <= pagesize
)
72 return pages
* pagesize
;
77 /* Return 0 if we can't determine the value. */
81 /* Return the amount of physical memory available. */
85 #if defined _SC_AVPHYS_PAGES && defined _SC_PAGESIZE
87 double pages
= sysconf (_SC_AVPHYS_PAGES
);
88 double pagesize
= sysconf (_SC_PAGESIZE
);
89 if (0 <= pages
&& 0 <= pagesize
)
90 return pages
* pagesize
;
94 #if HAVE_PSTAT_GETSTATIC && HAVE_PSTAT_GETDYNAMIC
95 { /* This works on hpux11. */
96 struct pst_static pss
;
97 struct pst_dynamic psd
;
98 if (0 <= pstat_getstatic (&pss
, sizeof pss
, 1, 0)
99 && 0 <= pstat_getdynamic (&psd
, sizeof psd
, 1, 0))
101 double pages
= psd
.psd_free
;
102 double pagesize
= pss
.page_size
;
103 if (0 <= pages
&& 0 <= pagesize
)
104 return pages
* pagesize
;
109 #if HAVE_SYSMP && defined MP_SAGET && defined MPSA_RMINFO && defined _SC_PAGESIZE
110 { /* This works on irix6. */
111 struct rminfo realmem
;
112 if (sysmp(MP_SAGET
, MPSA_RMINFO
, &realmem
, sizeof(realmem
)) == 0)
114 double pagesize
= sysconf (_SC_PAGESIZE
);
115 double pages
= realmem
.availrmem
;
116 if (0 <= pages
&& 0 <= pagesize
)
117 return pages
* pagesize
;
122 /* Guess 25% of physical memory. */
123 return physmem_total () / 4;
135 printf ("%12.f %12.f\n", physmem_total (), physmem_available ());
143 compile-command: "gcc -DDEBUG -DHAVE_CONFIG_H -I.. -g -O -Wall -W physmem.c"