From ec0984a97cec59d0403ae1f23e23f100666e8148 Mon Sep 17 00:00:00 2001 From: simonmar Date: Fri, 22 Apr 2005 12:28:01 +0000 Subject: [PATCH] [project @ 2005-04-22 12:28:00 by simonmar] - Now that labels are always prefixed with '&' in .hc code, we have to fix some sloppiness in the RTS .cmm code. Fortunately it's not too painful. - SMP: acquire/release the storage manager lock around atomicModifyMutVar#. This is a hack: atomicModifyMutVar# isn't atomic under SMP otherwise, but the SM lock is a large sledgehammer. I think I'll apply the sledgehammer to the MVar primitives too, for the time being. --- ghc/includes/Cmm.h | 6 ++++++ ghc/includes/Constants.h | 6 ++++++ ghc/includes/STM.h | 5 +++++ ghc/includes/TSO.h | 4 ++++ ghc/rts/Makefile | 2 ++ ghc/rts/PrimOps.cmm | 24 ++++++++++++++++-------- ghc/rts/Storage.c | 13 +------------ ghc/rts/StoragePriv.h | 24 ++++++++++++++++++++++++ ghc/rts/Timer.h | 1 - 9 files changed, 64 insertions(+), 21 deletions(-) create mode 100644 ghc/rts/StoragePriv.h diff --git a/ghc/includes/Cmm.h b/ghc/includes/Cmm.h index e4f44d6..09320a0 100644 --- a/ghc/includes/Cmm.h +++ b/ghc/includes/Cmm.h @@ -505,4 +505,10 @@ TICK_BUMP(ALLOC_HEAP_ctr); \ TICK_BUMP_BY(ALLOC_HEAP_tot,n) +/* ----------------------------------------------------------------------------- + Misc junk + -------------------------------------------------------------------------- */ + +#define TICK_MILLISECS (1000/TICK_FREQUENCY) /* ms per tick */ + #endif /* CMM_H */ diff --git a/ghc/includes/Constants.h b/ghc/includes/Constants.h index e98f25f..ab73b9b 100644 --- a/ghc/includes/Constants.h +++ b/ghc/includes/Constants.h @@ -266,4 +266,10 @@ #error RESERVED_STACK_WORDS may be wrong! #endif +/* ----------------------------------------------------------------------------- + How often our context-switch timer ticks + -------------------------------------------------------------------------- */ + +#define TICK_FREQUENCY 50 /* ticks per second */ + #endif /* CONSTANTS_H */ diff --git a/ghc/includes/STM.h b/ghc/includes/STM.h index 45723d7..6b65b0e 100644 --- a/ghc/includes/STM.h +++ b/ghc/includes/STM.h @@ -227,7 +227,12 @@ extern void stmWriteTVar(StgTRecHeader *trec, #define END_STM_WAIT_QUEUE ((StgTVarWaitQueue *)(void *)&stg_END_STM_WAIT_QUEUE_closure) #define END_STM_CHUNK_LIST ((StgTRecChunk *)(void *)&stg_END_STM_CHUNK_LIST_closure) + +#if IN_STG_CODE +#define NO_TREC (stg_NO_TREC_closure) +#else #define NO_TREC ((StgTRecHeader *)(void *)&stg_NO_TREC_closure) +#endif /*----------------------------------------------------------------------*/ diff --git a/ghc/includes/TSO.h b/ghc/includes/TSO.h index 098ec4c..ce1d29c 100644 --- a/ghc/includes/TSO.h +++ b/ghc/includes/TSO.h @@ -240,7 +240,11 @@ extern StgTSO dummy_tso; /* this is the NIL ptr for a TSO queue (e.g. runnable queue) */ +#if IN_STG_CODE +#define END_TSO_QUEUE (stg_END_TSO_QUEUE_closure) +#else #define END_TSO_QUEUE ((StgTSO *)(void*)&stg_END_TSO_QUEUE_closure) +#endif #if defined(PAR) || defined(GRAN) /* this is the NIL ptr for a blocking queue */ diff --git a/ghc/rts/Makefile b/ghc/rts/Makefile index 934c429..29b2f9a 100644 --- a/ghc/rts/Makefile +++ b/ghc/rts/Makefile @@ -318,6 +318,8 @@ SRC_HC_OPTS += \ -\#include ProfHeap.h \ -\#include LdvProfile.h \ -\#include Profiling.h \ + -\#include StoragePriv.h \ + -\#include OSThreads.h \ -\#include Apply.h ifeq "$(Windows)" "YES" diff --git a/ghc/rts/PrimOps.cmm b/ghc/rts/PrimOps.cmm index 3ddb2bc..42ae582 100644 --- a/ghc/rts/PrimOps.cmm +++ b/ghc/rts/PrimOps.cmm @@ -166,6 +166,10 @@ atomicModifyMutVarzh_fast W_ mv, z, x, y, r; /* Args: R1 :: MutVar#, R2 :: a -> (a,b) */ +#if defined(SMP) + foreign "C" ACQUIRE_LOCK(sm_mutex "ptr"); +#endif + /* If x is the current contents of the MutVar#, then We want to make the new contents point to @@ -183,18 +187,18 @@ atomicModifyMutVarzh_fast */ #if MIN_UPD_SIZE > 1 -#define THUNK_1_SIZE (SIZEOF_StgHeader + WDS(MIN_UPD_SIZE)) +#define THUNK_1_SIZE (SIZEOF_StgThunkHeader + WDS(MIN_UPD_SIZE)) #define TICK_ALLOC_THUNK_1() TICK_ALLOC_UP_THK(WDS(1),WDS(MIN_UPD_SIZE-1)) #else -#define THUNK_1_SIZE (SIZEOF_StgHeader + WDS(1)) +#define THUNK_1_SIZE (SIZEOF_StgThunkHeader + WDS(1)) #define TICK_ALLOC_THUNK_1() TICK_ALLOC_UP_THK(WDS(1),0) #endif #if MIN_UPD_SIZE > 2 -#define THUNK_2_SIZE (SIZEOF_StgHeader + WDS(MIN_UPD_SIZE)) +#define THUNK_2_SIZE (SIZEOF_StgThunkHeader + WDS(MIN_UPD_SIZE)) #define TICK_ALLOC_THUNK_2() TICK_ALLOC_UP_THK(WDS(2),WDS(MIN_UPD_SIZE-2)) #else -#define THUNK_2_SIZE (SIZEOF_StgHeader + WDS(2)) +#define THUNK_2_SIZE (SIZEOF_StgThunkHeader + WDS(2)) #define TICK_ALLOC_THUNK_2() TICK_ALLOC_UP_THK(WDS(2),0) #endif @@ -209,15 +213,15 @@ atomicModifyMutVarzh_fast z = Hp - THUNK_2_SIZE + WDS(1); SET_HDR(z, stg_ap_2_upd_info, W_[CCCS]); LDV_RECORD_CREATE(z); - StgClosure_payload(z,0) = R2; - StgClosure_payload(z,1) = x; + StgThunk_payload(z,0) = R2; + StgThunk_payload(z,1) = x; TICK_ALLOC_THUNK_1(); CCCS_ALLOC(THUNK_1_SIZE); y = z - THUNK_1_SIZE; SET_HDR(y, stg_sel_0_upd_info, W_[CCCS]); LDV_RECORD_CREATE(y); - StgClosure_payload(y,0) = z; + StgThunk_payload(y,0) = z; StgMutVar_var(R1) = y; @@ -226,7 +230,11 @@ atomicModifyMutVarzh_fast r = y - THUNK_1_SIZE; SET_HDR(r, stg_sel_1_upd_info, W_[CCCS]); LDV_RECORD_CREATE(r); - StgClosure_payload(r,0) = z; + StgThunk_payload(r,0) = z; + +#if defined(SMP) + foreign "C" RELEASE_LOCK(sm_mutex "ptr"); +#endif RET_P(r); } diff --git a/ghc/rts/Storage.c b/ghc/rts/Storage.c index 00ed711..b2878c2 100644 --- a/ghc/rts/Storage.c +++ b/ghc/rts/Storage.c @@ -22,6 +22,7 @@ #include "Storage.h" #include "Schedule.h" #include "RetainerProfile.h" // for counting memory blocks (memInventory) +#include "StoragePriv.h" #include #include @@ -63,18 +64,6 @@ static void *stgAllocForGMP (size_t size_in_bytes); static void *stgReallocForGMP (void *ptr, size_t old_size, size_t new_size); static void stgDeallocForGMP (void *ptr, size_t size); -/* - * 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 - static void initStep (step *stp, int g, int s) { diff --git a/ghc/rts/StoragePriv.h b/ghc/rts/StoragePriv.h new file mode 100644 index 0000000..678370b --- /dev/null +++ b/ghc/rts/StoragePriv.h @@ -0,0 +1,24 @@ +/* ----------------------------------------------------------------------------- + * + * (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 */ diff --git a/ghc/rts/Timer.h b/ghc/rts/Timer.h index 1c4696e..4ec480d 100644 --- a/ghc/rts/Timer.h +++ b/ghc/rts/Timer.h @@ -8,7 +8,6 @@ #ifndef __TIMER_H__ #define __TIMER_H__ -# define TICK_FREQUENCY 50 /* ticks per second */ # define TICK_MILLISECS (1000/TICK_FREQUENCY) /* ms per tick */ /* Context switch timing constants. Context switches happen after a -- 1.7.10.4