This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Patch: *bsd & darwin support in libiberty/physmem.c
- From: "Kaveh R. Ghazi" <ghazi at caip dot rutgers dot edu>
- To: gcc-patches at gcc dot gnu dot org
- Cc: apinski at apple dot com, dj at redhat dot com, kparz at iastate dot edu, pfeifer at dbai dot tuwien dot ac dot at, rearnsha at arm dot com, toa at pop dot agri dot ch
- Date: Fri, 21 Feb 2003 18:11:58 -0500 (EST)
- Subject: Re: Patch: *bsd & darwin support in libiberty/physmem.c
> It applies cleanly against the current gcc trunk's libiberty. (I
> made an update for irix6 earlier today.)
This one applies cleanly after Rainer's install. Try it instead,
thanks.
2003-02-21 Kaveh R. Ghazi <ghazi at caip dot rutgers dot edu>
* configure.in: Check for sys/sysctl.h and sysctl.
* physmem.c: Add support for *bsd and darwin.
diff -rup orig/egcc-CVS20030221/libiberty/configure.in egcc-CVS20030221/libiberty/configure.in
--- orig/egcc-CVS20030221/libiberty/configure.in 2003-02-21 17:29:45.000000000 -0500
+++ egcc-CVS20030221/libiberty/configure.in 2003-02-21 18:03:06.222604236 -0500
@@ -142,7 +142,7 @@ AC_SUBST_FILE(host_makefile_frag)
# It's OK to check for header files. Although the compiler may not be
# able to link anything, it had better be able to at least compile
# something.
-AC_CHECK_HEADERS(sys/file.h sys/param.h limits.h stdlib.h string.h unistd.h strings.h sys/time.h time.h sys/resource.h sys/stat.h sys/mman.h fcntl.h alloca.h sys/pstat.h sys/sysmp.h sys/sysinfo.h machine/hal_sysinfo.h sys/table.h)
+AC_CHECK_HEADERS(sys/file.h sys/param.h limits.h stdlib.h string.h unistd.h strings.h sys/time.h time.h sys/resource.h sys/stat.h sys/mman.h fcntl.h alloca.h sys/pstat.h sys/sysmp.h sys/sysinfo.h machine/hal_sysinfo.h sys/table.h sys/sysctl.h)
AC_HEADER_SYS_WAIT
AC_HEADER_TIME
@@ -208,7 +208,7 @@ vars="sys_errlist sys_nerr sys_siglist"
checkfuncs="getrusage on_exit psignal strerror strsignal sysconf times sbrk gettimeofday"
checkfuncs="$checkfuncs realpath canonicalize_file_name pstat_getstatic pstat_getdynamic sysmp"
-checkfuncs="$checkfuncs getsysinfo table"
+checkfuncs="$checkfuncs getsysinfo table sysctl"
# These are neither executed nor required, but they help keep
# autoheader happy without adding a bunch of text to acconfig.h.
@@ -220,7 +220,7 @@ if test "x" = "y"; then
AC_CHECK_FUNCS(strtod strtol strtoul tmpnam vasprintf vfprintf vprintf)
AC_CHECK_FUNCS(vsprintf waitpid getrusage on_exit psignal strerror strsignal)
AC_CHECK_FUNCS(sysconf times sbrk gettimeofday ffs)
- AC_CHECK_FUNCS(pstat_getstatic pstat_getdynamic sysmp getsysinfo table)
+ AC_CHECK_FUNCS(pstat_getstatic pstat_getdynamic sysmp getsysinfo table sysctl)
AC_CHECK_FUNCS(realpath canonicalize_file_name)
AC_DEFINE(HAVE_SYS_ERRLIST, 1, [Define if you have the sys_errlist variable.])
AC_DEFINE(HAVE_SYS_NERR, 1, [Define if you have the sys_nerr variable.])
diff -rup orig/egcc-CVS20030221/libiberty/physmem.c egcc-CVS20030221/libiberty/physmem.c
--- orig/egcc-CVS20030221/libiberty/physmem.c 2003-02-21 17:29:46.000000000 -0500
+++ egcc-CVS20030221/libiberty/physmem.c 2003-02-21 18:01:12.137803608 -0500
@@ -42,6 +42,16 @@
# include <sys/table.h>
#endif
+#include <sys/types.h>
+
+#if HAVE_SYS_PARAM_H
+#include <sys/param.h>
+#endif
+
+#if HAVE_SYS_SYSCTL_H
+#include <sys/sysctl.h>
+#endif
+
#include "libiberty.h"
/* Return the total amount of physical memory. */
@@ -98,6 +108,21 @@ physmem_total ()
}
#endif
+#if HAVE_SYSCTL && defined HW_PHYSMEM && defined HW_PAGESIZE
+ { /* This works on *bsd and darwin. */
+ unsigned int physmem, pagesize;
+ size_t len = sizeof(pagesize);
+ int mib[2] = {CTL_HW, HW_PAGESIZE};
+
+ if (sysctl(mib, ARRAY_SIZE(mib), &pagesize, &len, NULL, 0) == 0)
+ {
+ mib[1] = HW_PHYSMEM;
+ if (sysctl(mib, ARRAY_SIZE(mib), &physmem, &len, NULL, 0) == 0)
+ return (double)physmem * pagesize;
+ }
+ }
+#endif
+
/* Return 0 if we can't determine the value. */
return 0;
}
@@ -158,6 +183,21 @@ physmem_available ()
}
#endif
+#if HAVE_SYSCTL && defined HW_USERMEM && defined HW_PAGESIZE
+ { /* This works on *bsd and darwin. */
+ unsigned int usermem, pagesize;
+ size_t len = sizeof(pagesize);
+ int mib[2] = {CTL_HW, HW_PAGESIZE};
+
+ if (sysctl(mib, ARRAY_SIZE(mib), &pagesize, &len, NULL, 0) == 0)
+ {
+ mib[1] = HW_USERMEM;
+ if (sysctl(mib, ARRAY_SIZE(mib), &usermem, &len, NULL, 0) == 0)
+ return (double)usermem * pagesize;
+ }
+ }
+#endif
+
/* Guess 25% of physical memory. */
return physmem_total () / 4;
}