parameterize max proc id
[unix-history] / usr / src / sys / kern / subr_prof.c
index 566df54..460616f 100644 (file)
@@ -1,15 +1,17 @@
 /*
  * Copyright (c) 1982, 1986 Regents of the University of California.
 /*
  * Copyright (c) 1982, 1986 Regents of the University of California.
- * All rights reserved.  The Berkeley software License Agreement
- * specifies the terms and conditions for redistribution.
+ * All rights reserved.
  *
  *
- *     @(#)subr_prof.c 7.2 (Berkeley) %G%
+ * %sccs.include.redist.c%
+ *
+ *     @(#)subr_prof.c 7.9 (Berkeley) %G%
  */
 
 #ifdef GPROF
 #include "gprof.h"
 #include "param.h"
 #include "systm.h"
  */
 
 #ifdef GPROF
 #include "gprof.h"
 #include "param.h"
 #include "systm.h"
+#include "malloc.h"
 
 /*
  * Froms is actually a bunch of unsigned shorts indexing tos
 
 /*
  * Froms is actually a bunch of unsigned shorts indexing tos
@@ -18,12 +20,7 @@ int  profiling = 3;
 u_short        *froms;
 struct tostruct *tos = 0;
 long   tolimit = 0;
 u_short        *froms;
 struct tostruct *tos = 0;
 long   tolimit = 0;
-#if defined(vax)
-char   *s_lowpc = (char *)0x80000000;
-#endif
-#if defined(tahoe)
-char   *s_lowpc = (char *)0xc0000000;
-#endif
+char   *s_lowpc = (char *)KERNBASE;
 extern char etext;
 char   *s_highpc = &etext;
 u_long s_textsize = 0;
 extern char etext;
 char   *s_highpc = &etext;
 u_long s_textsize = 0;
@@ -47,46 +44,50 @@ kmstartup()
        printf("Profiling kernel, s_textsize=%d [%x..%x]\n",
                s_textsize, s_lowpc, s_highpc);
        ssiz = (s_textsize / HISTFRACTION) + sizeof (struct phdr);
        printf("Profiling kernel, s_textsize=%d [%x..%x]\n",
                s_textsize, s_lowpc, s_highpc);
        ssiz = (s_textsize / HISTFRACTION) + sizeof (struct phdr);
-       sbuf = (u_short *)calloc(ssiz);
+       sbuf = (u_short *)malloc(ssiz, M_GPROF, M_WAITOK);
        if (sbuf == 0) {
                printf("No space for monitor buffer(s)\n");
                return;
        }
        if (sbuf == 0) {
                printf("No space for monitor buffer(s)\n");
                return;
        }
+       bzero(sbuf, ssiz);
        fromssize = s_textsize / HASHFRACTION;
        fromssize = s_textsize / HASHFRACTION;
-       froms = (u_short *)calloc(fromssize);
+       froms = (u_short *)malloc(fromssize, M_GPROF, M_WAITOK);
        if (froms == 0) {
                printf("No space for monitor buffer(s)\n");
        if (froms == 0) {
                printf("No space for monitor buffer(s)\n");
-               cfreemem(sbuf, ssiz);
+               free(sbuf, M_GPROF);
                sbuf = 0;
                return;
        }
                sbuf = 0;
                return;
        }
+       bzero(froms, fromssize);
        tolimit = s_textsize * ARCDENSITY / 100;
        if (tolimit < MINARCS)
                tolimit = MINARCS;
        else if (tolimit > (0xffff - 1))
                tolimit = 0xffff - 1;
        tossize = tolimit * sizeof (struct tostruct);
        tolimit = s_textsize * ARCDENSITY / 100;
        if (tolimit < MINARCS)
                tolimit = MINARCS;
        else if (tolimit > (0xffff - 1))
                tolimit = 0xffff - 1;
        tossize = tolimit * sizeof (struct tostruct);
-       tos = (struct tostruct *)calloc(tossize);
+       tos = (struct tostruct *)malloc(tossize, M_GPROF, M_WAITOK);
        if (tos == 0) {
                printf("No space for monitor buffer(s)\n");
        if (tos == 0) {
                printf("No space for monitor buffer(s)\n");
-               cfreemem(sbuf, ssiz), sbuf = 0;
-               cfreemem(froms, fromssize), froms = 0;
+               free(sbuf, M_GPROF), sbuf = 0;
+               free(froms, M_GPROF), froms = 0;
                return;
        }
                return;
        }
+       bzero(tos, tossize);
        tos[0].link = 0;
        ((struct phdr *)sbuf)->lpc = s_lowpc;
        ((struct phdr *)sbuf)->hpc = s_highpc;
        ((struct phdr *)sbuf)->ncnt = ssiz;
        kcount = (u_short *)(((int)sbuf) + sizeof (struct phdr));
        tos[0].link = 0;
        ((struct phdr *)sbuf)->lpc = s_lowpc;
        ((struct phdr *)sbuf)->hpc = s_highpc;
        ((struct phdr *)sbuf)->ncnt = ssiz;
        kcount = (u_short *)(((int)sbuf) + sizeof (struct phdr));
-#ifdef notdef
-       /*
-        * Profiling is what mcount checks to see if
-        * all the data structures are ready!!!
-        */
-       profiling = 0;          /* patch by hand when you're ready */
-#endif
 }
 
 }
 
