Commit c29301d6 by Ian Lance Taylor

Add runtime profiling infrastructure, not yet working.

From-SVN: r171579
parent d253656a
...@@ -423,6 +423,7 @@ runtime_files = \ ...@@ -423,6 +423,7 @@ runtime_files = \
runtime/go-unsafe-newarray.c \ runtime/go-unsafe-newarray.c \
runtime/go-unsafe-pointer.c \ runtime/go-unsafe-pointer.c \
runtime/go-unwind.c \ runtime/go-unwind.c \
runtime/cpuprof.c \
runtime/mcache.c \ runtime/mcache.c \
runtime/mcentral.c \ runtime/mcentral.c \
$(runtime_mem_file) \ $(runtime_mem_file) \
......
...@@ -207,7 +207,7 @@ am__libgo_la_SOURCES_DIST = runtime/go-append.c runtime/go-assert.c \ ...@@ -207,7 +207,7 @@ am__libgo_la_SOURCES_DIST = runtime/go-append.c runtime/go-assert.c \
runtime/go-typestring.c runtime/go-unreflect.c \ runtime/go-typestring.c runtime/go-unreflect.c \
runtime/go-unsafe-new.c runtime/go-unsafe-newarray.c \ runtime/go-unsafe-new.c runtime/go-unsafe-newarray.c \
runtime/go-unsafe-pointer.c runtime/go-unwind.c \ runtime/go-unsafe-pointer.c runtime/go-unwind.c \
runtime/mcache.c runtime/mcentral.c \ runtime/cpuprof.c runtime/mcache.c runtime/mcentral.c \
runtime/mem_posix_memalign.c runtime/mem.c runtime/mfinal.c \ runtime/mem_posix_memalign.c runtime/mem.c runtime/mfinal.c \
runtime/mfixalloc.c runtime/mgc0.c runtime/mheap.c \ runtime/mfixalloc.c runtime/mgc0.c runtime/mheap.c \
runtime/msize.c runtime/proc.c runtime/thread.c \ runtime/msize.c runtime/proc.c runtime/thread.c \
...@@ -240,10 +240,11 @@ am__objects_3 = go-append.lo go-assert.lo go-assert-interface.lo \ ...@@ -240,10 +240,11 @@ am__objects_3 = go-append.lo go-assert.lo go-assert-interface.lo \
go-type-error.lo go-type-identity.lo go-type-interface.lo \ go-type-error.lo go-type-identity.lo go-type-interface.lo \
go-type-string.lo go-typedesc-equal.lo go-typestring.lo \ go-type-string.lo go-typedesc-equal.lo go-typestring.lo \
go-unreflect.lo go-unsafe-new.lo go-unsafe-newarray.lo \ go-unreflect.lo go-unsafe-new.lo go-unsafe-newarray.lo \
go-unsafe-pointer.lo go-unwind.lo mcache.lo mcentral.lo \ go-unsafe-pointer.lo go-unwind.lo cpuprof.lo mcache.lo \
$(am__objects_1) mfinal.lo mfixalloc.lo mgc0.lo mheap.lo \ mcentral.lo $(am__objects_1) mfinal.lo mfixalloc.lo mgc0.lo \
msize.lo proc.lo thread.lo $(am__objects_2) chan.lo iface.lo \ mheap.lo msize.lo proc.lo thread.lo $(am__objects_2) chan.lo \
malloc.lo map.lo mprof.lo reflect.lo sigqueue.lo string.lo iface.lo malloc.lo map.lo mprof.lo reflect.lo sigqueue.lo \
string.lo
am_libgo_la_OBJECTS = $(am__objects_3) am_libgo_la_OBJECTS = $(am__objects_3)
libgo_la_OBJECTS = $(am_libgo_la_OBJECTS) libgo_la_OBJECTS = $(am_libgo_la_OBJECTS)
DEFAULT_INCLUDES = -I.@am__isrc@ DEFAULT_INCLUDES = -I.@am__isrc@
...@@ -836,6 +837,7 @@ runtime_files = \ ...@@ -836,6 +837,7 @@ runtime_files = \
runtime/go-unsafe-newarray.c \ runtime/go-unsafe-newarray.c \
runtime/go-unsafe-pointer.c \ runtime/go-unsafe-pointer.c \
runtime/go-unwind.c \ runtime/go-unwind.c \
runtime/cpuprof.c \
runtime/mcache.c \ runtime/mcache.c \
runtime/mcentral.c \ runtime/mcentral.c \
$(runtime_mem_file) \ $(runtime_mem_file) \
...@@ -2164,6 +2166,7 @@ distclean-compile: ...@@ -2164,6 +2166,7 @@ distclean-compile:
-rm -f *.tab.c -rm -f *.tab.c
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/chan.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/chan.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpuprof.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/go-append.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/go-append.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/go-assert-interface.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/go-assert-interface.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/go-assert.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/go-assert.Plo@am__quote@
...@@ -2836,6 +2839,13 @@ go-unwind.lo: runtime/go-unwind.c ...@@ -2836,6 +2839,13 @@ go-unwind.lo: runtime/go-unwind.c
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o go-unwind.lo `test -f 'runtime/go-unwind.c' || echo '$(srcdir)/'`runtime/go-unwind.c @am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o go-unwind.lo `test -f 'runtime/go-unwind.c' || echo '$(srcdir)/'`runtime/go-unwind.c
cpuprof.lo: runtime/cpuprof.c
@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT cpuprof.lo -MD -MP -MF $(DEPDIR)/cpuprof.Tpo -c -o cpuprof.lo `test -f 'runtime/cpuprof.c' || echo '$(srcdir)/'`runtime/cpuprof.c
@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/cpuprof.Tpo $(DEPDIR)/cpuprof.Plo
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='runtime/cpuprof.c' object='cpuprof.lo' libtool=yes @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o cpuprof.lo `test -f 'runtime/cpuprof.c' || echo '$(srcdir)/'`runtime/cpuprof.c
mcache.lo: runtime/mcache.c mcache.lo: runtime/mcache.c
@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT mcache.lo -MD -MP -MF $(DEPDIR)/mcache.Tpo -c -o mcache.lo `test -f 'runtime/mcache.c' || echo '$(srcdir)/'`runtime/mcache.c @am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT mcache.lo -MD -MP -MF $(DEPDIR)/mcache.Tpo -c -o mcache.lo `test -f 'runtime/mcache.c' || echo '$(srcdir)/'`runtime/mcache.c
@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/mcache.Tpo $(DEPDIR)/mcache.Plo @am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/mcache.Tpo $(DEPDIR)/mcache.Plo
......
...@@ -21,7 +21,7 @@ static pthread_cond_t note_cond = PTHREAD_COND_INITIALIZER; ...@@ -21,7 +21,7 @@ static pthread_cond_t note_cond = PTHREAD_COND_INITIALIZER;
notewakeup. */ notewakeup. */
void void
noteclear (Note* n) runtime_noteclear (Note* n)
{ {
int32 i; int32 i;
...@@ -37,7 +37,7 @@ noteclear (Note* n) ...@@ -37,7 +37,7 @@ noteclear (Note* n)
/* Wait until notewakeup is called. */ /* Wait until notewakeup is called. */
void void
notesleep (Note* n) runtime_notesleep (Note* n)
{ {
int32 i; int32 i;
...@@ -57,7 +57,7 @@ notesleep (Note* n) ...@@ -57,7 +57,7 @@ notesleep (Note* n)
/* Wake up every thread sleeping on the note. */ /* Wake up every thread sleeping on the note. */
void void
notewakeup (Note *n) runtime_notewakeup (Note *n)
{ {
int32 i; int32 i;
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <signal.h> #include <signal.h>
#include <stdlib.h> #include <stdlib.h>
#include <sys/time.h>
#include "go-assert.h" #include "go-assert.h"
#include "go-panic.h" #include "go-panic.h"
...@@ -13,10 +14,8 @@ ...@@ -13,10 +14,8 @@
#include "runtime.h" #include "runtime.h"
#undef int #ifndef SA_RESTART
#define SA_RESTART 0
#ifndef SA_ONSTACK
#define SA_ONSTACK 0
#endif #endif
/* What to do for a signal. */ /* What to do for a signal. */
...@@ -27,68 +26,70 @@ struct sigtab ...@@ -27,68 +26,70 @@ struct sigtab
int sig; int sig;
/* Nonzero if the signal should be ignored. */ /* Nonzero if the signal should be ignored. */
_Bool ignore; _Bool ignore;
/* Nonzero if we should restart system calls. */
_Bool restart;
}; };
/* What to do for signals. */ /* What to do for signals. */
static struct sigtab signals[] = static struct sigtab signals[] =
{ {
{ SIGHUP, 0 }, { SIGHUP, 0, 1 },
{ SIGINT, 0 }, { SIGINT, 0, 1 },
{ SIGALRM, 1 }, { SIGALRM, 1, 1 },
{ SIGTERM, 0 }, { SIGTERM, 0, 1 },
#ifdef SIGBUS #ifdef SIGBUS
{ SIGBUS, 0 }, { SIGBUS, 0, 0 },
#endif #endif
#ifdef SIGFPE #ifdef SIGFPE
{ SIGFPE, 0 }, { SIGFPE, 0, 0 },
#endif #endif
#ifdef SIGUSR1 #ifdef SIGUSR1
{ SIGUSR1, 1 }, { SIGUSR1, 1, 1 },
#endif #endif
#ifdef SIGSEGV #ifdef SIGSEGV
{ SIGSEGV, 0 }, { SIGSEGV, 0, 0 },
#endif #endif
#ifdef SIGUSR2 #ifdef SIGUSR2
{ SIGUSR2, 1 }, { SIGUSR2, 1, 1 },
#endif #endif
#ifdef SIGPIPE #ifdef SIGPIPE
{ SIGPIPE, 1 }, { SIGPIPE, 1, 0 },
#endif #endif
#ifdef SIGCHLD #ifdef SIGCHLD
{ SIGCHLD, 1 }, { SIGCHLD, 1, 1 },
#endif #endif
#ifdef SIGTSTP #ifdef SIGTSTP
{ SIGTSTP, 1 }, { SIGTSTP, 1, 1 },
#endif #endif
#ifdef SIGTTIN #ifdef SIGTTIN
{ SIGTTIN, 1 }, { SIGTTIN, 1, 1 },
#endif #endif
#ifdef SIGTTOU #ifdef SIGTTOU
{ SIGTTOU, 1 }, { SIGTTOU, 1, 1 },
#endif #endif
#ifdef SIGURG #ifdef SIGURG
{ SIGURG, 1 }, { SIGURG, 1, 1 },
#endif #endif
#ifdef SIGXCPU #ifdef SIGXCPU
{ SIGXCPU, 1 }, { SIGXCPU, 1, 1 },
#endif #endif
#ifdef SIGXFSZ #ifdef SIGXFSZ
{ SIGXFSZ, 1 }, { SIGXFSZ, 1, 1 },
#endif #endif
#ifdef SIGVTARLM #ifdef SIGVTARLM
{ SIGVTALRM, 1 }, { SIGVTALRM, 1, 1 },
#endif #endif
#ifdef SIGWINCH #ifdef SIGWINCH
{ SIGWINCH, 1 }, { SIGWINCH, 1, 1 },
#endif #endif
#ifdef SIGIO #ifdef SIGIO
{ SIGIO, 1 }, { SIGIO, 1, 1 },
#endif #endif
#ifdef SIGPWR #ifdef SIGPWR
{ SIGPWR, 1 }, { SIGPWR, 1, 1 },
#endif #endif
{ -1, 0 } { -1, 0, 0 }
}; };
/* The Go signal handler. */ /* The Go signal handler. */
...@@ -99,6 +100,13 @@ sighandler (int sig) ...@@ -99,6 +100,13 @@ sighandler (int sig)
const char *msg; const char *msg;
int i; int i;
if (sig == SIGPROF)
{
/* FIXME. */
runtime_sigprof (0, 0, nil);
return;
}
/* FIXME: Should check siginfo for more information when /* FIXME: Should check siginfo for more information when
available. */ available. */
msg = NULL; msg = NULL;
...@@ -192,6 +200,48 @@ __initsig () ...@@ -192,6 +200,48 @@ __initsig ()
__go_assert (i == 0); __go_assert (i == 0);
for (i = 0; signals[i].sig != -1; ++i) for (i = 0; signals[i].sig != -1; ++i)
if (sigaction (signals[i].sig, &sa, NULL) != 0) {
__go_assert (0); sa.sa_flags = signals[i].restart ? SA_RESTART : 0;
if (sigaction (signals[i].sig, &sa, NULL) != 0)
__go_assert (0);
}
}
void
runtime_resetcpuprofiler(int32 hz)
{
struct itimerval it;
struct sigaction sa;
int i;
memset (&it, 0, sizeof it);
memset (&sa, 0, sizeof sa);
i = sigfillset (&sa.sa_mask);
__go_assert (i == 0);
if (hz == 0)
{
i = setitimer (ITIMER_PROF, &it, NULL);
__go_assert (i == 0);
sa.sa_handler = SIG_IGN;
i = sigaction (SIGPROF, &sa, NULL);
__go_assert (i == 0);
}
else
{
sa.sa_handler = sighandler;
sa.sa_flags = SA_RESTART;
i = sigaction (SIGPROF, &sa, NULL);
__go_assert (i == 0);
it.it_interval.tv_sec = 0;
it.it_interval.tv_usec = 1000000 / hz;
it.it_value = it.it_interval;
i = setitimer (ITIMER_PROF, &it, NULL);
__go_assert (i == 0);
}
m->profilehz = hz;
} }
...@@ -14,3 +14,60 @@ M m0; ...@@ -14,3 +14,60 @@ M m0;
#endif #endif
__thread M *m = &m0; __thread M *m = &m0;
static struct {
Lock;
void (*fn)(uintptr*, int32);
int32 hz;
uintptr pcbuf[100];
} prof;
void
runtime_sigprof(uint8 *pc __attribute__ ((unused)),
uint8 *sp __attribute__ ((unused)),
uint8 *lr __attribute__ ((unused)))
{
int32 n;
if(prof.fn == nil || prof.hz == 0)
return;
runtime_lock(&prof);
if(prof.fn == nil) {
runtime_unlock(&prof);
return;
}
n = 0;
// n = runtime·gentraceback(pc, sp, lr, gp, 0, prof.pcbuf, nelem(prof.pcbuf));
if(n > 0)
prof.fn(prof.pcbuf, n);
runtime_unlock(&prof);
}
void
runtime_setcpuprofilerate(void (*fn)(uintptr*, int32), int32 hz)
{
// Force sane arguments.
if(hz < 0)
hz = 0;
if(hz == 0)
fn = nil;
if(fn == nil)
hz = 0;
// Stop profiler on this cpu so that it is safe to lock prof.
// if a profiling signal came in while we had prof locked,
// it would deadlock.
runtime_resetcpuprofiler(0);
runtime_lock(&prof);
prof.fn = fn;
prof.hz = hz;
runtime_unlock(&prof);
// runtime_lock(&runtime_sched);
// runtime_sched.profilehz = hz;
// runtime_unlock(&runtime_sched);
if(hz != 0)
runtime_resetcpuprofiler(hz);
}
...@@ -102,6 +102,7 @@ struct M ...@@ -102,6 +102,7 @@ struct M
int32 gcing_for_prof; int32 gcing_for_prof;
int32 holds_finlock; int32 holds_finlock;
int32 gcing_for_finlock; int32 gcing_for_finlock;
int32 profilehz;
MCache *mcache; MCache *mcache;
/* For the list of all threads. */ /* For the list of all threads. */
...@@ -163,9 +164,9 @@ void semrelease (uint32 *) asm ("libgo_runtime.runtime.Semrelease"); ...@@ -163,9 +164,9 @@ void semrelease (uint32 *) asm ("libgo_runtime.runtime.Semrelease");
* once notewakeup has been called, all the notesleeps * once notewakeup has been called, all the notesleeps
* will return. future notesleeps will return immediately. * will return. future notesleeps will return immediately.
*/ */
void noteclear(Note*); void runtime_noteclear(Note*);
void notesleep(Note*); void runtime_notesleep(Note*);
void notewakeup(Note*); void runtime_notewakeup(Note*);
/* Functions. */ /* Functions. */
#define runtime_printf printf #define runtime_printf printf
...@@ -187,6 +188,10 @@ void runtime_walkfintab(void (*fn)(void*), void (*scan)(byte *, int64)); ...@@ -187,6 +188,10 @@ void runtime_walkfintab(void (*fn)(void*), void (*scan)(byte *, int64));
#define runtime_cas(pval, old, new) __sync_bool_compare_and_swap (pval, old, new) #define runtime_cas(pval, old, new) __sync_bool_compare_and_swap (pval, old, new)
#define runtime_casp(pval, old, new) __sync_bool_compare_and_swap (pval, old, new) #define runtime_casp(pval, old, new) __sync_bool_compare_and_swap (pval, old, new)
void runtime_sigprof(uint8 *pc, uint8 *sp, uint8 *lr);
void runtime_resetcpuprofiler(int32);
void runtime_setcpuprofilerate(void(*)(uintptr*, int32), int32);
struct __go_func_type; struct __go_func_type;
void reflect_call(const struct __go_func_type *, const void *, _Bool, void **, void reflect_call(const struct __go_func_type *, const void *, _Bool, void **,
void **) void **)
......
...@@ -51,7 +51,7 @@ static struct { ...@@ -51,7 +51,7 @@ static struct {
void void
siginit(void) siginit(void)
{ {
noteclear(&sig); runtime_noteclear(&sig);
} }
// Called from sighandler to send a signal back out of the signal handling thread. // Called from sighandler to send a signal back out of the signal handling thread.
...@@ -71,7 +71,7 @@ __go_sigsend(int32 s) ...@@ -71,7 +71,7 @@ __go_sigsend(int32 s)
// Added to queue. // Added to queue.
// Only send a wakeup for the first signal in each round. // Only send a wakeup for the first signal in each round.
if(mask == 0) if(mask == 0)
notewakeup(&sig); runtime_notewakeup(&sig);
break; break;
} }
} }
...@@ -81,9 +81,9 @@ __go_sigsend(int32 s) ...@@ -81,9 +81,9 @@ __go_sigsend(int32 s)
// Called to receive a bitmask of queued signals. // Called to receive a bitmask of queued signals.
func Sigrecv() (m uint32) { func Sigrecv() (m uint32) {
// runtime·entersyscall(); // runtime·entersyscall();
notesleep(&sig); runtime_notesleep(&sig);
// runtime·exitsyscall(); // runtime·exitsyscall();
noteclear(&sig); runtime_noteclear(&sig);
for(;;) { for(;;) {
m = sig.mask; m = sig.mask;
if(runtime_cas(&sig.mask, m, 0)) if(runtime_cas(&sig.mask, m, 0))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment