public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [libgo] Don't try to use uninitialized semaphores (PR go/48222)
@ 2011-04-04 16:34 Rainer Orth
  2011-04-04 23:44 ` Ian Lance Taylor
  0 siblings, 1 reply; 2+ messages in thread
From: Rainer Orth @ 2011-04-04 16:34 UTC (permalink / raw)
  To: gcc-patches; +Cc: Ian Lance Taylor

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.

diff --git a/libgo/runtime/cpuprof.c b/libgo/runtime/cpuprof.c
--- a/libgo/runtime/cpuprof.c
+++ b/libgo/runtime/cpuprof.c
@@ -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.
diff --git a/libgo/runtime/go-main.c b/libgo/runtime/go-main.c
--- a/libgo/runtime/go-main.c
+++ b/libgo/runtime/go-main.c
@@ -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;
diff --git a/libgo/runtime/malloc.goc b/libgo/runtime/malloc.goc
--- a/libgo/runtime/malloc.goc
+++ b/libgo/runtime/malloc.goc
@@ -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));
 }
diff --git a/libgo/runtime/runtime.h b/libgo/runtime/runtime.h
--- a/libgo/runtime/runtime.h
+++ b/libgo/runtime/runtime.h
@@ -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);
 

-- 
-----------------------------------------------------------------------------
Rainer Orth, Center for Biotechnology, Bielefeld University

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [libgo] Don't try to use uninitialized semaphores (PR go/48222)
  2011-04-04 16:34 [libgo] Don't try to use uninitialized semaphores (PR go/48222) Rainer Orth
@ 2011-04-04 23:44 ` Ian Lance Taylor
  0 siblings, 0 replies; 2+ messages in thread
From: Ian Lance Taylor @ 2011-04-04 23:44 UTC (permalink / raw)
  To: Rainer Orth; +Cc: gcc-patches, gofrontend-dev

Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE> writes:

> 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.

Thanks for tracking this down.  I wonder why I never saw the problem on
GNU/Linux?

I committed your patch.

Ian

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-04-04 23:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-04-04 16:34 [libgo] Don't try to use uninitialized semaphores (PR go/48222) Rainer Orth
2011-04-04 23:44 ` Ian Lance Taylor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).