Abstracting out mempool related access to mempool.h as macros
authorNikhil Jain <nikhil@illinois.edu>
Mon, 26 Mar 2012 18:42:25 +0000 (11:42 -0700)
committerNikhil Jain <nikhil@illinois.edu>
Mon, 26 Mar 2012 18:42:25 +0000 (11:42 -0700)
src/arch/gemini_gni/machine.c
src/arch/util/mempool.h
src/conv-core/isomalloc.c

index ac302bbcca48825b5cbaa36b3c008775f4a408d7..5daff7774ac1478031849567d330c559831a32ae 100644 (file)
@@ -254,23 +254,23 @@ uint8_t   onesided_hnd, omdh;
     } while (0)
 #endif
 
-#define   GetMempoolBlockPtr(x)  (((mempool_header*)((char*)(x)-ALIGNBUF))->block_ptr)
-#define   GetMempoolPtr(x)        GetMempoolBlockPtr(x)->mptr
-#define   GetMempoolsize(x)       GetMempoolBlockPtr(x)->size
-#define   GetMemHndl(x)           GetMempoolBlockPtr(x)->mem_hndl
-#define   IncreaseMsgInRecv(x)    (GetMempoolBlockPtr(x)->msgs_in_recv)++
-#define   DecreaseMsgInRecv(x)    (GetMempoolBlockPtr(x)->msgs_in_recv)--
-#define   IncreaseMsgInSend(x)    (GetMempoolBlockPtr(x)->msgs_in_send)++
-#define   DecreaseMsgInSend(x)    (GetMempoolBlockPtr(x)->msgs_in_send)--
-#define   NoMsgInSend(x)          GetMempoolBlockPtr(x)->msgs_in_send == 0
-#define   NoMsgInRecv(x)          GetMempoolBlockPtr(x)->msgs_in_recv == 0
-#define   NoMsgInFlight(x)        (GetMempoolBlockPtr(x)->msgs_in_send + GetMempoolBlockPtr(x)->msgs_in_recv  == 0)
+#define   GetMempoolBlockPtr(x)   MEMPOOL_GetBlockPtr(MEMPOOL_GetMempoolHeader(x,ALIGNBUF))
+#define   GetMempoolPtr(x)        MEMPOOL_GetMempoolPtr(MEMPOOL_GetMempoolHeader(x,ALIGNBUF))
+#define   GetMempoolsize(x)       MEMPOOL_GetSize(MEMPOOL_GetMempoolHeader(x,ALIGNBUF))
+#define   GetMemHndl(x)           MEMPOOL_GetMemHndl(MEMPOOL_GetMempoolHeader(x,ALIGNBUF))
+#define   IncreaseMsgInRecv(x)    MEMPOOL_IncMsgInRecv(MEMPOOL_GetMempoolHeader(x,ALIGNBUF))
+#define   DecreaseMsgInRecv(x)    MEMPOOL_DecMsgInRecv(MEMPOOL_GetMempoolHeader(x,ALIGNBUF))
+#define   IncreaseMsgInSend(x)    MEMPOOL_IncMsgInSend(MEMPOOL_GetMempoolHeader(x,ALIGNBUF))
+#define   DecreaseMsgInSend(x)    MEMPOOL_DecMsgInSend(MEMPOOL_GetMempoolHeader(x,ALIGNBUF))
+#define   NoMsgInSend(x)          MEMPOOL_GetMsgInSend(MEMPOOL_GetMempoolHeader(x,ALIGNBUF)) == 0
+#define   NoMsgInRecv(x)          MEMPOOL_GetMsgInRecv(MEMPOOL_GetMempoolHeader(x,ALIGNBUF)) == 0
+#define   NoMsgInFlight(x)        (NoMsgInSend(x) && NoMsgInRecv(x))
 #define   IsMemHndlZero(x)        ((x).qword1 == 0 && (x).qword2 == 0)
 #define   SetMemHndlZero(x)       do {(x).qword1 = 0;(x).qword2 = 0;} while (0)
-#define   NotRegistered(x)        IsMemHndlZero(((block_header*)x)->mem_hndl)
+#define   NotRegistered(x)        IsMemHndlZero(GetMemHndl(x))
 
-#define   GetMemHndlFromBlockHeader(x) ((block_header*)x)->mem_hndl
-#define   GetSizeFromBlockHeader(x)    ((block_header*)x)->size
+#define   GetMemHndlFromBlockHeader(x) MEMPOOL_GetBlockMemHndl(x)
+#define   GetSizeFromBlockHeader(x)    MEMPOOL_GetBlockSize(x)
 
 #define CmiGetMsgSize(m)     ((CmiMsgHeaderExt*)m)->size
 #define CmiSetMsgSize(m,s)   ((((CmiMsgHeaderExt*)m)->size)=(s))
index aa14b4f9ecc43e3bb4fc674ab6e8f1d8e8826405..ce1dc3eb67938c52f2330736db9933168c2364ee 100644 (file)
@@ -20,6 +20,29 @@ typedef void (* mempool_freeblock)(void *ptr, mem_handle_t mem_hndl);
 
 #define cutOffNum 25 
 
