Mercurial > cgi-bin > hgwebdir.cgi > VMS > VMS_Implementations > VMS_impls > VMS__MC_shared_impl
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 22:0877c22b1191 | 23:314cb94c95a0 |
|---|---|
| 12 #include <stdlib.h> | 12 #include <stdlib.h> |
| 13 #include <stdio.h> | 13 #include <stdio.h> |
| 14 | 14 |
| 15 #include "VMS.h" | 15 #include "VMS.h" |
| 16 #include "Histogram/Histogram.h" | 16 #include "Histogram/Histogram.h" |
| 17 | |
| 18 inline void | |
| 19 sendFreeReqst_lib(int receiverID, void *ptrToFree, VirtProcr *animPr); | |
| 20 | |
| 21 inline void | |
| 22 sendFreeReqst_master(int receiverID, void *ptrToFree); | |
| 17 | 23 |
| 18 /*Helper function | 24 /*Helper function |
| 19 *Insert a newly generated free chunk into the first spot on the free list. | 25 *Insert a newly generated free chunk into the first spot on the free list. |
| 20 * The chunk is cast as a MallocProlog, so the various pointers in it are | 26 * The chunk is cast as a MallocProlog, so the various pointers in it are |
| 21 * accessed with C's help -- and the size of the prolog is easily added to | 27 * accessed with C's help -- and the size of the prolog is easily added to |
| 68 VMS__malloc_on_core( size_t sizeRequested, int procrID) | 74 VMS__malloc_on_core( size_t sizeRequested, int procrID) |
| 69 { MallocProlog *foundElem = NULL, *currElem, *newElem; | 75 { MallocProlog *foundElem = NULL, *currElem, *newElem; |
| 70 MallocPrologAllocated *returnElem; | 76 MallocPrologAllocated *returnElem; |
| 71 ssize_t amountExtra, sizeConsumed,sizeOfFound; | 77 ssize_t amountExtra, sizeConsumed,sizeOfFound; |
| 72 uint32 foundElemIsTopOfHeap; | 78 uint32 foundElemIsTopOfHeap; |
| 73 | |
| 74 printf("Malloc on core %d\n", procrID); | |
| 75 | 79 |
| 76 //============================= MEASUREMENT STUFF ======================== | 80 //============================= MEASUREMENT STUFF ======================== |
| 77 #ifdef MEAS__TIME_MALLOC | 81 #ifdef MEAS__TIME_MALLOC |
| 78 int32 startStamp, endStamp; | 82 int32 startStamp, endStamp; |
| 79 saveLowTimeStampCountInto( startStamp ); | 83 saveLowTimeStampCountInto( startStamp ); |
| 165 { | 169 { |
| 166 VMS__free_on_core(ptrToFree, _VMSMasterEnv->currentMasterProcrID); | 170 VMS__free_on_core(ptrToFree, _VMSMasterEnv->currentMasterProcrID); |
| 167 } | 171 } |
| 168 else | 172 else |
| 169 { | 173 { |
| 170 //Request from other Core | 174 sendFreeReqst_master(chunk->procrID, ptrToFree); |
| 175 | |
| 171 } | 176 } |
| 172 } | 177 } |
| 173 | 178 |
| 174 /* | 179 /* |
| 175 * This free is called for the plugins. It decides whether the allocation of | 180 * This free is called for the plugins. It decides whether the allocation of |
| 178 */ | 183 */ |
| 179 void | 184 void |
| 180 VMS__free_in_lib(void *ptrToFree, VirtProcr *VProc) | 185 VMS__free_in_lib(void *ptrToFree, VirtProcr *VProc) |
| 181 { | 186 { |
| 182 MallocPrologAllocated *chunk = (MallocPrologAllocated*)ptrToFree - 1; | 187 MallocPrologAllocated *chunk = (MallocPrologAllocated*)ptrToFree - 1; |
| 183 printf("Free from core %d for core %d\n", VProc->coreAnimatedBy, chunk->procrID); | |
| 184 if(chunk->procrID == VProc->coreAnimatedBy) | 188 if(chunk->procrID == VProc->coreAnimatedBy) |
| 185 { | 189 { |
| 186 VMS__free_on_core(ptrToFree, VProc->coreAnimatedBy); | 190 VMS__free_on_core(ptrToFree, VProc->coreAnimatedBy); |
| 187 } | 191 } |
| 188 else | 192 else |
| 189 { | 193 { |
| 190 //Request from other Core | 194 sendFreeReqst_lib(chunk->procrID, ptrToFree, VProc); |
| 191 } | 195 } |
| 192 } | 196 } |
| 197 | |
| 198 /* | |
| 199 * This is called form a masterVP and request an free from a different masterVP. | |
| 200 * The free of the request structure is done after the request is handled. | |
| 201 */ | |
| 202 inline void | |
| 203 sendFreeReqst_master(int receiverID, void *ptrToFree) | |
| 204 { | |
| 205 InterVMSCoreReqst *freeReqst = VMS__malloc(sizeof(InterVMSCoreReqst)); | |
| 206 freeReqst->freePtr = ptrToFree; | |
| 207 freeReqst->secondReqType = transfer_free_ptr; | |
| 208 | |
| 209 sendInterMasterReqst(receiverID, (InterMasterReqst*)freeReqst); | |
| 210 } | |
| 211 | |
| 212 /* | |
| 213 * This is called if the free is called from the plugin. This requests an inter | |
| 214 * master request from his master. | |
| 215 */ | |
| 216 inline void | |
| 217 sendFreeReqst_lib(int receiverID, void *ptrToFree, VirtProcr *animPr ) | |
| 218 { | |
| 219 VMSSemReq reqData; | |
| 220 InterVMSCoreReqst *freeReqst = VMS__malloc(sizeof(InterVMSCoreReqst)); | |
| 221 freeReqst->freePtr = ptrToFree; | |
| 222 freeReqst->secondReqType = transfer_free_ptr; | |
| 223 | |
| 224 reqData.reqType = interMasterReqst; | |
| 225 reqData.receiverID = receiverID; | |
| 226 reqData.data = (void*)freeReqst; | |
| 227 | |
| 228 VMS__send_VMSSem_request( (void*)&reqData, animPr ); | |
| 229 } | |
| 193 | 230 |
| 194 /*This is sequential code -- only to be called from the Master | 231 /*This is sequential code -- only to be called from the Master |
| 195 * When free, subtract the size of prolog from pointer, then cast it to a | 232 * When free, subtract the size of prolog from pointer, then cast it to a |
| 196 * MallocProlog. Then check the nextLower and nextHigher chunks to see if | 233 * MallocProlog. Then check the nextLower and nextHigher chunks to see if |
| 197 * one or both are also free, and coalesce if so, and if neither free, then | 234 * one or both are also free, and coalesce if so, and if neither free, then |
| 365 void | 402 void |
| 366 VMS__free_in_ext( void *ptrToFree ) | 403 VMS__free_in_ext( void *ptrToFree ) |
| 367 { | 404 { |
| 368 //just risk system-stack faults until get this figured out | 405 //just risk system-stack faults until get this figured out |
| 369 free( ptrToFree ); | 406 free( ptrToFree ); |
| 370 | |
| 371 //TODO: fix this -- so | |
| 372 } | 407 } |
| 373 | 408 |
| 374 | 409 |
| 375 /*Designed to be called from the main thread outside of VMS, during init | 410 /*Designed to be called from the main thread outside of VMS, during init |
| 376 */ | 411 */ |
| 416 | 451 |
| 417 | 452 |
| 418 /*Designed to be called from the main thread outside of VMS, during cleanup | 453 /*Designed to be called from the main thread outside of VMS, during cleanup |
| 419 */ | 454 */ |
| 420 void | 455 void |
| 421 VMS_ext__free_free_list( MallocProlog* freeListHeads[] ) | 456 VMS_ext__free_free_list( MallocProlog* freeListHead) |
| 422 { | 457 { |
| 423 //stashed a ptr to the one and only bug chunk malloc'd from OS in the | 458 //stashed a ptr to the one and only bug chunk malloc'd from OS in the |
| 424 // free list head's next lower in mem pointer | 459 // free list head's next lower in mem pointer |
| 425 int i; | 460 free( freeListHead->nextLowerInMem ); |
| 426 for(i=0; i<NUM_CORES; i++) | |
| 427 { | |
| 428 free( freeListHeads[i]->nextLowerInMem ); | |
| 429 } | |
| 430 //don't free the head -- it'll be in an array eventually -- free whole | 461 //don't free the head -- it'll be in an array eventually -- free whole |
| 431 // array when all the free lists linked from it have already been freed | 462 // array when all the free lists linked from it have already been freed |
| 432 } | 463 } |
| 433 | 464 |
