summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorderaadt <deraadt@openbsd.org>1996-06-18 10:07:41 +0000
committerderaadt <deraadt@openbsd.org>1996-06-18 10:07:41 +0000
commit64d71990389d0c49a0f7b6d7ebeca8978261a32c (patch)
tree4f3dc2367b157c19d82c536a4f311dcc8a1dc28b
parentupdate id (diff)
downloadwireguard-openbsd-64d71990389d0c49a0f7b6d7ebeca8978261a32c.tar.xz
wireguard-openbsd-64d71990389d0c49a0f7b6d7ebeca8978261a32c.zip
use p->hashfraction when doing non-time-critical calculations, rather than
using HASHFRACTION directly. in time-critical calculations, if HASHFRACTION is a power of two, check that p->hashfraction == HASHFRACTION and if so do the calculation with the compiled-in value so that the compiler can optimize out (potentially) expensive divisions. if p->hashfraction != HASHFRACTION, actually do the division. This has the result that on machines with slow division, the division can be optimized out of the common case, but that if HASHFRACTION changes from the compiled-in value (for whatever reason), profiling will still work. Changes suggested by Chris Torek.
-rw-r--r--lib/libc/gmon/gmon.c6
-rw-r--r--lib/libc/gmon/mcount.c23
2 files changed, 18 insertions, 11 deletions
diff --git a/lib/libc/gmon/gmon.c b/lib/libc/gmon/gmon.c
index 45b14fd5497..cc7dedf252a 100644
--- a/lib/libc/gmon/gmon.c
+++ b/lib/libc/gmon/gmon.c
@@ -1,4 +1,4 @@
-/* $NetBSD: gmon.c,v 1.5 1995/11/21 22:23:47 jtc Exp $ */
+/* $NetBSD: gmon.c,v 1.5.4.1 1996/06/12 04:20:16 cgd Exp $ */
/*-
* Copyright (c) 1983, 1992, 1993
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)gmon.c 8.1 (Berkeley) 6/4/93";
#else
-static char rcsid[] = "$NetBSD: gmon.c,v 1.5 1995/11/21 22:23:47 jtc Exp $";
+static char rcsid[] = "$NetBSD: gmon.c,v 1.5.4.1 1996/06/12 04:20:16 cgd Exp $";
#endif
#endif
@@ -83,7 +83,7 @@ monstartup(lowpc, highpc)
p->textsize = p->highpc - p->lowpc;
p->kcountsize = p->textsize / HISTFRACTION;
p->hashfraction = HASHFRACTION;
- p->fromssize = p->textsize / HASHFRACTION;
+ p->fromssize = p->textsize / p->hashfraction;
p->tolimit = p->textsize * ARCDENSITY / 100;
if (p->tolimit < MINARCS)
p->tolimit = MINARCS;
diff --git a/lib/libc/gmon/mcount.c b/lib/libc/gmon/mcount.c
index fb8f1ac3f2b..f6c00a53855 100644
--- a/lib/libc/gmon/mcount.c
+++ b/lib/libc/gmon/mcount.c
@@ -1,4 +1,4 @@
-/* $NetBSD: mcount.c,v 1.3 1995/02/27 12:54:42 cgd Exp $ */
+/* $NetBSD: mcount.c,v 1.3.6.2 1996/06/12 04:20:17 cgd Exp $ */
/*-
* Copyright (c) 1983, 1992, 1993
@@ -33,11 +33,11 @@
* SUCH DAMAGE.
*/
-#if !defined(lint) && !defined(KERNEL) && defined(LIBC_SCCS)
+#if !defined(lint) && !defined(_KERNEL) && defined(LIBC_SCCS)
#if 0
static char sccsid[] = "@(#)mcount.c 8.1 (Berkeley) 6/4/93";
#else
-static char rcsid[] = "$NetBSD: mcount.c,v 1.3 1995/02/27 12:54:42 cgd Exp $";
+static char rcsid[] = "$NetBSD: mcount.c,v 1.3.6.2 1996/06/12 04:20:17 cgd Exp $";
#endif
#endif
@@ -66,7 +66,7 @@ _MCOUNT_DECL(frompc, selfpc) /* _mcount; may be static, inline, etc */
register struct tostruct *top, *prevtop;
register struct gmonparam *p;
register long toindex;
-#ifdef KERNEL
+#ifdef _KERNEL
register int s;
#endif
@@ -77,7 +77,7 @@ _MCOUNT_DECL(frompc, selfpc) /* _mcount; may be static, inline, etc */
*/
if (p->state != GMON_PROF_ON)
return;
-#ifdef KERNEL
+#ifdef _KERNEL
MCOUNT_ENTER;
#else
p->state = GMON_PROF_BUSY;
@@ -91,7 +91,14 @@ _MCOUNT_DECL(frompc, selfpc) /* _mcount; may be static, inline, etc */
if (frompc > p->textsize)
goto done;
- frompcindex = &p->froms[frompc / (p->hashfraction * sizeof(*p->froms))];
+#if (HASHFRACTION & (HASHFRACTION - 1)) == 0
+ if (p->hashfraction == HASHFRACTION)
+ frompcindex =
+ &p->froms[frompc / (HASHFRACTION * sizeof(*p->froms))];
+ else
+#endif
+ frompcindex =
+ &p->froms[frompc / (p->hashfraction * sizeof(*p->froms))];
toindex = *frompcindex;
if (toindex == 0) {
/*
@@ -163,7 +170,7 @@ _MCOUNT_DECL(frompc, selfpc) /* _mcount; may be static, inline, etc */
}
done:
-#ifdef KERNEL
+#ifdef _KERNEL
MCOUNT_EXIT;
#else
p->state = GMON_PROF_ON;
@@ -171,7 +178,7 @@ done:
return;
overflow:
p->state = GMON_PROF_ERROR;
-#ifdef KERNEL
+#ifdef _KERNEL
MCOUNT_EXIT;
#endif
return;