[project @ 2005-04-22 12:28:00 by simonmar]
authorsimonmar <unknown>
Fri, 22 Apr 2005 12:28:01 +0000 (12:28 +0000)
committersimonmar <unknown>
Fri, 22 Apr 2005 12:28:01 +0000 (12:28 +0000)
- 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
ghc/includes/Constants.h
ghc/includes/STM.h
ghc/includes/TSO.h
ghc/rts/Makefile
ghc/rts/PrimOps.cmm
ghc/rts/Storage.c
ghc/rts/StoragePriv.h [new file with mode: 0644]
ghc/rts/Timer.h

index e4f44d6..09320a0 100644 (file)
     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 */
index e98f25f..ab73b9b 100644 (file)
 #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 */
index 45723d7..6b65b0e 100644 (file)
@@ -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
 
 /*----------------------------------------------------------------------*/
 
index 098ec4c..ce1d29c 100644 (file)
@@ -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 */
index 934c429..29b2f9a 100644 (file)
@@ -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"
index 3ddb2bc..42ae582 100644 (file)
@@ -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);
 }
index 00ed711..b2878c2 100644 (file)
@@ -22,6 +22,7 @@
 #include "Storage.h"
 #include "Schedule.h"
 #include "RetainerProfile.h"   // for counting memory blocks (memInventory)
+#include "StoragePriv.h"
 
 #include <stdlib.h>
 #include <string.h>
@@ -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 (file)
index 0000000..678370b
--- /dev/null
@@ -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 */
index 1c4696e..4ec480d 100644 (file)
@@ -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