@@ -114,6 +114,12 @@ static void add(Profile*, uintptr*, int3
static bool evict(Profile*, Entry*);
static bool flushlog(Profile*);
+void
+runtime_cpuprofinit(void)
+{
+ runtime_initlock(&lk);
+}
+
// LostProfileData is a no-op function used in profiles
// to mark the number of profiling stack traces that were
// discarded due to slow data writers.
@@ -48,6 +48,7 @@ main (int argc, char **argv)
struct __go_string *values;
runtime_mallocinit ();
+ runtime_cpuprofinit ();
__go_gc_goroutine_init (&argc);
Args.__count = argc;
@@ -350,6 +350,12 @@ runtime_mallocinit(void)
runtime_MHeap_Init(&runtime_mheap, runtime_SysAlloc);
m->mcache = runtime_allocmcache();
+ // Initialize malloc profiling.
+ runtime_Mprof_Init();
+
+ // Initialize finalizer.
+ runtime_initfintab();
+
// See if it works.
runtime_free(runtime_malloc(1));
}
@@ -189,6 +189,7 @@ void runtime_walkfintab(void (*fn)(void*
#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_cpuprofinit(void);
void runtime_resetcpuprofiler(int32);
void runtime_setcpuprofilerate(void(*)(uintptr*, int32), int32);
After some time with DTrace, I found what caused the intermittend assertion failures in thread.c: /vol/gcc/src/hg/trunk/local/libgo/runtime/thread.c:63: libgo assertion failure /vol/gcc/src/hg/trunk/local/libgo/runtime/thread.c:40: libgo assertion failure It turned out that sem_wait or sem_post was called with an uninitialized semaphore, and always the same one: > fffffd7fc79407a8::whatis fffffd7fc79407a8 is libgo.so.0.0.0`proflock+8, in /vol/gcc/obj/gcc-4.7.0-20110401/11-gcc/i386-pc-solaris2.11/amd64/libgo/.libs/lib go.so.0.0.0 [fffffd7fc7940000,fffffd7fc9978000) Lock proflock is initialized in runtime/mprof.goc (runtime_Mprof_Init), but that is never called. There are two other instances of the same problem: * Lock finlock in mfinal.c, initialized in runtime_initfintab, which again isn't called. * Lock lk in cpuprof.c, which even lacks an initialization function. The following patch fixes all this and makes those random assertion failures go away. Rainer 2011-04-03 Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE> PR go/48222 * runtime/malloc.goc (runtime_mallocinit): Call runtime_Mprof_Init, runtime_initfintab. * runtime/cpuprof.c (runtime_cpuprofinit): New function. * runtime/runtime.h (runtime_cpuprofinit): Declare it. * runtime/go-main.c (main): Use it.