Statically ping memory from the nearest memory controller on the cores
authorjzhou <jzhou>
Thu, 1 Jul 2010 03:10:31 +0000 (03:10 +0000)
committerjzhou <jzhou>
Thu, 1 Jul 2010 03:10:31 +0000 (03:10 +0000)
Robust/src/Runtime/GCSharedHash.c
Robust/src/Runtime/GCSharedHash.h
Robust/src/Runtime/multicoregarbage.c
Robust/src/Runtime/multicoregarbage.h
Robust/src/Runtime/multicoretask.c

index c56a1da49f247586d70c0820fb868a2b817471de..c6437ab18cb50cd086825797016431ea6a9b8001 100755 (executable)
 #define INLINE    inline __attribute__((always_inline))
 #endif // #ifndef INLINE
 
+// TODO check the average collision times
+//int gc_num_search = 0;
+//int gc_num_collision = 0;
+
 /* GCSHARED HASH ********************************************************/
 
 // params: startaddr -- the start addr of the shared memory
@@ -301,7 +305,39 @@ mgcsharedhashtbl_t * mgcsharedhashCreate(unsigned int size,
   ctable->loadfactor = loadfactor;
   ctable->threshold = size*loadfactor;
 
-  ctable->mask = (size << 7)-1;
+  ctable->mask = (size << 6)-1;
+
+  ctable->structs = NULL ; //FREEMALLOC_NGC(1*sizeof(mgcliststruct_t));
+  ctable->numelements = 0; // Initial number of elements in the hash
+  ctable->list = NULL;
+
+  return ctable;
+}
+
+mgcsharedhashtbl_t * mgcsharedhashCreate_I(unsigned int size, 
+                                           double loadfactor) {
+  mgcsharedhashtbl_t * ctable;
+  mgcsharedhashlistnode_t * nodes;
+  int i;
+
+  ctable = (mgcsharedhashtbl_t *)FREEMALLOC_NGC_I(sizeof(mgcsharedhashtbl_t));
+  if(ctable == NULL) {
+       // TODO
+       BAMBOO_EXIT(0xeeef);
+       return NULL;
+  }
+  // Allocate space for the hash table
+  ctable->table = (mgcsharedhashlistnode_t *)FREEMALLOC_NGC_I(
+         size*sizeof(mgcsharedhashlistnode_t));
+  if(ctable->table == NULL) {
+       BAMBOO_EXIT(0xfffe); // TODO
+       return NULL;
+  }
+  ctable->size = size;
+  ctable->loadfactor = loadfactor;
+  ctable->threshold = size*loadfactor;
+
+  ctable->mask = (size << 6)-1;
 
   ctable->structs = NULL ; //FREEMALLOC_NGC(1*sizeof(mgcliststruct_t));
   ctable->numelements = 0; // Initial number of elements in the hash
@@ -351,8 +387,10 @@ int mgcsharedhashInsert(mgcsharedhashtbl_t * tbl, void * key, void * val) {
     return -1;
   }
 
-  ptr=&tbl->table[(((unsigned INTPTR)key)&tbl->mask)>>7];
-  //printf("%x \n", (((unsigned INTPTR)key)&tbl->mask)>>7); // TODO
+  //int keyto = ((unsigned INTPTR)key) % (tbl->size);
+  //ptr=&tbl->table[keyto];
+  ptr=&tbl->table[(((unsigned INTPTR)key)&tbl->mask)>>6];
+  //printf("%x \n", (((unsigned INTPTR)key)&tbl->mask)>>6); // TODO
 
   if(ptr->key==0) {
     // the first time insert a value for the key
@@ -370,6 +408,8 @@ int mgcsharedhashInsert(mgcsharedhashtbl_t * tbl, void * key, void * val) {
          ptr->val = val;
        }
   }
+  ptr->next = tbl->list;
+  tbl->list = ptr;
   tbl->numelements++;
   return 1;
 }
@@ -382,8 +422,10 @@ int mgcsharedhashInsert_I(mgcsharedhashtbl_t * tbl, void * key, void * val) {
     return -1;
   }
 
