From: simonmar Date: Wed, 27 Apr 2005 14:25:18 +0000 (+0000) Subject: [project @ 2005-04-27 14:25:17 by simonmar] X-Git-Tag: Initial_conversion_from_CVS_complete~654 X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=0cc009952787f2112365100a04dc73aa3d0fca67;p=ghc-hetmet.git [project @ 2005-04-27 14:25:17 by simonmar] Hold the sm_mutex around access to the mutable list. The SMP RTS now seems quite stable, I've run my simple test program with 64 threads without crashes. --- diff --git a/ghc/rts/OSThreads.h b/ghc/includes/OSThreads.h similarity index 86% rename from ghc/rts/OSThreads.h rename to ghc/includes/OSThreads.h index 0ba6fb9..a065f7a 100644 --- a/ghc/rts/OSThreads.h +++ b/ghc/includes/OSThreads.h @@ -4,11 +4,12 @@ * * Accessing OS threads functionality in a (mostly) OS-independent * manner. - * * * --------------------------------------------------------------------------*/ + #ifndef __OSTHREADS_H__ #define __OSTHREADS_H__ + #if defined(RTS_SUPPORTS_THREADS) /* to the end */ # if defined(HAVE_PTHREAD_H) && !defined(WANT_NATIVE_WIN32_THREADS) @@ -21,8 +22,12 @@ typedef pthread_t OSThreadId; #define INIT_COND_VAR PTHREAD_COND_INITIALIZER #ifdef LOCK_DEBUG -#define ACQUIRE_LOCK(mutex) debugBelch("ACQUIRE_LOCK(0x%p) %s %d\n", mutex,__FILE__,__LINE__); pthread_mutex_lock(mutex) -#define RELEASE_LOCK(mutex) debugBelch("RELEASE_LOCK(0x%p) %s %d\n", mutex,__FILE__,__LINE__); pthread_mutex_unlock(mutex) +#define ACQUIRE_LOCK(mutex) \ + debugBelch("ACQUIRE_LOCK(0x%p) %s %d\n", mutex,__FILE__,__LINE__); \ + pthread_mutex_lock(mutex) +#define RELEASE_LOCK(mutex) \ + debugBelch("RELEASE_LOCK(0x%p) %s %d\n", mutex,__FILE__,__LINE__); \ + pthread_mutex_unlock(mutex) #else #define ACQUIRE_LOCK(mutex) pthread_mutex_lock(mutex) #define RELEASE_LOCK(mutex) pthread_mutex_unlock(mutex) @@ -31,8 +36,6 @@ typedef pthread_t OSThreadId; # elif defined(HAVE_WINDOWS_H) #include -#include "RtsUtils.h" - typedef HANDLE Condition; typedef HANDLE Mutex; typedef DWORD OSThreadId; @@ -40,7 +43,7 @@ typedef DWORD OSThreadId; #define INIT_MUTEX_VAR 0 #define INIT_COND_VAR 0 -static inline void +INLINE_HEADER void ACQUIRE_LOCK(Mutex *mutex) { if (WaitForSingleObject(*mutex,INFINITE) == WAIT_FAILED) { @@ -48,7 +51,7 @@ ACQUIRE_LOCK(Mutex *mutex) } } -static inline void +INLINE_HEADER void RELEASE_LOCK(Mutex *mutex) { if (ReleaseMutex(*mutex) == 0) { diff --git a/ghc/includes/Storage.h b/ghc/includes/Storage.h index 4404dfa..69ddef6 100644 --- a/ghc/includes/Storage.h +++ b/ghc/includes/Storage.h @@ -10,6 +10,7 @@ #define STORAGE_H #include +#include "OSThreads.h" /* ----------------------------------------------------------------------------- * Generational GC @@ -187,10 +188,18 @@ extern void GarbageCollect(void (*get_roots)(evac_fn),rtsBool force_major_gc); -------------------------------------------------------------------------- */ -/* ToDo: shouldn't recordMutable acquire some - * kind of lock in the SMP case? Or do we need per-processor - * mutable lists? +/* + * Storage manager mutex */ +#if defined(SMP) +extern Mutex sm_mutex; +#define ACQUIRE_SM_LOCK ACQUIRE_LOCK(&sm_mutex); +#define RELEASE_SM_LOCK RELEASE_LOCK(&sm_mutex); +#else +#define ACQUIRE_SM_LOCK +#define RELEASE_SM_LOCK +#endif + INLINE_HEADER void recordMutableGen(StgClosure *p, generation *gen) { @@ -205,6 +214,15 @@ recordMutableGen(StgClosure *p, generation *gen) gen->mut_list = bd; } *bd->free++ = (StgWord)p; + +} + +INLINE_HEADER void +recordMutableGenLock(StgClosure *p, generation *gen) +{ + ACQUIRE_SM_LOCK; + recordMutableGen(p,gen); + RELEASE_SM_LOCK; } INLINE_HEADER void @@ -216,6 +234,14 @@ recordMutable(StgClosure *p) if (bd->gen_no > 0) recordMutableGen(p, &RTS_DEREF(generations)[bd->gen_no]); } +INLINE_HEADER void +recordMutableLock(StgClosure *p) +{ + ACQUIRE_SM_LOCK; + recordMutable(p); + RELEASE_SM_LOCK; +} + /* ----------------------------------------------------------------------------- The CAF table - used to let us revert CAFs in GHCi -------------------------------------------------------------------------- */ diff --git a/ghc/includes/Updates.h b/ghc/includes/Updates.h index a748a37..514f1da 100644 --- a/ghc/includes/Updates.h +++ b/ghc/includes/Updates.h @@ -256,7 +256,7 @@ DEBUG_FILL_SLOP(StgClosure *p) and_then; \ } else { \ DEBUG_FILL_SLOP(p1); \ - foreign "C" recordMutableGen(p1 "ptr", \ + foreign "C" recordMutableGenLock(p1 "ptr", \ generation(TO_W_(bdescr_gen_no(bd))) "ptr"); \ StgInd_indirectee(p1) = p2; \ SET_INFO(p1, stg_IND_OLDGEN_info); \ @@ -280,7 +280,7 @@ DEBUG_FILL_SLOP(StgClosure *p) and_then; \ } else { \ DEBUG_FILL_SLOP(p1); \ - recordMutableGen(p1, &generations[bd->gen_no]); \ + recordMutableGenLock(p1, &generations[bd->gen_no]); \ ((StgInd *)p1)->indirectee = p2; \ SET_INFO(p1, &stg_IND_OLDGEN_info); \ TICK_UPD_OLD_IND(); \ @@ -319,7 +319,7 @@ updateWithPermIndirection(StgClosure *p1, LDV_RECORD_CREATE(p1); TICK_UPD_NEW_PERM_IND(p1); } else { - recordMutableGen(p1, &generations[bd->gen_no]); + recordMutableGenLock(p1, &generations[bd->gen_no]); ((StgInd *)p1)->indirectee = p2; SET_INFO(p1, &stg_IND_OLDGEN_PERM_info); /* diff --git a/ghc/rts/Makefile b/ghc/rts/Makefile index 29b2f9a..b564849 100644 --- a/ghc/rts/Makefile +++ b/ghc/rts/Makefile @@ -318,7 +318,6 @@ SRC_HC_OPTS += \ -\#include ProfHeap.h \ -\#include LdvProfile.h \ -\#include Profiling.h \ - -\#include StoragePriv.h \ -\#include OSThreads.h \ -\#include Apply.h diff --git a/ghc/rts/PrimOps.cmm b/ghc/rts/PrimOps.cmm index cfdaca6..ff1b442 100644 --- a/ghc/rts/PrimOps.cmm +++ b/ghc/rts/PrimOps.cmm @@ -135,7 +135,7 @@ unsafeThawArrayzh_fast // maintains this invariant. // if (%INFO_TYPE(%GET_STD_INFO(R1)) != HALF_W_(MUT_ARR_PTRS_FROZEN0)) { - foreign "C" recordMutable(R1 "ptr"); + foreign "C" recordMutableLock(R1 "ptr"); } SET_INFO(R1,stg_MUT_ARR_PTRS_info); diff --git a/ghc/rts/Storage.c b/ghc/rts/Storage.c index 9298c15..536d8b7 100644 --- a/ghc/rts/Storage.c +++ b/ghc/rts/Storage.c @@ -22,7 +22,6 @@ #include "Storage.h" #include "Schedule.h" #include "RetainerProfile.h" // for counting memory blocks (memInventory) -#include "StoragePriv.h" #include #include diff --git a/ghc/rts/StoragePriv.h b/ghc/rts/StoragePriv.h deleted file mode 100644 index 678370b..0000000 --- a/ghc/rts/StoragePriv.h +++ /dev/null @@ -1,24 +0,0 @@ -/* ----------------------------------------------------------------------------- - * - * (c) The GHC Team, 1998-2005 - * - * Storage manager bits visible to the rest of the RTS only - * - * ---------------------------------------------------------------------------*/ - -#ifndef STORAGEPRIV_H -#define STORAGEPRIV_H - -/* - * Storage manager mutex - */ -#if defined(SMP) -extern Mutex sm_mutex; -#define ACQUIRE_SM_LOCK ACQUIRE_LOCK(&sm_mutex) -#define RELEASE_SM_LOCK RELEASE_LOCK(&sm_mutex) -#else -#define ACQUIRE_SM_LOCK -#define RELEASE_SM_LOCK -#endif - -#endif /* STORAGEPRIV_H */