diff vmalloc.c @ 135:0b49fd35afc1

distributed free working -app sends a VMSSemReqst to his Master which send a request to a different Master -Master send the request directly -The request structure is freed by the sender, when the request was handled There are still problems on shutdown. The shutdownVPs are all allocated by one Master which is likly to be terminated
author Merten Sach <msach@mailbox.tu-berlin.de>
date Fri, 16 Sep 2011 20:08:28 +0200
parents a9b72021f053
children 99343ffe1918
line diff
     1.1 --- a/vmalloc.c	Fri Sep 16 16:19:24 2011 +0200
     1.2 +++ b/vmalloc.c	Fri Sep 16 20:08:28 2011 +0200
     1.3 @@ -15,6 +15,12 @@
     1.4  #include "VMS.h"
     1.5  #include "Histogram/Histogram.h"
     1.6  
     1.7 +inline void
     1.8 +sendFreeReqst_lib(int receiverID, void *ptrToFree, VirtProcr *animPr);
     1.9 +
    1.10 +inline void
    1.11 +sendFreeReqst_master(int receiverID, void *ptrToFree);
    1.12 +
    1.13  /*Helper function
    1.14   *Insert a newly generated free chunk into the first spot on the free list.
    1.15   * The chunk is cast as a MallocProlog, so the various pointers in it are
    1.16 @@ -70,8 +76,6 @@
    1.17     MallocPrologAllocated *returnElem;
    1.18     ssize_t        amountExtra, sizeConsumed,sizeOfFound;
    1.19     uint32        foundElemIsTopOfHeap;
    1.20 -   
    1.21 -   printf("Malloc on core %d\n", procrID);
    1.22  
    1.23     //============================= MEASUREMENT STUFF ========================
    1.24     #ifdef MEAS__TIME_MALLOC
    1.25 @@ -167,7 +171,8 @@
    1.26      }
    1.27      else
    1.28      {
    1.29 -        //Request from other Core
    1.30 +        sendFreeReqst_master(chunk->procrID, ptrToFree);
    1.31 +        
    1.32      }
    1.33  }
    1.34  
    1.35 @@ -180,17 +185,49 @@
    1.36  VMS__free_in_lib(void *ptrToFree, VirtProcr *VProc)
    1.37  {
    1.38      MallocPrologAllocated *chunk = (MallocPrologAllocated*)ptrToFree - 1;
    1.39 -    printf("Free from core %d for core %d\n", VProc->coreAnimatedBy, chunk->procrID);
    1.40      if(chunk->procrID == VProc->coreAnimatedBy)
    1.41      {
    1.42          VMS__free_on_core(ptrToFree, VProc->coreAnimatedBy);
    1.43      }
    1.44      else
    1.45      {
    1.46 -        //Request from other Core
    1.47 +        sendFreeReqst_lib(chunk->procrID, ptrToFree, VProc);
    1.48      }
    1.49  }
    1.50  
    1.51 +/* 
    1.52 + * This is called form a masterVP and request an free from a different masterVP.
    1.53 + * The free of the request structure is done after the request is handled.
    1.54 + */
    1.55 +inline void
    1.56 +sendFreeReqst_master(int receiverID, void *ptrToFree)
    1.57 +{
    1.58 +   InterVMSCoreReqst *freeReqst = VMS__malloc(sizeof(InterVMSCoreReqst));
    1.59 +   freeReqst->freePtr = ptrToFree;
    1.60 +   freeReqst->secondReqType = transfer_free_ptr;
    1.61 +
    1.62 +   sendInterMasterReqst(receiverID, (InterMasterReqst*)freeReqst);
    1.63 + }
    1.64 +
    1.65 +/*
    1.66 + * This is called if the free is called from the plugin. This requests an inter
    1.67 + * master request from his master.
    1.68 + */
    1.69 +inline void
    1.70 +sendFreeReqst_lib(int receiverID, void *ptrToFree, VirtProcr *animPr )
    1.71 +{
    1.72 +   VMSSemReq reqData;
    1.73 +   InterVMSCoreReqst *freeReqst = VMS__malloc(sizeof(InterVMSCoreReqst));
    1.74 +   freeReqst->freePtr = ptrToFree;
    1.75 +   freeReqst->secondReqType = transfer_free_ptr;
    1.76 +
    1.77 +   reqData.reqType  = interMasterReqst;
    1.78 +   reqData.receiverID   = receiverID;
    1.79 +   reqData.data  = (void*)freeReqst;
    1.80 +
    1.81 +   VMS__send_VMSSem_request( (void*)&reqData, animPr );
    1.82 + }
    1.83 +
    1.84  /*This is sequential code -- only to be called from the Master
    1.85   * When free, subtract the size of prolog from pointer, then cast it to a
    1.86   * MallocProlog.  Then check the nextLower and nextHigher chunks to see if
    1.87 @@ -367,8 +404,6 @@
    1.88   {
    1.89        //just risk system-stack faults until get this figured out
    1.90     free( ptrToFree );
    1.91 -
    1.92 -      //TODO: fix this -- so 
    1.93   }
    1.94  
    1.95  
    1.96 @@ -418,15 +453,11 @@
    1.97  /*Designed to be called from the main thread outside of VMS, during cleanup
    1.98   */
    1.99  void
   1.100 -VMS_ext__free_free_list( MallocProlog* freeListHeads[] )
   1.101 +VMS_ext__free_free_list( MallocProlog* freeListHead)
   1.102   {    
   1.103        //stashed a ptr to the one and only bug chunk malloc'd from OS in the
   1.104        // free list head's next lower in mem pointer
   1.105 -    int i;
   1.106 -    for(i=0; i<NUM_CORES; i++)
   1.107 -    {
   1.108 -        free( freeListHeads[i]->nextLowerInMem );
   1.109 -    }
   1.110 +    free( freeListHead->nextLowerInMem );
   1.111     //don't free the head -- it'll be in an array eventually -- free whole
   1.112     // array when all the free lists linked from it have already been freed
   1.113   }