+//given x as mptr get
+#define   MEMPOOL_GetBlockHead(x)   (block_header*)&(x->block_head)    
+//given x as block header, get ...
+#define   MEMPOOL_GetBlockSize(x)    (((block_header*)x)->size)
+#define   MEMPOOL_GetBlockMemHndl(x) (((block_header*)x)->mem_hndl)
+#define   MEMPOOL_GetBlockNext(x)    (((block_header*)x)->block_next)     
+//given x as user pointer, get mempool_header/slot_header
+#define   MEMPOOL_GetMempoolHeader(x,align) \
+                                  ((mempool_header*)((char*)(x)-align))
+//given x as mempool_header/slot_header, get ...
+#define   MEMPOOL_GetBlockPtr(x)    ((block_header*)(x->block_ptr))
+#define   MEMPOOL_GetMempoolPtr(x)  ((mempool_type*)(MEMPOOL_GetBlockPtr(x)->mptr))
+#define   MEMPOOL_GetSize(x)      (MEMPOOL_GetBlockPtr(x)->size)
+#define   MEMPOOL_GetMemHndl(x)   (MEMPOOL_GetBlockPtr(x)->mem_hndl)
+#define   MEMPOOL_GetMsgInRecv(x) (MEMPOOL_GetBlockPtr(x)->msgs_in_recv)
+#define   MEMPOOL_GetMsgInSend(x) (MEMPOOL_GetBlockPtr(x)->msgs_in_send)
+#define   MEMPOOL_IncMsgInRecv(x) (MEMPOOL_GetBlockPtr(x)->msgs_in_recv)++
+#define   MEMPOOL_DecMsgInRecv(x) (MEMPOOL_GetBlockPtr(x)->msgs_in_recv)--
+#define   MEMPOOL_IncMsgInSend(x) (MEMPOOL_GetBlockPtr(x)->msgs_in_send)++
+#define   MEMPOOL_DecMsgInSend(x) (MEMPOOL_GetBlockPtr(x)->msgs_in_send)--
+#define   MEMPOOL_GetSlotGNext(x)     (x->gnext)
+#define   MEMPOOL_GetSlotStatus(x)    (x->status)
+#define          MEMPOOL_GetSlotSize(x)      (cutOffPoints[x->size])
 struct block_header;
 struct mempool_type;
 
index d14aed009dd3047139718c0370c12016999a5379..375c500db3ffcd5c9ff036ef8f85db5bd230d013 100644 (file)
@@ -2604,19 +2604,19 @@ void CmiIsomallocBlockListPup(pup_er p,CmiIsomallocBlockList **lp, CthThread tid
   flags[0] = 0; flags[1] = 1;
   if(!pup_isUnpacking(p)) {
     mptr = CtvAccessOther(tid,threadpool);
-    current = &(CtvAccessOther(tid,threadpool)->block_head);
+    current = MEMPOOL_GetBlockHead(mptr);
     while(current != NULL) {
       numBlocks++;
-      current = current->block_next?(block_header *)((char*)mptr+current->block_next):NULL;
+      current = MEMPOOL_GetBlockNext(current)?(block_header *)((char*)mptr+MEMPOOL_GetBlockNext(current)):NULL;
     }
 #if ISOMALLOC_DEBUG
     printf("Number of blocks packed %d\n",numBlocks);
 #endif
     pup_int(p,&numBlocks);
-    current = &(CtvAccessOther(tid,threadpool)->block_head);
+    current = MEMPOOL_GetBlockHead(mptr);
     while(current != NULL) {
-      pup_bytes(p,&current->size,sizeof(current->size));
-      pup_bytes(p,&current->mem_hndl,sizeof(CmiInt8));
+      pup_bytes(p,&(MEMPOOL_GetBlockSize(current)),sizeof(MEMPOOL_GetBlockSize(current)));
+      pup_bytes(p,&(MEMPOOL_GetBlockMemHndl(current)),sizeof(CmiInt8));
       numSlots = 0;
       if(flag) {
         pup_bytes(p,current,sizeof(mempool_type));
@@ -2627,7 +2627,7 @@ void CmiIsomallocBlockListPup(pup_er p,CmiIsomallocBlockList **lp, CthThread tid
       }
       while(currSlot != NULL) {
         numSlots++;
-        currSlot = currSlot->gnext?(slot_header*)((char*)mptr+currSlot->gnext):NULL;
+        currSlot = (MEMPOOL_GetSlotGNext(currSlot))?(slot_header*)((char*)mptr+MEMPOOL_GetSlotGNext(currSlot)):NULL;
       }
       pup_int(p,&numSlots);
       if(flag) {
@@ -2638,16 +2638,16 @@ void CmiIsomallocBlockListPup(pup_er p,CmiIsomallocBlockList **lp, CthThread tid
       }
       while(currSlot != NULL) {
         pup_int(p,&cutOffPoints[currSlot->size]);
-        if(currSlot->status) {
+        if(MEMPOOL_GetSlotStatus(currSlot)) {
           pup_int(p,&flags[0]);
           pup_bytes(p,(void*)currSlot,sizeof(slot_header));
         } else {
           pup_int(p,&flags[1]);
-          pup_bytes(p,(void*)currSlot,cutOffPoints[currSlot->size]);
+          pup_bytes(p,(void*)currSlot,MEMPOOL_GetSlotSize(currSlot));
         }
-        currSlot = currSlot->gnext?(slot_header*)((char*)mptr+currSlot->gnext):NULL;
+        currSlot = (MEMPOOL_GetSlotGNext(currSlot))?(slot_header*)((char*)mptr+MEMPOOL_GetSlotGNext(currSlot)):NULL;
       }
-      current = current->block_next?(block_header *)((char*)mptr+current->block_next):NULL;
+      current = (MEMPOOL_GetBlockNext(current))?(block_header *)((char*)mptr+MEMPOOL_GetBlockNext(current)):NULL;
     }
   }