# HG changeset patch # User Me # Date 1281345871 25200 # Node ID c8823e0bb2b430713eeb99a088a8ea6d2e826a3f # Parent 0e008278fe3c0c8381450e4ee240b6af6746ae80 Started adding own version of malloc and free Just in case they're using TLS and causing the issues diff -r 0e008278fe3c -r c8823e0bb2b4 CoreLoop.c --- a/CoreLoop.c Wed Jul 28 13:12:10 2010 -0700 +++ b/CoreLoop.c Mon Aug 09 02:24:31 2010 -0700 @@ -16,13 +16,18 @@ #include -/*This is the loop that runs in the PThread pinned to each core - * get work-unit struc from queue, - * call function-ptr, passing it pointer to data - * transfer return value to slave's "requests" pointer - * write the slave's "Done" flag and repeat. +/*This is the loop that runs in the OS Thread pinned to each core + *Get virt procr from queue, + * save state of current animator, then load in state of virt procr, using + * jmp instr to switch the program-counter state -- making the virt procr + * the new animator. + *At some point, the virt procr will suspend itself by saving out its + * animator state (stack ptr, frame ptr, program counter) and switching + * back to the OS Thread's animator state, which means restoring the + * stack and frame and jumping to the core loop start point. + *This cycle then repeats, until a special shutdown virtual processor is + * animated, which jumps to the end point at the bottom of core loop. */ -//pthread_create requires ptr to func that takes void * and returns void * void * coreLoop( void *paramsIn ) { @@ -32,7 +37,6 @@ unsigned long coreMask; //has 1 in bit positions of allowed cores int errorCode; - // Get the communication queues out of the param passed in coreLoopThdParams = (ThdParams *)paramsIn; //wait until signalled that setup is complete @@ -44,15 +48,11 @@ } pthread_mutex_unlock( &suspendLock ); - printf( "\nCore unsuspended: %d\n", coreLoopThdParams->coreNum ); + //printf( "\nCore unsuspended: %d\n", coreLoopThdParams->coreNum ); //set thread affinity //Linux requires pinning thd to core inside thread-function //Designate a core by a 1 in bit-position corresponding to the core -// cpu_set_t cpuMask; -// CPU_ZERO( &cpuMask ); -// CPU_SET( coreLoopThdParams->coreNum, &cpuMask ); - coreMask = 1 << coreLoopThdParams->coreNum; pthread_t selfThd = pthread_self(); @@ -73,7 +73,7 @@ // after the start point -- with the one exception of _VMSWorkQ - // Get to work! -- virt procr jumps back here when done or suspends + // Get to work! -- virt procr jumps back here when suspends //Note, have to restore the frame-pointer before jump to here, to get // this code to work right (workQ and so forth are frame-ptr relative) CoreLoopStartPt: @@ -84,13 +84,10 @@ workQ = _VMSWorkQ; currPr = (VirtProcr *) readVMSQ( workQ ); -// printf("core %d loop procr addr: %d\n", coreLoopThdParams->coreNum, \ -// (int)currPr ); fflush(stdin); - currPr->coreLoopStartPt = &&CoreLoopStartPt; //to be sure.(GCC specific) - + currPr->coreLoopStartPt = &&CoreLoopStartPt; //to be sure -- chg for perf currPr->coreAnimatedBy = coreLoopThdParams->coreNum; - //switch to virt procr's stack and frame ptr then jump to virt procr + //switch to virt procr's stack and frame ptr then jump to virt procr fn void *stackPtr, *framePtr, *jmpPt, *coreLoopFramePtrAddr, \ *coreLoopStackPtrAddr; @@ -123,15 +120,18 @@ /* clobber */ : "memory", "%eax", "%ebx", "%ecx", "%edx", "%edi", "%esi" \ ); - //======================================================================== - - //jmp to here when want to shut down the VMS system + //=========== jmp to here when want to shut down the VMS system ========== CoreLoopEndPt: + //first free shutdown VP that jumped here -- it first restores the + // coreloop's stack, so addr of currPr in stack frame is still correct + VMS__handle_dissipate_reqst( currPr ); pthread_exit( NULL ); } + +//=========================================================================== /*This sequential version is exact same as threaded, except doesn't do the * pin-threads part, nor the wait until setup complete part. */ diff -r 0e008278fe3c -r c8823e0bb2b4 MasterLoop.c --- a/MasterLoop.c Wed Jul 28 13:12:10 2010 -0700 +++ b/MasterLoop.c Mon Aug 09 02:24:31 2010 -0700 @@ -194,7 +194,7 @@ movl %4, %%esp; \ movl %5, %%ebp; \ movl $0x0, (%%ebx); \ - jmp %%eax " \ + jmp %%eax;" \ /* outputs */ : "=g" (stackPtrAddr), "=g" (framePtrAddr), \ "=g"(stillRunningAddr) \ /* inputs */ : "g" (jmpPt), "g"(coreLoopStackPtr), "g"(coreLoopFramePtr)\ diff -r 0e008278fe3c -r c8823e0bb2b4 VMS.c --- a/VMS.c Wed Jul 28 13:12:10 2010 -0700 +++ b/VMS.c Mon Aug 09 02:24:31 2010 -0700 @@ -100,8 +100,49 @@ writeVMSQ( masterEnv->masterVirtPr, workQ ); numProcrsCreated = 1; //global counter for debugging + + //==================== malloc substitute ======================== + // + //Testing whether malloc is using thread-local storage and therefore + // causing unreliable behavior. + //Just allocate a massive chunk of memory and roll own malloc/free and + // make app use VMS__malloc_to, which will suspend and perform malloc + // in the master, taking from this massive chunk. + +// initFreeList(); } +/* +void +initMasterMalloc() + { + _VMSMasterEnv->mallocChunk = malloc( MASSIVE_MALLOC_SIZE ); + + //The free-list element is the first several locations of an + // allocated chunk -- the address given to the application is pre- + // pended with both the ownership structure and the free-list struc. + //So, write the values of these into the first locations of + // mallocChunk -- which marks it as free & puts in its size. + listElem = (FreeListElem *)_VMSMasterEnv->mallocChunk; + listElem->size = MASSIVE_MALLOC_SIZE - NUM_PREPEND_BYTES + listElem->next = NULL; + } + +void +dissipateMasterMalloc() + { + //Just foo code -- to get going -- doing as if free list were link-list + currElem = _VMSMasterEnv->freeList; + while( currElem != NULL ) + { + nextElem = currElem->next; + masterFree( currElem ); + currElem = nextElem; + } + free( _VMSMasterEnv->freeList ); + } + */ + void create_sched_slots( MasterEnv *masterEnv ) { SchedSlot **schedSlots, **filledSlots; @@ -551,7 +592,7 @@ *This function has the sole purpose of setting the stack and framePtr * to the coreLoop's stack and framePtr.. it does that then jumps to the * core loop's shutdown point -- might be able to just call Pthread_exit - * from here, but going back to the pthread's stack and setting everything + * from here, but am going back to the pthread's stack and setting everything * up just as if it never jumped out, before calling pthread_exit. *The end-point of core loop will free the stack and so forth of the * processor that animates this function, (this fn is transfering the @@ -580,7 +621,9 @@ -/*This is called has to free anything allocated during VMS_init, and any other alloc'd +/*This is called after the threads have shut down and control as returned + * to the semantic layer, in the entry point function in the main thread. + * It has to free anything allocated during VMS_init, and any other alloc'd * locations that might be left over. */ void diff -r 0e008278fe3c -r c8823e0bb2b4 VMS.h --- a/VMS.h Wed Jul 28 13:12:10 2010 -0700 +++ b/VMS.h Mon Aug 09 02:24:31 2010 -0700 @@ -22,15 +22,20 @@ //#define NUM_SCHED_SLOTS (2 * NUM_CORES + 1) #define NUM_SCHED_SLOTS 3 - //128K stack.. compromise, want 10K virtPr -#define VIRT_PROCR_STACK_SIZE 0x10000 + // 8K stack +#define VIRT_PROCR_STACK_SIZE 0x20000 + + //256M of total memory for VMS application to VMS__malloc +#define MASSIVE_MALLOC_SIZE 0x10000000 + +#define NUM_PREPEND_BYTES sizeof(FreeListElem) + sizeof(ownerElem); #define SUCCESS 0 -#define writeVMSQ writePThdQ -#define readVMSQ readPThdQ -#define makeVMSQ makePThdQ -#define VMSQueueStruc PThdQueueStruc +#define writeVMSQ writeCASQ +#define readVMSQ readCASQ +#define makeVMSQ makeCASQ +#define VMSQueueStruc CASQueueStruc //#define thdAttrs NULL //For PThreads @@ -104,23 +109,25 @@ typedef struct { - SlaveScheduler slaveScheduler; - RequestHandler requestHandler; + SlaveScheduler slaveScheduler; + RequestHandler requestHandler; - SchedSlot **schedSlots; - SchedSlot **filledSlots; - int numToPrecede; + SchedSlot **schedSlots; + SchedSlot **filledSlots; + int numToPrecede; - volatile int stillRunning; + volatile int stillRunning; - VirtProcr *masterVirtPr; + VirtProcr *masterVirtPr; - void *semanticEnv; - void *OSEventStruc; //for future, when add I/O to BLIS + void *semanticEnv; + void *OSEventStruc; //for future, when add I/O to BLIS - void *coreLoopEndPt; //addr to jump to to shut down a coreLoop + void *coreLoopEndPt; //addr to jump to to shut down a coreLoop - int setupComplete; + int setupComplete; + + void *mallocChunk; } MasterEnv;