This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Speeding up ggc-simple on stage1
On Jan 16, 2000, Richard Henderson <rth@cygnus.com> wrote:
> On Sat, Jan 15, 2000 at 11:00:50PM -0200, Alexandre Oliva wrote:
>> But attacking the hot spots is precisely what I'm doing. ggc-simple
>> seems to be just too slow.
> I've just remembered something. This is AIX 4.1 you're
> working on right? It has mmap. What it doesn't do is
> pass the normal can-we-force-map-anywhere default test
> that autoconf uses.
Here's a patch for gcc that allows it to use AIX 4.1's mmap.
If it makes it to the next snapshot, I'll finally be able to complete
a bootstrap on gcc 2.96.* on that poor powerpc. It's amazingly,
brutally, almost impossibly faster! Thanks for the suggestions!
Ok to install?
Index: gcc/aclocal.m4
===================================================================
RCS file: /cvs/gcc/egcs/gcc/aclocal.m4,v
retrieving revision 1.19
diff -u -r1.19 aclocal.m4
--- gcc/aclocal.m4 2000/01/13 00:37:05 1.19
+++ gcc/aclocal.m4 2000/01/16 16:19:33
@@ -680,3 +680,85 @@
fi
AC_SUBST($1)dnl
])
+
+# Check whether mmap can map an arbitrary page from /dev/zero, without
+# MAP_FIXED. AC_FUNC_MMAP requires MAP_FIXED to work.
+AC_DEFUN([AC_FUNC_MMAP_ZERO],
+[AC_CHECK_HEADERS(unistd.h)
+AC_CHECK_FUNCS(getpagesize)
+AC_CACHE_CHECK(for working mmap from /dev/zero, ac_cv_func_mmap_zero,
+[AC_TRY_RUN([
+/* Test by Richard Henderson and Alexandre Oliva.
+ Check whether mmap from /dev/zero works. */
+#include <sys/types.h>
+#include <fcntl.h>
+#include <sys/mman.h>
+
+/* This mess was copied from the GNU getpagesize.h. */
+#ifndef HAVE_GETPAGESIZE
+# ifdef HAVE_UNISTD_H
+# include <unistd.h>
+# endif
+
+/* Assume that all systems that can run configure have sys/param.h. */
+# ifndef HAVE_SYS_PARAM_H
+# define HAVE_SYS_PARAM_H 1
+# endif
+
+# ifdef _SC_PAGESIZE
+# define getpagesize() sysconf(_SC_PAGESIZE)
+# else /* no _SC_PAGESIZE */
+# ifdef HAVE_SYS_PARAM_H
+# include <sys/param.h>
+# ifdef EXEC_PAGESIZE
+# define getpagesize() EXEC_PAGESIZE
+# else /* no EXEC_PAGESIZE */
+# ifdef NBPG
+# define getpagesize() NBPG * CLSIZE
+# ifndef CLSIZE
+# define CLSIZE 1
+# endif /* no CLSIZE */
+# else /* no NBPG */
+# ifdef NBPC
+# define getpagesize() NBPC
+# else /* no NBPC */
+# ifdef PAGESIZE
+# define getpagesize() PAGESIZE
+# endif /* PAGESIZE */
+# endif /* no NBPC */
+# endif /* no NBPG */
+# endif /* no EXEC_PAGESIZE */
+# else /* no HAVE_SYS_PARAM_H */
+# define getpagesize() 8192 /* punt totally */
+# endif /* no HAVE_SYS_PARAM_H */
+# endif /* no _SC_PAGESIZE */
+
+#endif /* no HAVE_GETPAGESIZE */
+
+int main()
+{
+ char *x;
+ int fd, pg;
+
+ fd = open("/dev/zero", O_RDWR);
+ if (fd < 0)
+ exit(1);
+
+ pg = getpagesize();
+ x = (char*)mmap(0, pg, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0);
+ if (x == (char *) -1)
+ exit(2);
+
+ *(int *)x += 1;
+
+ if (munmap(x, pg) < 0)
+ exit(3);
+
+ exit(0);
+}], ac_cv_func_mmap_zero=yes, ac_cv_func_mmap_zero=no,
+ac_cv_func_mmap_zero=no)])
+if test $ac_cv_func_mmap_zero = yes; then
+ AC_DEFINE(HAVE_MMAP_ZERO, 1,
+ [Define if mmap can get us zeroed pages from /dev/zero.])
+fi
+])
Index: gcc/configure.in
===================================================================
RCS file: /cvs/gcc/egcs/gcc/configure.in,v
retrieving revision 1.324
diff -u -r1.324 configure.in
--- gcc/configure.in 2000/01/13 15:36:24 1.324
+++ gcc/configure.in 2000/01/16 16:19:33
@@ -405,7 +405,7 @@
;;
esac
AC_FUNC_VFORK
-AC_FUNC_MMAP
+AC_FUNC_MMAP_ZERO
GCC_NEED_DECLARATIONS(bcopy bzero bcmp \
index rindex getenv atol sbrk abort atof strerror getcwd getwd \
@@ -4578,9 +4578,8 @@
AC_MSG_ERROR([$withval is an invalid option to --with-gc])
;;
esac],
-[if test $ac_cv_func_mmap_fixed_mapped = yes; then
- GGC=ggc-page
-elif test $ac_cv_func_valloc = yes; then
+[if test $ac_cv_func_mmap_zero = yes \
+ || test $ac_cv_func_valloc = yes; then
GGC=ggc-page
else
GGC=ggc-simple
Index: gcc/ggc-page.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/ggc-page.c,v
retrieving revision 1.18
diff -u -r1.18 ggc-page.c
--- gcc/ggc-page.c 1999/12/26 23:06:54 1.18
+++ gcc/ggc-page.c 2000/01/16 16:19:33
@@ -1,5 +1,5 @@
/* "Bag-of-pages" garbage collector for the GNU compiler.
- Copyright (C) 1999 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2000 Free Software Foundation, Inc.
This file is part of GNU CC.
@@ -27,7 +27,7 @@
#include "flags.h"
#include "ggc.h"
-#ifdef HAVE_MMAP
+#ifdef HAVE_MMAP_ZERO
#include <sys/mman.h>
#endif
@@ -229,7 +229,7 @@
unsigned char context_depth;
/* A file descriptor open to /dev/zero for reading. */
-#if defined (HAVE_MMAP) && !defined(MAP_ANONYMOUS)
+#if defined (HAVE_MMAP_ZERO) && !defined(MAP_ANONYMOUS)
int dev_zero_fd;
#endif
@@ -408,7 +408,7 @@
{
char *page;
-#ifdef HAVE_MMAP
+#ifdef HAVE_MMAP_ZERO
#ifdef MAP_ANONYMOUS
page = (char *) mmap (pref, size, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
@@ -430,7 +430,7 @@
exit(1);
}
#endif /* HAVE_VALLOC */
-#endif /* HAVE_MMAP */
+#endif /* HAVE_MMAP_ZERO */
/* Remember that we allocated this memory. */
G.bytes_mapped += size;
@@ -533,7 +533,7 @@
static void
release_pages ()
{
-#ifdef HAVE_MMAP
+#ifdef HAVE_MMAP_ZERO
page_entry *p, *next;
char *start;
size_t len;
@@ -579,7 +579,7 @@
free (p);
}
#endif /* HAVE_VALLOC */
-#endif /* HAVE_MMAP */
+#endif /* HAVE_MMAP_ZERO */
G.free_pages = NULL;
}
@@ -794,7 +794,7 @@
G.pagesize = getpagesize();
G.lg_pagesize = exact_log2 (G.pagesize);
-#if defined (HAVE_MMAP) && !defined(MAP_ANONYMOUS)
+#if defined (HAVE_MMAP_ZERO) && !defined(MAP_ANONYMOUS)
G.dev_zero_fd = open ("/dev/zero", O_RDONLY);
if (G.dev_zero_fd == -1)
abort ();
@@ -808,7 +808,7 @@
G.allocated_last_gc = GGC_MIN_LAST_ALLOCATED;
-#ifdef HAVE_MMAP
+#ifdef HAVE_MMAP_ZERO
/* StunOS has an amazing off-by-one error for the first mmap allocation
after fiddling with RLIMIT_STACK. The result, as hard as it is to
believe, is an unaligned page allocation, which would cause us to
--
Alexandre Oliva http://www.ic.unicamp.br/~oliva IC-Unicamp, Bra[sz]il
oliva@{lsd.ic.unicamp.br,guarana.{org,com}} aoliva@{acm,computer}.org
oliva@{gnu.org,kaffe.org,{egcs,sourceware}.cygnus.com,samba.org}
** I may forward mail about projects to mailing lists; please use them