+/*
+ * Special, non-profiled versions
+ */
+#if defined(hp300) && !defined(__GNUC__)
+#define splhigh        _splhigh
+#define splx   _splx
+#endif
+
 /*
  * This routine is massaged so that it may be jsb'ed to on vax.
  */
 /*
  * This routine is massaged so that it may be jsb'ed to on vax.
  */
@@ -115,24 +116,56 @@ mcount()
 #ifdef lint
        selfpc = (char *)0;
        frompcindex = 0;
 #ifdef lint
        selfpc = (char *)0;
        frompcindex = 0;
+#else
+       ;                               /* avoid label botch */
+#ifdef __GNUC__
+#if defined(vax)
+       Fix Me!!
+#endif
+#if defined(tahoe)
+       Fix Me!!
+#endif
+#if defined(hp300)
+       /*
+        * selfpc = pc pushed by mcount jsr,
+        * frompcindex = pc pushed by jsr into self.
+        * In GCC the caller's stack frame has already been built so we
+        * have to chase a6 to find caller's raddr.  This assumes that all
+        * routines we are profiling were built with GCC and that all
+        * profiled routines use link/unlk.
+        */
+       asm("movl a6@(4),%0" : "=r" (selfpc));
+       asm("movl a6@(0)@(4),%0" : "=r" (frompcindex));
+#endif
 #else
 #if defined(vax)
        asm("   movl (sp), r11");       /* selfpc = ... (jsb frame) */
        asm("   movl 16(fp), r10");     /* frompcindex =     (calls frame) */
 #endif
 #if defined(tahoe)
 #else
 #if defined(vax)
        asm("   movl (sp), r11");       /* selfpc = ... (jsb frame) */
        asm("   movl 16(fp), r10");     /* frompcindex =     (calls frame) */
 #endif
 #if defined(tahoe)
-       ;                               /* avoid label botch */
        asm("   movl -8(fp),r12");      /* selfpc = callf frame */
        asm("   movl (fp),r11");
        asm("   movl -8(r11),r11");     /* frompcindex = 1 callf frame back */
 #endif
        asm("   movl -8(fp),r12");      /* selfpc = callf frame */
        asm("   movl (fp),r11");
        asm("   movl -8(r11),r11");     /* frompcindex = 1 callf frame back */
 #endif
+#if defined(hp300)
+       asm("   .text");                /* make sure we're in text space */
+       asm("   movl a6@(4),a5");       /* selfpc = pc pushed by mcount jsr */
+       asm("   movl a6@(8),a4");       /* frompcindex = pc pushed by jsr into
+                                          self, stack frame not yet built */
 #endif
 #endif
+#endif /* not __GNUC__ */
+#endif /* not lint */
        /*
         * Insure that we cannot be recursively invoked.
         * this requires that splhigh() and splx() below
         * do NOT call mcount!
         */
        /*
         * Insure that we cannot be recursively invoked.
         * this requires that splhigh() and splx() below
         * do NOT call mcount!
         */
+#if defined(hp300) && defined(__GNUC__)
+       asm("movw       sr,%0" : "=g" (s));
+       asm("movw       #0x2700,sr");
+#else
        s = splhigh();
        s = splhigh();
+#endif
        /*
         * Check that frompcindex is a reasonable pc value.
         * For example: signal catchers get called from the stack,
        /*
         * Check that frompcindex is a reasonable pc value.
         * For example: signal catchers get called from the stack,
@@ -210,7 +243,11 @@ mcount()
 
        }
 done:
 
        }
 done:
+#if defined(hp300) && defined(__GNUC__)
+       asm("movw       %0,sr" : : "g" (s));
+#else
        splx(s);
        splx(s);
+#endif
        /* and fall through */
 out:
 #if defined(vax)
        /* and fall through */
 out:
 #if defined(vax)