-  ptr=&tbl->table[(((unsigned INTPTR)key)&tbl->mask)>>7];
-  //printf("%x \n", (((unsigned INTPTR)key)&tbl->mask)>>7); // TODO
+  //int keyto = ((unsigned INTPTR)key) % (tbl->size);
+  //ptr=&tbl->table[keyto];
+  ptr=&tbl->table[(((unsigned INTPTR)key)&tbl->mask)>>6];
+  //printf("%x \n", (((unsigned INTPTR)key)&tbl->mask)>>6); // TODO
 
   if(ptr->key==0) {
     // the first time insert a value for the key
@@ -405,6 +447,8 @@ int mgcsharedhashInsert_I(mgcsharedhashtbl_t * tbl, void * key, void * val) {
          ptr->val = val;
        }
   }
+  ptr->next = tbl->list;
+  tbl->list = ptr;
   tbl->numelements++;
   return 1;
 }
@@ -412,16 +456,20 @@ int mgcsharedhashInsert_I(mgcsharedhashtbl_t * tbl, void * key, void * val) {
 // Search for an address for a given oid
 INLINE void * mgcsharedhashSearch(mgcsharedhashtbl_t * tbl, void * key) {
   //REMOVE HASH FUNCTION CALL TO MAKE SURE IT IS INLINED HERE]
+  //int keyto = ((unsigned INTPTR)key) % (tbl->size);
+  //mgcsharedhashlistnode_t * node=&tbl->table[keyto];
   mgcsharedhashlistnode_t * node = 
        &tbl->table[(((unsigned INTPTR)key)&tbl->mask)>>6];
   mgcsharedhashlistnode_t *top = &tbl->table[tbl->size];
 
-  int i = 0;
+  //int i = 0;
+  //gc_num_search++;
   do {
-       i++;
+       //i++;
     if(node->key == key) {
          // TODO
-        printf("%x \n", 0xe000+i);
+        //printf("%x \n", 0xe000+i);
+        //gc_num_collision += i;
       return node->val;
     }
     node++;
index 375e693fa75ab58d2f476f6399db561ef942fd0c..94725fbf721393b7c851f9bc2a0c462a3e9c546e 100755 (executable)
@@ -80,6 +80,7 @@ typedef struct mgcsharedhashtbl {
 } mgcsharedhashtbl_t;
 
 mgcsharedhashtbl_t * mgcsharedhashCreate(unsigned int size, double loadfactor);
+mgcsharedhashtbl_t * mgcsharedhashCreate_I(unsigned int size,double loadfactor);
 int mgcsharedhashInsert(mgcsharedhashtbl_t * tbl, void * key, void * val);
 void * mgcsharedhashSearch(mgcsharedhashtbl_t * tbl, void * key);
 //unsigned int mgchashResize(unsigned int newsize);
index f3a93c6301224f9c7dcfed0f7a07e8952f491dc6..e0f92c4527c4d944dfed99325ca060eca232b229 100644 (file)
@@ -1941,11 +1941,18 @@ innermoveobj:
     //mgchashInsert_I(orig->ptr, to->ptr);
     RuntimeHashadd_I(gcpointertbl, orig->ptr, to->ptr);
        if(isremote) {
+#ifdef GC_PROFILE
+       //unsigned long long ttimet = BAMBOO_GET_EXE_TIME();
+#endif
          // add to the sharedptbl
          if(gcsharedptbl != NULL) {
                //GCSharedHashadd_I(gcsharedptbl, orig->ptr, to->ptr);
                mgcsharedhashInsert_I(gcsharedptbl, orig->ptr, to->ptr);
+               //num_mapinforequest++; // TODO
          }
+#ifdef GC_PROFILE
+       //flushstalltime_i += BAMBOO_GET_EXE_TIME()-ttimet;
+#endif
        }
     //MGCHashadd_I(gcpointertbl, orig->ptr, to->ptr);
     BAMBOO_ENTER_CLIENT_MODE_FROM_RUNTIME();
@@ -2233,12 +2240,12 @@ inline void * flushObj(void * objptr) {
     // a shared obj ptr, change to new address
     BAMBOO_ENTER_RUNTIME_MODE_FROM_CLIENT();
 #ifdef GC_PROFILE
-    // TODO unsigned long long ttime = BAMBOO_GET_EXE_TIME();
+    unsigned long long ttime = BAMBOO_GET_EXE_TIME();
 #endif
     //dstptr = mgchashSearch(objptr);
     RuntimeHashget(gcpointertbl, objptr, &dstptr);
 #ifdef GC_PROFILE
-    // TODO flushstalltime += BAMBOO_GET_EXE_TIME()-ttime;
+    flushstalltime += BAMBOO_GET_EXE_TIME()-ttime;
 #endif
     //MGCHashget(gcpointertbl, objptr, &dstptr);
     BAMBOO_ENTER_CLIENT_MODE_FROM_RUNTIME();
@@ -2254,13 +2261,16 @@ inline void * flushObj(void * objptr) {
       BAMBOO_DEBUGPRINT_REG(hostcore(objptr));
 #endif
       if(hostcore(objptr) == BAMBOO_NUM_OF_CORE) {
-       // error! the obj is right on this core, but cannot find it
-       BAMBOO_DEBUGPRINT_REG(objptr);
-       BAMBOO_EXIT(0xb103);
-       // assume that the obj has not been moved, use the original address
-       //dstptr = objptr;
+               // error! the obj is right on this core, but cannot find it
+               BAMBOO_DEBUGPRINT_REG(objptr);
+               BAMBOO_EXIT(0xb103);
+               // assume that the obj has not been moved, use the original address
+               //dstptr = objptr;
       } else {
                int hostc = hostcore(objptr);
+#ifdef GC_PROFILE
+               unsigned long long ttimet = BAMBOO_GET_EXE_TIME();
+#endif
                // check the corresponsing sharedptbl
                BAMBOO_ENTER_RUNTIME_MODE_FROM_CLIENT();
                //struct GCSharedHash * sptbl = gcrpointertbls[hostcore(objptr)];
@@ -2273,6 +2283,9 @@ inline void * flushObj(void * objptr) {
                  }
                }
                BAMBOO_ENTER_CLIENT_MODE_FROM_RUNTIME();
+#ifdef GC_PROFILE
+               flushstalltime_i += BAMBOO_GET_EXE_TIME()-ttimet;
+#endif
 
                if(dstptr == NULL) {
                  // still can not get the mapping info,
@@ -2282,11 +2295,11 @@ inline void * flushObj(void * objptr) {
                  gcmappedobj = NULL;
 #ifdef GC_PROFILE
        // TODO
-       num_mapinforequest++;
+       //num_mapinforequest++;
        //unsigned long long ttime = BAMBOO_GET_EXE_TIME();
 #endif
 #ifdef GC_PROFILE
-       unsigned long long ttimet = BAMBOO_GET_EXE_TIME();
+       //unsigned long long ttimet = BAMBOO_GET_EXE_TIME();
 #endif
                  // the first time require the mapping, send msg to the hostcore
                  // for the mapping info
@@ -2298,7 +2311,7 @@ inline void * flushObj(void * objptr) {
                        }
                  }
 #ifdef GC_PROFILE
-       flushstalltime_i += BAMBOO_GET_EXE_TIME()-ttimet;
+       //flushstalltime_i += BAMBOO_GET_EXE_TIME()-ttimet;
 #endif
 #ifdef GC_PROFILE
        // TODO
@@ -2686,13 +2699,13 @@ inline void flush(struct garbagelist * stackptr) {
   }
 #ifdef GC_PROFILE
   // TODO 
-  if(BAMBOO_NUM_OF_CORE == 0) {
-    BAMBOO_DEBUGPRINT(0xffff);
-    BAMBOO_DEBUGPRINT_REG(num_mapinforequest);
+  //if(BAMBOO_NUM_OF_CORE == 0) {
+    //BAMBOO_DEBUGPRINT(0xffff);
+    //BAMBOO_DEBUGPRINT_REG(num_mapinforequest);
     //BAMBOO_DEBUGPRINT_REG(flushstalltime);
     //BAMBOO_DEBUGPRINT_REG(num_mapinforequest_i);
-    BAMBOO_DEBUGPRINT_REG(flushstalltime_i);
-  }
+    //BAMBOO_DEBUGPRINT_REG(flushstalltime_i);
+  //}
   //BAMBOO_DEBUGPRINT_REG(flushstalltime);
 #endif
 #ifdef DEBUG
@@ -3195,6 +3208,10 @@ inline void gc(struct garbagelist * stackptr) {
                   udn_tile_coord_y());
     //dumpSMem();
 #endif
+       // TODO
+       /*extern int gc_num_search;
+       extern int gc_num_collision;
+       tprintf("Average collision: %d \n", gc_num_collision/gc_num_search);*/
   } else if(BAMBOO_NUM_OF_CORE < NUMCORES4GC) {
     gcprocessing = true;
     gc_collect(stackptr);
index 0cbab6e0801ed32820e45549d299cd46f889d861..765122102fa85b6287dff35b9a910b69ff00cdc0 100644 (file)
@@ -115,7 +115,7 @@ void * gcmappingtbl[NUMCORESACTIVE][NUM_MAPPING];*/
 //                                  + NUMCORES4GC bamboo_rmsp
 // These three types of table are always reside at the bottom of the shared 
 // memory and will never be moved or garbage collected
-#define BAMBOO_RMSP_SIZE (BAMBOO_SMEM_SIZE * 64)
+#define BAMBOO_RMSP_SIZE (BAMBOO_SMEM_SIZE * 45)
 mspace bamboo_rmsp;
 // shared pointer mapping tbl
 //volatile struct GCSharedHash * gcsharedptbl;
index 829ac1d93e85a6de916ef8f07632b947f053c8ce..fd1ae1e4609399b82ac9720a1474b35a668fb197 100644 (file)
@@ -136,7 +136,14 @@ void initruntimedata() {
   if(BAMBOO_NUM_OF_CORE < NUMCORES4GC) {
        int t_size = ((BAMBOO_RMSP_SIZE)-sizeof(mgcsharedhashtbl_t)*2
                -128*sizeof(size_t))/sizeof(mgcsharedhashlistnode_t)-2;
-       gcsharedptbl = mgcsharedhashCreate(t_size,0.30);//allocateGCSharedHash_I(20);
+       int kk = 0;
+       unsigned int tmp_k = 1 << (sizeof(int)*8 -1);
+       while(((t_size & tmp_k) == 0) && (kk < sizeof(int)*8)) {
+         t_size = t_size << 1;
+         kk++;
+       }
+       t_size = tmp_k >> kk;
+       gcsharedptbl = mgcsharedhashCreate_I(t_size,0.30);//allocateGCSharedHash_I(20);
   } else {
        gcsharedptbl = NULL;
   }
@@ -1311,12 +1318,12 @@ void * localmalloc_I(int coren,
   if(foundsmem == 1) {
     // find suitable block
     mem = gcbaseva+bamboo_smemtbl[tofindb]+((tofindb<NUMCORES4GC) ?
-                                            (BAMBOO_SMEM_SIZE_L*tofindb) : (BAMBOO_LARGE_SMEM_BOUND+
-                                                                            (tofindb-NUMCORES4GC)*BAMBOO_SMEM_SIZE));
+          (BAMBOO_SMEM_SIZE_L*tofindb) : (BAMBOO_LARGE_SMEM_BOUND+
+          (tofindb-NUMCORES4GC)*BAMBOO_SMEM_SIZE));
     *allocsize = size;
     // set bamboo_smemtbl
     for(i = tofindb; i <= totest; i++) {
-      bamboo_smemtbl[i]=(i<NUMCORES4GC) ? BAMBOO_SMEM_SIZE_L : BAMBOO_SMEM_SIZE;
+      bamboo_smemtbl[i]=(i<NUMCORES4GC)?BAMBOO_SMEM_SIZE_L:BAMBOO_SMEM_SIZE;
     }
   } else if(foundsmem == 2) {
     // no suitable block
@@ -1347,24 +1354,24 @@ void * globalmalloc_I(int coren,
       bool tocheck = true;
       // have some space in the block
       if(totest == tofindb) {
-       // the first partition
-       size = bound - nsize;
+               // the first partition
+               size = bound - nsize;
       } else if(nsize == 0) {
-       // an empty partition, can be appended
-       size += bound;
+               // an empty partition, can be appended
+               size += bound;
       } else {
-       // not an empty partition, can not be appended
-       // the last continuous block is not big enough, start another block
-       isnext = true;
-       tocheck = false;
-      }                   // if(totest == tofindb) else if(nsize == 0) else ...
+               // not an empty partition, can not be appended
+               // the last continuous block is not big enough, start another block
+               isnext = true;
+               tocheck = false;
+      }  // if(totest == tofindb) else if(nsize == 0) else ...
       if(tocheck) {
-       if(size >= isize) {
-         // have enough space in the block, malloc
-         foundsmem = 1;
-         break;
-       }                         // if(size > isize)
-      }                   // if(tocheck)
+               if(size >= isize) {
+                 // have enough space in the block, malloc
+                 foundsmem = 1;
+                 break;
+               }  // if(size > isize)
+      }   // if(tocheck)
     } else {
       isnext = true;
     }            // if(nsize < bound) else ...
@@ -1377,18 +1384,18 @@ void * globalmalloc_I(int coren,
     if(isnext) {
       // start another block
       tofindb = totest;
-    }             // if(islocal)
+    } // if(islocal)
   } while(true);
 
   if(foundsmem == 1) {
     // find suitable block
     mem = gcbaseva+bamboo_smemtbl[tofindb]+((tofindb<NUMCORES4GC) ?
-                                            (BAMBOO_SMEM_SIZE_L*tofindb) : (BAMBOO_LARGE_SMEM_BOUND+
-                                                                            (tofindb-NUMCORES4GC)*BAMBOO_SMEM_SIZE));
+          (BAMBOO_SMEM_SIZE_L*tofindb) : (BAMBOO_LARGE_SMEM_BOUND+
+          (tofindb-NUMCORES4GC)*BAMBOO_SMEM_SIZE));
     *allocsize = size;
     // set bamboo_smemtbl
     for(int i = tofindb; i <= totest; i++) {
-      bamboo_smemtbl[i]=(i<NUMCORES4GC) ? BAMBOO_SMEM_SIZE_L : BAMBOO_SMEM_SIZE;
+      bamboo_smemtbl[i]=(i<NUMCORES4GC)?BAMBOO_SMEM_SIZE_L:BAMBOO_SMEM_SIZE;
     }
     if(tofindb == bamboo_free_block) {
       bamboo_free_block = totest+1;
@@ -2101,7 +2108,8 @@ INLINE void processmsg_memresponse_I() {
   } else {
 #ifdef MULTICORE_GC
     // fill header to store the size of this mem block
-    memset(data1, 0, BAMBOO_CACHE_LINE_SIZE);
+    BAMBOO_MEMSET_WH(data1, '\0', BAMBOO_CACHE_LINE_SIZE); 
+       //memset(data1, 0, BAMBOO_CACHE_LINE_SIZE);
     (*((int*)data1)) = data2;
     bamboo_smem_size = data2 - BAMBOO_CACHE_LINE_SIZE;
     bamboo_cur_msp = data1 + BAMBOO_CACHE_LINE_SIZE;
@@ -2328,7 +2336,7 @@ INLINE void processmsg_gcmarkedobj_I() {
   if(((int *)data1)[6] == INIT) {
     // this is the first time that this object is discovered,
     // set the flag as DISCOVERED
-    ((int *)data1)[6] |= DISCOVERED;
+    ((int *)data1)[6] = DISCOVERED;
     gc_enqueue_I(data1);
   } 
   // set the remote flag