# HG changeset patch # User Merten Sach # Date 1305203021 -7200 # Node ID a49f0298015164f487009ae2e95d1f2cc176e3e1 # Parent 9c3107044f86c36fea3a8f72f64910b1363555be fixed: hist index error, zero devision diff -r 9c3107044f86 -r a49f02980151 CoreLoop.c --- a/CoreLoop.c Sat Nov 20 08:19:05 2010 +0100 +++ b/CoreLoop.c Thu May 12 14:23:41 2011 +0200 @@ -8,7 +8,7 @@ #include "VMS.h" #include "Queue_impl/BlockingQueue.h" -#include +//#include #include #include diff -r 9c3107044f86 -r a49f02980151 SwitchAnimators.h --- a/SwitchAnimators.h Sat Nov 20 08:19:05 2010 +0100 +++ b/SwitchAnimators.h Thu May 12 14:23:41 2011 +0200 @@ -1,237 +1,237 @@ -/* - * Copyright 2009 OpenSourceStewardshipFoundation.org - * Licensed under GNU General Public License version 2 - * - * Author: seanhalle@yahoo.com - * - */ - -#ifndef _SwitchAnimators_H -#define _SwitchAnimators_H -#define __USE_GNU - -/*Isolating code for switching between animators within these macros -- at - * some point will make switches to compile for 32 bit or for 64 bit, which - * having these isolated will make cleaner - * - *This also makes it easier to change architectures, at some point - *And it cleans the code up, having the ugly assembly out of the way - */ - -/*Originally, let GCC handle input and output variables, which - * worked fine with -O0, but with -O3, it eliminated what it - * thought was un-used stores -- to fix this, am now hard-coding - * the offsets of the fields of VirtProcr and VMSMasterEnv data - * structs into the assembly for switching between VPs. - *To see what the offsets are, copy the following code to - * someplace, set compile to -O0 so it doesn't optimize, and - * set a break-point on the first line. In DDD or Eclipse, look - * at the disassembly to see what it compiled for the offsets. - * - void *foo; - foo = currPr->stackPtr; \ - foo = currPr->framePtr; \ - foo = currPr->nextInstrPt; \ - foo = currPr->coreLoopStackPtr; - foo = currPr->coreLoopFramePtr; - foo = _VMSMasterEnv->coreLoopStartPt; - foo = _VMSMasterEnv->coreLoopEndPt; - foo = _VMSMasterEnv->masterLock; - - * VirtProcr offsets: - * 0xc stackPtr - * 0x10 framePtr - * 0x14 nextInstrPt - * 0x1c coreLoopFramePtr - * 0x20 coreLoopStackPtr - * - * _VMSMasterEnv offsets: - * 0x24 coreLoopStartPt - * 0x28 coreLoopEndPt - * 0x30 masterLock - * - *For reference on the switch-VP assembly, the %%eax, %%ebx, %%ecx are - * general purpose registers -- the "clobber" at the end tells GCC that the - * values in the listed registers are overwritten inside the assembly, so - * that GCC doesn't rely on keeping values in registers across the assembly. - *The "input" tells GCC to generate the assembly form of the variable name. - *The "%0" and "%1" mean the first and second items in the "input" list at - * the bottom, respectively. So, where %0 appears, GCC looks at the bottom, - * gets the first item it sees, generates the assembly for accessing that - * variable, and replaces %0 with that. - * - *%%ebp is the frame-ptr register and %%esp is the stack-ptr register - */ - -//=========================== MasterVP to CoreLoop ========================== -// - //Save stack ptr and frame, restore CoreLoop's stack and frame, - // and clear the MasterLock - //GCC's -O3 messes with this -- go through generated -- protect somehow - // -#define masterSwitchToCoreLoop( masterPr ) \ - void *stackPtrAddr, *framePtrAddr; \ - volatile void *masterLockAddr; \ - void *jmpPt, *coreLoopFramePtr, *coreLoopStackPtr; \ -\ - masterLockAddr = &(_VMSMasterEnv->masterLock); \ -\ - jmpPt = _VMSMasterEnv->coreLoopStartPt; \ - coreLoopStackPtr = masterPr->coreLoopStackPtr; \ - coreLoopFramePtr = masterPr->coreLoopFramePtr; \ -\ - asm volatile("mov %0, %%ecx; \ - mov %1, %%ebx; \ - mov %%ebx, %%eax; \ - add $0x10, %%eax; \ - movl %%esp, (%%eax); \ - mov %%ebx, %%eax; \ - add $0x14, %%eax; \ - movl %%ebp, (%%eax); \ - movl %2, %%eax; \ - movl %3, %%esp; \ - movl %4, %%ebp; \ - movl $0x0, (%%ecx); \ - jmp %%eax" \ - /* outputs */ : "=g"(masterLockAddr) \ - /* inputs */ : "g"(masterPr), "g" (jmpPt), "g" (coreLoopStackPtr), \ - "g" (coreLoopFramePtr) \ - /* clobber */ : "memory", "%eax", "%ebx", "%ecx", "%edx", "%edi", "%esi" \ - ); - -// asm volatile("movl %0, %%eax; \ - movl %%esp, (%%eax); \ - movl %1, %%eax; \ - movl %%ebp, (%%eax); \ - movl %2, %%ebx; \ - movl %3, %%eax; \ - movl %4, %%esp; \ - movl %5, %%ebp; \ - movl $0x0, (%%ebx); \ - jmp %%eax;" \ - /* outputs */ : "=g" (stackPtrAddr), "=g" (framePtrAddr), \ - "=g"(masterLockAddr) \ - /* inputs */ : "g" (jmpPt), "g"(coreLoopStackPtr), "g"(coreLoopFramePtr)\ - /* clobber */ : "memory", "%eax", "%ebx", "%ecx", "%edx", "%edi", "%esi" \ - );//can probably make clobber list empty -- but safe for now - - -//=========================== SlaveVP to CoreLoop =========================== -// - -#define SwitchToCoreLoop( animatingPr ) \ - void *jmpPt, *coreLoopStackPtr; \ - void *coreLoopFramePtr; \ -\ - jmpPt = _VMSMasterEnv->coreLoopStartPt; \ - coreLoopStackPtr = animatingPr->coreLoopStackPtr; \ - coreLoopFramePtr = animatingPr->coreLoopFramePtr; \ -\ - asm volatile("mov %0,%%ebx; \ - mov %%ebx, %%eax; \ - add $0x10, %%eax; \ - movl %%esp, (%%eax); \ - mov %%ebx, %%eax; \ - add $0x14, %%eax; \ - movl %%ebp, (%%eax); \ - movl %1, %%eax; \ - movl %2, %%esp; \ - movl %3, %%ebp; \ - jmp %%eax" \ - /* outputs */ : \ - /* inputs */ : "g"(animatingPr), "g" (jmpPt), "g" (coreLoopStackPtr), \ - "g" (coreLoopFramePtr) \ - /* clobber */ : "memory", "%eax", "%ebx", "%ecx", "%edx", "%edi", "%esi" \ - ); - - /*Save the virt procr's stack and frame ptrs*/ \ -// asm volatile("movl %0, %%eax; \ - movl %%esp, (%%eax); \ - movl %1, %%eax; \ - movl %%ebp, (%%eax) "\ - /* outputs */ : "=g" (stackPtrAddr), "=g" (framePtrAddr) \ - /* inputs */ : \ - /* clobber */ : "%eax" \ - ); \ -\ - /*restore coreloop's frame ptr, then jump back to "start" of core loop*/\ - /*Note, GCC compiles to assembly that saves esp and ebp in the stack*/ \ - /* frame -- so have to explicitly do assembly that saves to memory*/ \ - asm volatile("movl %0, %%eax; \ - movl %1, %%esp; \ - movl %2, %%ebp; \ - jmp %%eax " \ - /* outputs */ : \ - /* inputs */ : "m" (jmpPt), "m"(coreLoopStackPtr), "m"(coreLoopFramePtr)\ - /* clobber */ : "memory", "%eax", "%ebx", "%ecx", "%edx", "%edi","%esi" \ - ); - //list everything as clobbered to force GCC to save all - // live vars that are in regs on stack before this - // assembly, so that stack pointer is correct, before jmp - - - -//============================== CoreLoop to VP ============================= -// - //Save the core loop's stack and frame pointers into virt procr struct - // then switch to stack ptr and frame ptr of virt procr & jmp to it - //This was a pain to get right because GCC converts the "(jmpPt)" to - // frame-relative mem-op -- so generated machine code first changed the - // frame pointer, then tried to jump to an addr stored on stack, which - // it accessed as an offset from frame-ptr! (wrong frame-ptr now) - //Explicitly loading into eax before changing frame-ptr fixed it - //Also, it turns "(currPr->coreLoopFramePtr)" into a temporary on the - // stack, so "movl %%ebp, %0" saves to the temp, NOT the data-struc! - - - //switch to virt procr's stack and frame ptr then jump to virt procr fn -/* VirtProcr offsets: - * 0xc stackPtr - * 0x10 framePtr - * 0x14 nextInstrPt - * 0x1c coreLoopFramePtr - * 0x20 coreLoopStackPtr - * - * _VMSMasterEnv offsets: - * 0x24 coreLoopStartPt - * 0x28 coreLoopEndPt - * 0x30 masterLock - */ -#define SwitchToVP( currPr ) \ - asm volatile("movl %0, %%ebx; \ - movl %%esp, 0x20(%%ebx); \ - movl %%ebp, 0x1c(%%ebx); \ - movl 0x14(%%ebx), %%eax; \ - movl 0x0c(%%ebx), %%esp; \ - movl 0x10(%%ebx), %%ebp; \ - jmp *%%eax" \ - /* outputs */ : \ - /* inputs */ : "g"(currPr) \ - /* clobber */ : "memory", "%eax", "%ebx", "%ecx", "%edx", "%edi", "%esi" \ - ); - -// void *stackPtr, *framePtr, *jmpPt; \ -\ - stackPtr = currPr->stackPtr; \ - framePtr = currPr->framePtr; \ - jmpPt = currPr->nextInstrPt; \ -\ - asm volatile("mov %0,%%ebx; \ - mov %%ebx, %%eax; \ - add $0x1c, %%eax; \ - movl %%esp, (%%eax); \ - mov %%ebx, %%eax; \ - add $0x20, %%eax; \ - movl %%ebp, (%%eax); \ - movl %1, %%eax; \ - movl %2, %%esp; \ - movl %3, %%ebp; \ - jmp %%eax" \ - /* outputs */ : \ - /* inputs */ : "g"(currPr), "g" (jmpPt), "g" (stackPtr), "g" (framePtr) \ - /* clobber */ : "memory", "%eax", "%ebx", "%ecx", "%edx", "%edi", "%esi" \ - ); - - -#endif /* _SwitchAnimators_H */ - +/* + * Copyright 2009 OpenSourceStewardshipFoundation.org + * Licensed under GNU General Public License version 2 + * + * Author: seanhalle@yahoo.com + * + */ + +#ifndef _SwitchAnimators_H +#define _SwitchAnimators_H +#define __USE_GNU + +/*Isolating code for switching between animators within these macros -- at + * some point will make switches to compile for 32 bit or for 64 bit, which + * having these isolated will make cleaner + * + *This also makes it easier to change architectures, at some point + *And it cleans the code up, having the ugly assembly out of the way + */ + +/*Originally, let GCC handle input and output variables, which + * worked fine with -O0, but with -O3, it eliminated what it + * thought was un-used stores -- to fix this, am now hard-coding + * the offsets of the fields of VirtProcr and VMSMasterEnv data + * structs into the assembly for switching between VPs. + *To see what the offsets are, copy the following code to + * someplace, set compile to -O0 so it doesn't optimize, and + * set a break-point on the first line. In DDD or Eclipse, look + * at the disassembly to see what it compiled for the offsets. + * + void *foo; + foo = currPr->stackPtr; \ + foo = currPr->framePtr; \ + foo = currPr->nextInstrPt; \ + foo = currPr->coreLoopStackPtr; + foo = currPr->coreLoopFramePtr; + foo = _VMSMasterEnv->coreLoopStartPt; + foo = _VMSMasterEnv->coreLoopEndPt; + foo = _VMSMasterEnv->masterLock; + + * VirtProcr offsets: + * 0xc stackPtr + * 0x10 framePtr + * 0x14 nextInstrPt + * 0x1c coreLoopFramePtr + * 0x20 coreLoopStackPtr + * + * _VMSMasterEnv offsets: + * 0x24 coreLoopStartPt + * 0x28 coreLoopEndPt + * 0x30 masterLock + * + *For reference on the switch-VP assembly, the %%eax, %%ebx, %%ecx are + * general purpose registers -- the "clobber" at the end tells GCC that the + * values in the listed registers are overwritten inside the assembly, so + * that GCC doesn't rely on keeping values in registers across the assembly. + *The "input" tells GCC to generate the assembly form of the variable name. + *The "%0" and "%1" mean the first and second items in the "input" list at + * the bottom, respectively. So, where %0 appears, GCC looks at the bottom, + * gets the first item it sees, generates the assembly for accessing that + * variable, and replaces %0 with that. + * + *%%ebp is the frame-ptr register and %%esp is the stack-ptr register + */ + +//=========================== MasterVP to CoreLoop ========================== +// + //Save stack ptr and frame, restore CoreLoop's stack and frame, + // and clear the MasterLock + //GCC's -O3 messes with this -- go through generated -- protect somehow + // +#define masterSwitchToCoreLoop( masterPr ) \ + void *stackPtrAddr, *framePtrAddr; \ + volatile void *masterLockAddr; \ + void *jmpPt, *coreLoopFramePtr, *coreLoopStackPtr; \ +\ + masterLockAddr = &(_VMSMasterEnv->masterLock); \ +\ + jmpPt = _VMSMasterEnv->coreLoopStartPt; \ + coreLoopStackPtr = masterPr->coreLoopStackPtr; \ + coreLoopFramePtr = masterPr->coreLoopFramePtr; \ +\ + asm volatile("mov %0, %%ecx; \ + mov %1, %%ebx; \ + mov %%ebx, %%eax; \ + add $0x10, %%eax; \ + movl %%esp, (%%eax); \ + mov %%ebx, %%eax; \ + add $0x14, %%eax; \ + movl %%ebp, (%%eax); \ + movl %2, %%eax; \ + movl %3, %%esp; \ + movl %4, %%ebp; \ + movl $0x0, (%%ecx); \ + jmp %%eax" \ + /* outputs */ : "=g"(masterLockAddr) \ + /* inputs */ : "g"(masterPr), "g" (jmpPt), "g" (coreLoopStackPtr), \ + "g" (coreLoopFramePtr) \ + /* clobber */ : "memory", "%eax", "%ebx", "%ecx", "%edx", "%edi", "%esi" \ + ); + +// asm volatile("movl %0, %%eax; \ + movl %%esp, (%%eax); \ + movl %1, %%eax; \ + movl %%ebp, (%%eax); \ + movl %2, %%ebx; \ + movl %3, %%eax; \ + movl %4, %%esp; \ + movl %5, %%ebp; \ + movl $0x0, (%%ebx); \ + jmp %%eax;" \ + /* outputs */ : "=g" (stackPtrAddr), "=g" (framePtrAddr), \ + "=g"(masterLockAddr) \ + /* inputs */ : "g" (jmpPt), "g"(coreLoopStackPtr), "g"(coreLoopFramePtr)\ + /* clobber */ : "memory", "%eax", "%ebx", "%ecx", "%edx", "%edi", "%esi" \ + );//can probably make clobber list empty -- but safe for now + + +//=========================== SlaveVP to CoreLoop =========================== +// + +#define SwitchToCoreLoop( animatingPr ) \ + void *jmpPt, *coreLoopStackPtr; \ + void *coreLoopFramePtr; \ +\ + jmpPt = _VMSMasterEnv->coreLoopStartPt; \ + coreLoopStackPtr = animatingPr->coreLoopStackPtr; \ + coreLoopFramePtr = animatingPr->coreLoopFramePtr; \ +\ + asm volatile("mov %0,%%ebx; \ + mov %%ebx, %%eax; \ + add $0x10, %%eax; \ + movl %%esp, (%%eax); \ + mov %%ebx, %%eax; \ + add $0x14, %%eax; \ + movl %%ebp, (%%eax); \ + movl %1, %%eax; \ + movl %2, %%esp; \ + movl %3, %%ebp; \ + jmp %%eax" \ + /* outputs */ : \ + /* inputs */ : "g"(animatingPr), "g" (jmpPt), "g" (coreLoopStackPtr), \ + "g" (coreLoopFramePtr) \ + /* clobber */ : "memory", "%eax", "%ebx", "%ecx", "%edx", "%edi", "%esi" \ + ); + + /*Save the virt procr's stack and frame ptrs*/ \ +// asm volatile("movl %0, %%eax; \ + movl %%esp, (%%eax); \ + movl %1, %%eax; \ + movl %%ebp, (%%eax) "\ + /* outputs */ : "=g" (stackPtrAddr), "=g" (framePtrAddr) \ + /* inputs */ : \ + /* clobber */ : "%eax" \ + ); \ +\ + /*restore coreloop's frame ptr, then jump back to "start" of core loop*/\ + /*Note, GCC compiles to assembly that saves esp and ebp in the stack*/ \ + /* frame -- so have to explicitly do assembly that saves to memory*/ \ + asm volatile("movl %0, %%eax; \ + movl %1, %%esp; \ + movl %2, %%ebp; \ + jmp %%eax " \ + /* outputs */ : \ + /* inputs */ : "m" (jmpPt), "m"(coreLoopStackPtr), "m"(coreLoopFramePtr)\ + /* clobber */ : "memory", "%eax", "%ebx", "%ecx", "%edx", "%edi","%esi" \ + ); + //list everything as clobbered to force GCC to save all + // live vars that are in regs on stack before this + // assembly, so that stack pointer is correct, before jmp + + + +//============================== CoreLoop to VP ============================= +// + //Save the core loop's stack and frame pointers into virt procr struct + // then switch to stack ptr and frame ptr of virt procr & jmp to it + //This was a pain to get right because GCC converts the "(jmpPt)" to + // frame-relative mem-op -- so generated machine code first changed the + // frame pointer, then tried to jump to an addr stored on stack, which + // it accessed as an offset from frame-ptr! (wrong frame-ptr now) + //Explicitly loading into eax before changing frame-ptr fixed it + //Also, it turns "(currPr->coreLoopFramePtr)" into a temporary on the + // stack, so "movl %%ebp, %0" saves to the temp, NOT the data-struc! + + + //switch to virt procr's stack and frame ptr then jump to virt procr fn +/* VirtProcr offsets: + * 0xc stackPtr + * 0x10 framePtr + * 0x14 nextInstrPt + * 0x1c coreLoopFramePtr + * 0x20 coreLoopStackPtr + * + * _VMSMasterEnv offsets: + * 0x24 coreLoopStartPt + * 0x28 coreLoopEndPt + * 0x30 masterLock + */ +#define SwitchToVP( currPr ) \ + asm volatile("movl %0, %%ebx; \ + movl %%esp, 0x20(%%ebx); \ + movl %%ebp, 0x1c(%%ebx); \ + movl 0x14(%%ebx), %%eax; \ + movl 0x0c(%%ebx), %%esp; \ + movl 0x10(%%ebx), %%ebp; \ + jmp *%%eax" \ + /* outputs */ : \ + /* inputs */ : "g"(currPr) \ + /* clobber */ : "memory", "%eax", "%ebx", "%ecx", "%edx", "%edi", "%esi" \ + ); + +// void *stackPtr, *framePtr, *jmpPt; \ +\ + stackPtr = currPr->stackPtr; \ + framePtr = currPr->framePtr; \ + jmpPt = currPr->nextInstrPt; \ +\ + asm volatile("mov %0,%%ebx; \ + mov %%ebx, %%eax; \ + add $0x1c, %%eax; \ + movl %%esp, (%%eax); \ + mov %%ebx, %%eax; \ + add $0x20, %%eax; \ + movl %%ebp, (%%eax); \ + movl %1, %%eax; \ + movl %2, %%esp; \ + movl %3, %%ebp; \ + jmp %%eax" \ + /* outputs */ : \ + /* inputs */ : "g"(currPr), "g" (jmpPt), "g" (stackPtr), "g" (framePtr) \ + /* clobber */ : "memory", "%eax", "%ebx", "%ecx", "%edx", "%edi", "%esi" \ + ); + + +#endif /* _SwitchAnimators_H */ + diff -r 9c3107044f86 -r a49f02980151 VMS.h --- a/VMS.h Sat Nov 20 08:19:05 2010 +0100 +++ b/VMS.h Thu May 12 14:23:41 2011 +0200 @@ -1,473 +1,473 @@ -/* - * Copyright 2009 OpenSourceStewardshipFoundation.org - * Licensed under GNU General Public License version 2 - * - * Author: seanhalle@yahoo.com - * - */ - -#ifndef _VMS_H -#define _VMS_H -#define __USE_GNU - -#include "VMS_primitive_data_types.h" -#include "Queue_impl/PrivateQueue.h" -#include "Histogram/Histogram.h" -#include "DynArray/DynArray.h" -#include "Hash_impl/PrivateHash.h" -#include "vmalloc.h" - -#include -#include - - -//=============================== Debug =================================== -// - //When SEQUENTIAL is defined, VMS does sequential exe in the main thread - // It still does co-routines and all the mechanisms are the same, it just - // has only a single thread and animates VPs one at a time -//#define SEQUENTIAL - -//#define USE_WORK_STEALING - - //turns on the probe-instrumentation in the application -- when not - // defined, the calls to the probe functions turn into comments -#define STATS__ENABLE_PROBES -//#define TURN_ON_DEBUG_PROBES - - //These defines turn types of bug messages on and off - // be sure debug messages are un-commented (next block of defines) -#define dbgAppFlow TRUE /* Top level flow of application code -- general*/ -#define dbgProbes FALSE /* for issues inside probes themselves*/ -#define dbgB2BMaster FALSE /* in coreloop, back to back master VPs*/ -#define dbgRqstHdlr FALSE /* in request handler code*/ - - //Comment or un- the substitute half to turn on/off types of debug message -#define DEBUG( bool, msg) \ -// if( bool){ printf(msg); fflush(stdin);} -#define DEBUG1( bool, msg, param) \ -// if(bool){printf(msg, param); fflush(stdin);} -#define DEBUG2( bool, msg, p1, p2) \ -// if(bool) {printf(msg, p1, p2); fflush(stdin);} - -#define ERROR(msg) printf(msg); fflush(stdin); -#define ERROR1(msg, param) printf(msg, param); fflush(stdin); -#define ERROR2(msg, p1, p2) printf(msg, p1, p2); fflush(stdin); - -//=========================== STATS ======================= - - //when MEAS__TIME_STAMP_SUSP is defined, causes code to be inserted and - // compiled-in that saves the low part of the time stamp count just before - // suspending a processor and just after resuming that processor. It is - // saved into a field added to VirtProcr. Have to sanity-check for - // rollover of low portion into high portion. -//#define MEAS__TIME_STAMP_SUSP -//#define MEAS__TIME_MASTER -#define MEAS__TIME_PLUGIN -#define MEAS__TIME_MALLOC -//#define MEAS__TIME_MASTER_LOCK -#define MEAS__NUM_TIMES_TO_RUN 100000 - - //For code that calculates normalization-offset between TSC counts of - // different cores. -#define NUM_TSC_ROUND_TRIPS 10 - - -//========================= Hardware related Constants ===================== - //This value is the number of hardware threads in the shared memory - // machine -#define NUM_CORES 4 - - // tradeoff amortizing master fixed overhead vs imbalance potential - // when work-stealing, can make bigger, at risk of losing cache affinity -#define NUM_SCHED_SLOTS 5 - -#define MIN_WORK_UNIT_CYCLES 20000 - -#define MASTERLOCK_RETRIES 10000 - - // stack size in virtual processors created -#define VIRT_PROCR_STACK_SIZE 0x4000 /* 16K */ - - // memory for VMS__malloc -#define MALLOC_ADDITIONAL_MEM_FROM_OS_SIZE 0x10000000 /* 256M */ - - -//============================== - -#define SUCCESS 0 - -#define writeVMSQ writePrivQ -#define readVMSQ readPrivQ -#define makeVMSQ makeVMSPrivQ -#define numInVMSQ numInPrivQ -#define VMSQueueStruc PrivQueueStruc - - - -//=========================================================================== -typedef unsigned long long TSCount; - -typedef struct _SchedSlot SchedSlot; -typedef struct _VMSReqst VMSReqst; -typedef struct _VirtProcr VirtProcr; -typedef struct _IntervalProbe IntervalProbe; -typedef struct _GateStruc GateStruc; - - -typedef VirtProcr * (*SlaveScheduler) ( void *, int ); //semEnv, coreIdx -typedef void (*RequestHandler) ( VirtProcr *, void * ); //prWReqst, semEnv -typedef void (*VirtProcrFnPtr) ( void *, VirtProcr * ); //initData, animPr -typedef void VirtProcrFn ( void *, VirtProcr * ); //initData, animPr -typedef void (*ResumePrFnPtr) ( VirtProcr *, void * ); - - -//============= Requests =========== -// - -enum VMSReqstType //avoid starting enums at 0, for debug reasons - { - semantic = 1, - createReq, - dissipate, - VMSSemantic //goes with VMSSemReqst below - }; - -struct _VMSReqst - { - enum VMSReqstType reqType;//used for dissipate and in future for IO requests - void *semReqData; - - VMSReqst *nextReqst; - }; -//VMSReqst - -enum VMSSemReqstType //These are equivalent to semantic requests, but for - { // VMS's services available directly to app, like OS - createProbe = 1, // and probe services -- like a VMS-wide built-in lang - openFile, - otherIO - }; - -typedef struct - { enum VMSSemReqstType reqType; - VirtProcr *requestingPr; - char *nameStr; //for create probe - } - VMSSemReq; - - -//==================== Core data structures =================== - -struct _SchedSlot - { - int workIsDone; - int needsProcrAssigned; - VirtProcr *procrAssignedToSlot; - }; -//SchedSlot - -/*WARNING: re-arranging this data structure could cause VP switching - * assembly code to fail -- hard-codes offsets of fields - */ -struct _VirtProcr - { int procrID; //for debugging -- count up each time create - int coreAnimatedBy; - void *startOfStack; - void *stackPtr; - void *framePtr; - void *nextInstrPt; - - void *coreLoopStartPt; //allows proto-runtime to be linked later - void *coreLoopFramePtr; //restore before jmp back to core loop - void *coreLoopStackPtr; //restore before jmp back to core loop - - void *initialData; - - SchedSlot *schedSlot; - VMSReqst *requests; - - void *semanticData; //this lives here for the life of VP - void *dataRetFromReq;//values returned from plugin to VP go here - - //=========== MEASUREMENT STUFF ========== - #ifdef MEAS__TIME_STAMP_SUSP - unsigned int preSuspTSCLow; - unsigned int postSuspTSCLow; - #endif - #ifdef MEAS__TIME_MASTER /* in VirtProcr because multiple masterVPs*/ - unsigned int startMasterTSCLow; - unsigned int endMasterTSCLow; - #endif - //======================================== - - float64 createPtInSecs; //have space but don't use on some configs - }; -//VirtProcr - - -/*WARNING: re-arranging this data structure could cause VP-switching - * assembly code to fail -- hard-codes offsets of fields - * (because -O3 messes with things otherwise) - */ -typedef struct - { - SlaveScheduler slaveScheduler; - RequestHandler requestHandler; - - SchedSlot ***allSchedSlots; - VMSQueueStruc **readyToAnimateQs; - VirtProcr **masterVPs; - - void *semanticEnv; - void *OSEventStruc; //for future, when add I/O to BLIS - MallocProlog *freeListHead; - int32 amtOfOutstandingMem; //total currently allocated - - void *coreLoopStartPt;//addr to jump to to re-enter coreLoop - void *coreLoopEndPt; //addr to jump to to shut down a coreLoop - - int32 setupComplete; - int32 masterLock; - - int32 numMasterInARow[NUM_CORES];//detect back-to-back masterVP - GateStruc *workStealingGates[ NUM_CORES ]; //concurrent work-steal - int32 workStealingLock; - - int32 numProcrsCreated; //gives ordering to processor creation - - //=========== MEASUREMENT STUFF ============= - IntervalProbe **intervalProbes; - PrivDynArrayInfo *dynIntervalProbesInfo; - HashTable *probeNameHashTbl; - int32 masterCreateProbeID; - float64 createPtInSecs; - Histogram **measHists; - PrivDynArrayInfo *measHistsInfo; - #ifdef MEAS__TIME_PLUGIN - Histogram *reqHdlrLowTimeHist; - Histogram *reqHdlrHighTimeHist; - #endif - #ifdef MEAS__TIME_MALLOC - Histogram *mallocTimeHist; - Histogram *freeTimeHist; - #endif - #ifdef MEAS__TIME_MASTER_LOCK - Histogram *masterLockLowTimeHist; - Histogram *masterLockHighTimeHist; - #endif - } -MasterEnv; - -//========================= Extra Stuff Data Strucs ======================= -typedef struct - { - - } -VMSExcp; - -struct _GateStruc - { - int32 gateClosed; - int32 preGateProgress; - int32 waitProgress; - int32 exitProgress; - }; -//GateStruc - -//======================= OS Thread related =============================== - -void * coreLoop( void *paramsIn ); //standard PThreads fn prototype -void * coreLoop_Seq( void *paramsIn ); //standard PThreads fn prototype -void masterLoop( void *initData, VirtProcr *masterPr ); - - -typedef struct - { - void *endThdPt; - unsigned int coreNum; - } -ThdParams; - -pthread_t coreLoopThdHandles[ NUM_CORES ]; //pthread's virt-procr state -ThdParams *coreLoopThdParams [ NUM_CORES ]; -pthread_mutex_t suspendLock; -pthread_cond_t suspend_cond; - - - -//===================== Global Vars =================== - -volatile MasterEnv *_VMSMasterEnv; - - - - -//=========================== Function Prototypes ========================= - - -//========== Setup and shutdown ========== -void -VMS__init(); - -void -VMS__init_Seq(); - -void -VMS__start_the_work_then_wait_until_done(); - -void -VMS__start_the_work_then_wait_until_done_Seq(); - -VirtProcr * -VMS__create_procr( VirtProcrFnPtr fnPtr, void *initialData ); - -void -VMS__dissipate_procr( VirtProcr *procrToDissipate ); - - //Use this to create processor inside entry point & other places outside - // the VMS system boundary (IE, not run in slave nor Master) -VirtProcr * -VMS_ext__create_procr( VirtProcrFnPtr fnPtr, void *initialData ); - -void -VMS_ext__dissipate_procr( VirtProcr *procrToDissipate ); - -void -VMS__throw_exception( char *msgStr, VirtProcr *reqstPr, VMSExcp *excpData ); - -void -VMS__shutdown(); - -void -VMS__cleanup_at_end_of_shutdown(); - -void * -VMS__give_sem_env_for( VirtProcr *animPr ); - - -//============== Request Related =============== - -void -VMS__suspend_procr( VirtProcr *callingPr ); - -inline void -VMS__add_sem_request_in_mallocd_VMSReqst( void *semReqData, VirtProcr *callingPr ); - -inline void -VMS__send_sem_request( void *semReqData, VirtProcr *callingPr ); - -void -VMS__send_create_procr_req( void *semReqData, VirtProcr *reqstingPr ); - -void inline -VMS__send_dissipate_req( VirtProcr *prToDissipate ); - -inline void -VMS__send_VMSSem_request( void *semReqData, VirtProcr *callingPr ); - -VMSReqst * -VMS__take_next_request_out_of( VirtProcr *procrWithReq ); - -inline void * -VMS__take_sem_reqst_from( VMSReqst *req ); - -//======================== STATS ====================== - -//===== RDTSC wrapper ===== - -#define saveTimeStampCountInto(low, high) \ - asm volatile("RDTSC; \ - movl %%eax, %0; \ - movl %%edx, %1;" \ - /* outputs */ : "=m" (low), "=m" (high)\ - /* inputs */ : \ - /* clobber */ : "%eax", "%edx" \ - ); - -#define saveLowTimeStampCountInto(low) \ - asm volatile("RDTSC; \ - movl %%eax, %0;" \ - /* outputs */ : "=m" (low) \ - /* inputs */ : \ - /* clobber */ : "%eax", "%edx" \ - ); - -//==================== -#define makeAMeasHist( idx, name, numBins, startVal, binWidth ) \ - makeHighestDynArrayIndexBeAtLeast( _VMSMasterEnv->measHistsInfo, idx ); \ - _VMSMasterEnv->measHists[idx] = \ - makeFixedBinHist( numBins, startVal, binWidth, name ); - - -#define MEAS__SUB_CREATE /*turn on/off subtraction of create from plugin*/ -#define createHistIdx 1 -#define mutexLockHistIdx 2 -#define mutexUnlockHistIdx 3 -#define condWaitHistIdx 4 -#define condSignalHistIdx 5 - - -#define MakeTheMeasHists \ - _VMSMasterEnv->measHistsInfo = \ - makePrivDynArrayOfSize( &(_VMSMasterEnv->measHists), 200);\ - makeAMeasHist( createHistIdx, "Create", 50, 0, 200 ) \ - makeAMeasHist( mutexLockHistIdx, "mutex lock", 50, 0, 100 ) \ - makeAMeasHist( mutexUnlockHistIdx, "mutex unlock", 50, 0, 100 ) \ - makeAMeasHist( condWaitHistIdx, "cond wait", 50, 0, 100 ) \ - makeAMeasHist( condSignalHistIdx, "cond signal", 50, 0, 100 ) - -#define Meas_startCreate \ - int32 startStamp, endStamp; \ - saveLowTimeStampCountInto( startStamp ); \ - -#define Meas_endCreate \ - saveLowTimeStampCountInto( endStamp ); \ - addIntervalToHist( startStamp, endStamp, \ - _VMSMasterEnv->measHists[ createHistIdx ] ); - -#define Meas_startMutexLock \ - int32 startStamp, endStamp; \ - saveLowTimeStampCountInto( startStamp ); \ - -#define Meas_endMutexLock \ - saveLowTimeStampCountInto( endStamp ); \ - addIntervalToHist( startStamp, endStamp, \ - _VMSMasterEnv->measHists[ mutexLockHistIdx ] ); - -#define Meas_startMutexUnlock \ - int32 startStamp, endStamp; \ - saveLowTimeStampCountInto( startStamp ); \ - -#define Meas_endMutexUnlock \ - saveLowTimeStampCountInto( endStamp ); \ - addIntervalToHist( startStamp, endStamp, \ - _VMSMasterEnv->measHists[ mutexUnlockHistIdx ] ); - -#define Meas_startCondWait \ - int32 startStamp, endStamp; \ - saveLowTimeStampCountInto( startStamp ); \ - -#define Meas_endCondWait \ - saveLowTimeStampCountInto( endStamp ); \ - addIntervalToHist( startStamp, endStamp, \ - _VMSMasterEnv->measHists[ condWaitHistIdx ] ); - -#define Meas_startCondSignal \ - int32 startStamp, endStamp; \ - saveLowTimeStampCountInto( startStamp ); \ - -#define Meas_endCondSignal \ - saveLowTimeStampCountInto( endStamp ); \ - addIntervalToHist( startStamp, endStamp, \ - _VMSMasterEnv->measHists[ condSignalHistIdx ] ); - - -//===== - -#include "SwitchAnimators.h" -#include "probes.h" -#include "vutilities.h" - -#endif /* _VMS_H */ - +/* + * Copyright 2009 OpenSourceStewardshipFoundation.org + * Licensed under GNU General Public License version 2 + * + * Author: seanhalle@yahoo.com + * + */ + +#ifndef _VMS_H +#define _VMS_H +#define __USE_GNU + +#include "VMS_primitive_data_types.h" +#include "Queue_impl/PrivateQueue.h" +#include "Histogram/Histogram.h" +#include "DynArray/DynArray.h" +#include "Hash_impl/PrivateHash.h" +#include "vmalloc.h" + +#include +#include + + +//=============================== Debug =================================== +// + //When SEQUENTIAL is defined, VMS does sequential exe in the main thread + // It still does co-routines and all the mechanisms are the same, it just + // has only a single thread and animates VPs one at a time +//#define SEQUENTIAL + +//#define USE_WORK_STEALING + + //turns on the probe-instrumentation in the application -- when not + // defined, the calls to the probe functions turn into comments +#define STATS__ENABLE_PROBES +//#define TURN_ON_DEBUG_PROBES + + //These defines turn types of bug messages on and off + // be sure debug messages are un-commented (next block of defines) +#define dbgAppFlow TRUE /* Top level flow of application code -- general*/ +#define dbgProbes FALSE /* for issues inside probes themselves*/ +#define dbgB2BMaster FALSE /* in coreloop, back to back master VPs*/ +#define dbgRqstHdlr FALSE /* in request handler code*/ + + //Comment or un- the substitute half to turn on/off types of debug message +#define DEBUG( bool, msg) \ +// if( bool){ printf(msg); fflush(stdin);} +#define DEBUG1( bool, msg, param) \ +// if(bool){printf(msg, param); fflush(stdin);} +#define DEBUG2( bool, msg, p1, p2) \ +// if(bool) {printf(msg, p1, p2); fflush(stdin);} + +#define ERROR(msg) printf(msg); +#define ERROR1(msg, param) printf(msg, param); +#define ERROR2(msg, p1, p2) printf(msg, p1, p2); + +//=========================== STATS ======================= + + //when MEAS__TIME_STAMP_SUSP is defined, causes code to be inserted and + // compiled-in that saves the low part of the time stamp count just before + // suspending a processor and just after resuming that processor. It is + // saved into a field added to VirtProcr. Have to sanity-check for + // rollover of low portion into high portion. +//#define MEAS__TIME_STAMP_SUSP +//#define MEAS__TIME_MASTER +#define MEAS__TIME_PLUGIN +#define MEAS__TIME_MALLOC +//#define MEAS__TIME_MASTER_LOCK +#define MEAS__NUM_TIMES_TO_RUN 100000 + + //For code that calculates normalization-offset between TSC counts of + // different cores. +#define NUM_TSC_ROUND_TRIPS 10 + + +//========================= Hardware related Constants ===================== + //This value is the number of hardware threads in the shared memory + // machine +#define NUM_CORES 4 + + // tradeoff amortizing master fixed overhead vs imbalance potential + // when work-stealing, can make bigger, at risk of losing cache affinity +#define NUM_SCHED_SLOTS 5 + +#define MIN_WORK_UNIT_CYCLES 20000 + +#define MASTERLOCK_RETRIES 10000 + + // stack size in virtual processors created +#define VIRT_PROCR_STACK_SIZE 0x4000 /* 16K */ + + // memory for VMS__malloc +#define MALLOC_ADDITIONAL_MEM_FROM_OS_SIZE 0x10000000 /* 256M */ + + +//============================== + +#define SUCCESS 0 + +#define writeVMSQ writePrivQ +#define readVMSQ readPrivQ +#define makeVMSQ makeVMSPrivQ +#define numInVMSQ numInPrivQ +#define VMSQueueStruc PrivQueueStruc + + + +//=========================================================================== +typedef unsigned long long TSCount; + +typedef struct _SchedSlot SchedSlot; +typedef struct _VMSReqst VMSReqst; +typedef struct _VirtProcr VirtProcr; +typedef struct _IntervalProbe IntervalProbe; +typedef struct _GateStruc GateStruc; + + +typedef VirtProcr * (*SlaveScheduler) ( void *, int ); //semEnv, coreIdx +typedef void (*RequestHandler) ( VirtProcr *, void * ); //prWReqst, semEnv +typedef void (*VirtProcrFnPtr) ( void *, VirtProcr * ); //initData, animPr +typedef void VirtProcrFn ( void *, VirtProcr * ); //initData, animPr +typedef void (*ResumePrFnPtr) ( VirtProcr *, void * ); + + +//============= Requests =========== +// + +enum VMSReqstType //avoid starting enums at 0, for debug reasons + { + semantic = 1, + createReq, + dissipate, + VMSSemantic //goes with VMSSemReqst below + }; + +struct _VMSReqst + { + enum VMSReqstType reqType;//used for dissipate and in future for IO requests + void *semReqData; + + VMSReqst *nextReqst; + }; +//VMSReqst + +enum VMSSemReqstType //These are equivalent to semantic requests, but for + { // VMS's services available directly to app, like OS + createProbe = 1, // and probe services -- like a VMS-wide built-in lang + openFile, + otherIO + }; + +typedef struct + { enum VMSSemReqstType reqType; + VirtProcr *requestingPr; + char *nameStr; //for create probe + } + VMSSemReq; + + +//==================== Core data structures =================== + +struct _SchedSlot + { + int workIsDone; + int needsProcrAssigned; + VirtProcr *procrAssignedToSlot; + }; +//SchedSlot + +/*WARNING: re-arranging this data structure could cause VP switching + * assembly code to fail -- hard-codes offsets of fields + */ +struct _VirtProcr + { int procrID; //for debugging -- count up each time create + int coreAnimatedBy; + void *startOfStack; + void *stackPtr; + void *framePtr; + void *nextInstrPt; + + void *coreLoopStartPt; //allows proto-runtime to be linked later + void *coreLoopFramePtr; //restore before jmp back to core loop + void *coreLoopStackPtr; //restore before jmp back to core loop + + void *initialData; + + SchedSlot *schedSlot; + VMSReqst *requests; + + void *semanticData; //this lives here for the life of VP + void *dataRetFromReq;//values returned from plugin to VP go here + + //=========== MEASUREMENT STUFF ========== + #ifdef MEAS__TIME_STAMP_SUSP + unsigned int preSuspTSCLow; + unsigned int postSuspTSCLow; + #endif + #ifdef MEAS__TIME_MASTER /* in VirtProcr because multiple masterVPs*/ + unsigned int startMasterTSCLow; + unsigned int endMasterTSCLow; + #endif + //======================================== + + float64 createPtInSecs; //have space but don't use on some configs + }; +//VirtProcr + + +/*WARNING: re-arranging this data structure could cause VP-switching + * assembly code to fail -- hard-codes offsets of fields + * (because -O3 messes with things otherwise) + */ +typedef struct + { + SlaveScheduler slaveScheduler; + RequestHandler requestHandler; + + SchedSlot ***allSchedSlots; + VMSQueueStruc **readyToAnimateQs; + VirtProcr **masterVPs; + + void *semanticEnv; + void *OSEventStruc; //for future, when add I/O to BLIS + MallocProlog *freeListHead; + int32 amtOfOutstandingMem; //total currently allocated + + void *coreLoopStartPt;//addr to jump to to re-enter coreLoop + void *coreLoopEndPt; //addr to jump to to shut down a coreLoop + + int32 setupComplete; + int32 masterLock; + + int32 numMasterInARow[NUM_CORES];//detect back-to-back masterVP + GateStruc *workStealingGates[ NUM_CORES ]; //concurrent work-steal + int32 workStealingLock; + + int32 numProcrsCreated; //gives ordering to processor creation + + //=========== MEASUREMENT STUFF ============= + IntervalProbe **intervalProbes; + PrivDynArrayInfo *dynIntervalProbesInfo; + HashTable *probeNameHashTbl; + int32 masterCreateProbeID; + float64 createPtInSecs; + Histogram **measHists; + PrivDynArrayInfo *measHistsInfo; + #ifdef MEAS__TIME_PLUGIN + Histogram *reqHdlrLowTimeHist; + Histogram *reqHdlrHighTimeHist; + #endif + #ifdef MEAS__TIME_MALLOC + Histogram *mallocTimeHist; + Histogram *freeTimeHist; + #endif + #ifdef MEAS__TIME_MASTER_LOCK + Histogram *masterLockLowTimeHist; + Histogram *masterLockHighTimeHist; + #endif + } +MasterEnv; + +//========================= Extra Stuff Data Strucs ======================= +typedef struct + { + + } +VMSExcp; + +struct _GateStruc + { + int32 gateClosed; + int32 preGateProgress; + int32 waitProgress; + int32 exitProgress; + }; +//GateStruc + +//======================= OS Thread related =============================== + +void * coreLoop( void *paramsIn ); //standard PThreads fn prototype +void * coreLoop_Seq( void *paramsIn ); //standard PThreads fn prototype +void masterLoop( void *initData, VirtProcr *masterPr ); + + +typedef struct + { + void *endThdPt; + unsigned int coreNum; + } +ThdParams; + +pthread_t coreLoopThdHandles[ NUM_CORES ]; //pthread's virt-procr state +ThdParams *coreLoopThdParams [ NUM_CORES ]; +pthread_mutex_t suspendLock; +pthread_cond_t suspend_cond; + + + +//===================== Global Vars =================== + +volatile MasterEnv *_VMSMasterEnv; + + + + +//=========================== Function Prototypes ========================= + + +//========== Setup and shutdown ========== +void +VMS__init(); + +void +VMS__init_Seq(); + +void +VMS__start_the_work_then_wait_until_done(); + +void +VMS__start_the_work_then_wait_until_done_Seq(); + +VirtProcr * +VMS__create_procr( VirtProcrFnPtr fnPtr, void *initialData ); + +void +VMS__dissipate_procr( VirtProcr *procrToDissipate ); + + //Use this to create processor inside entry point & other places outside + // the VMS system boundary (IE, not run in slave nor Master) +VirtProcr * +VMS_ext__create_procr( VirtProcrFnPtr fnPtr, void *initialData ); + +void +VMS_ext__dissipate_procr( VirtProcr *procrToDissipate ); + +void +VMS__throw_exception( char *msgStr, VirtProcr *reqstPr, VMSExcp *excpData ); + +void +VMS__shutdown(); + +void +VMS__cleanup_at_end_of_shutdown(); + +void * +VMS__give_sem_env_for( VirtProcr *animPr ); + + +//============== Request Related =============== + +void +VMS__suspend_procr( VirtProcr *callingPr ); + +inline void +VMS__add_sem_request_in_mallocd_VMSReqst( void *semReqData, VirtProcr *callingPr ); + +inline void +VMS__send_sem_request( void *semReqData, VirtProcr *callingPr ); + +void +VMS__send_create_procr_req( void *semReqData, VirtProcr *reqstingPr ); + +void inline +VMS__send_dissipate_req( VirtProcr *prToDissipate ); + +inline void +VMS__send_VMSSem_request( void *semReqData, VirtProcr *callingPr ); + +VMSReqst * +VMS__take_next_request_out_of( VirtProcr *procrWithReq ); + +inline void * +VMS__take_sem_reqst_from( VMSReqst *req ); + +//======================== STATS ====================== + +//===== RDTSC wrapper ===== + +#define saveTimeStampCountInto(low, high) \ + asm volatile("RDTSC; \ + movl %%eax, %0; \ + movl %%edx, %1;" \ + /* outputs */ : "=m" (low), "=m" (high)\ + /* inputs */ : \ + /* clobber */ : "%eax", "%edx" \ + ); + +#define saveLowTimeStampCountInto(low) \ + asm volatile("RDTSC; \ + movl %%eax, %0;" \ + /* outputs */ : "=m" (low) \ + /* inputs */ : \ + /* clobber */ : "%eax", "%edx" \ + ); + +//==================== +#define makeAMeasHist( idx, name, numBins, startVal, binWidth ) \ + makeHighestDynArrayIndexBeAtLeast( _VMSMasterEnv->measHistsInfo, idx ); \ + _VMSMasterEnv->measHists[idx] = \ + makeFixedBinHist( numBins, startVal, binWidth, name ); + + +#define MEAS__SUB_CREATE /*turn on/off subtraction of create from plugin*/ +#define createHistIdx 0 +#define mutexLockHistIdx 1 +#define mutexUnlockHistIdx 2 +#define condWaitHistIdx 3 +#define condSignalHistIdx 4 + + +#define MakeTheMeasHists \ + _VMSMasterEnv->measHistsInfo = \ + makePrivDynArrayOfSize( &(_VMSMasterEnv->measHists), 200);\ + makeAMeasHist( createHistIdx, "Create", 50, 0, 200 ) \ + makeAMeasHist( mutexLockHistIdx, "mutex lock", 50, 0, 100 ) \ + makeAMeasHist( mutexUnlockHistIdx, "mutex unlock", 50, 0, 100 ) \ + makeAMeasHist( condWaitHistIdx, "cond wait", 50, 0, 100 ) \ + makeAMeasHist( condSignalHistIdx, "cond signal", 50, 0, 100 ) + +#define Meas_startCreate \ + int32 startStamp, endStamp; \ + saveLowTimeStampCountInto( startStamp ); \ + +#define Meas_endCreate \ + saveLowTimeStampCountInto( endStamp ); \ + addIntervalToHist( startStamp, endStamp, \ + _VMSMasterEnv->measHists[ createHistIdx ] ); + +#define Meas_startMutexLock \ + int32 startStamp, endStamp; \ + saveLowTimeStampCountInto( startStamp ); \ + +#define Meas_endMutexLock \ + saveLowTimeStampCountInto( endStamp ); \ + addIntervalToHist( startStamp, endStamp, \ + _VMSMasterEnv->measHists[ mutexLockHistIdx ] ); + +#define Meas_startMutexUnlock \ + int32 startStamp, endStamp; \ + saveLowTimeStampCountInto( startStamp ); \ + +#define Meas_endMutexUnlock \ + saveLowTimeStampCountInto( endStamp ); \ + addIntervalToHist( startStamp, endStamp, \ + _VMSMasterEnv->measHists[ mutexUnlockHistIdx ] ); + +#define Meas_startCondWait \ + int32 startStamp, endStamp; \ + saveLowTimeStampCountInto( startStamp ); \ + +#define Meas_endCondWait \ + saveLowTimeStampCountInto( endStamp ); \ + addIntervalToHist( startStamp, endStamp, \ + _VMSMasterEnv->measHists[ condWaitHistIdx ] ); + +#define Meas_startCondSignal \ + int32 startStamp, endStamp; \ + saveLowTimeStampCountInto( startStamp ); \ + +#define Meas_endCondSignal \ + saveLowTimeStampCountInto( endStamp ); \ + addIntervalToHist( startStamp, endStamp, \ + _VMSMasterEnv->measHists[ condSignalHistIdx ] ); + + +//===== + +#include "SwitchAnimators.h" +#include "probes.h" +#include "vutilities.h" + +#endif /* _VMS_H */ + diff -r 9c3107044f86 -r a49f02980151 VMS__DESIGN_NOTES.txt --- a/VMS__DESIGN_NOTES.txt Sat Nov 20 08:19:05 2010 +0100 +++ b/VMS__DESIGN_NOTES.txt Thu May 12 14:23:41 2011 +0200 @@ -1,2 +1,2 @@ - -Implement VMS this way: + +Implement VMS this way: diff -r 9c3107044f86 -r a49f02980151 VMS_primitive_data_types.h --- a/VMS_primitive_data_types.h Sat Nov 20 08:19:05 2010 +0100 +++ b/VMS_primitive_data_types.h Thu May 12 14:23:41 2011 +0200 @@ -1,53 +1,53 @@ -/* - * Copyright 2009 OpenSourceStewardshipFoundation.org - * Licensed under GNU General Public License version 2 - * - * Author: seanhalle@yahoo.com - * - - */ - -#ifndef _BLIS_PRIMITIVE_DATA_TYPES_H -#define _BLIS_PRIMITIVE_DATA_TYPES_H - - -/*For portability, need primitive data types that have a well defined - * size, and well-defined layout into bytes - *To do this, provide BLIS standard aliases for all primitive data types - *These aliases must be used in all BLIS functions instead of the ANSI types - * - *These definitions will be replaced inside each specialization module - * according to the compiler used in that module and the hardware being - * specialized to. - */ -/* -#define int8 char -#define uint8 char -#define int16 short -#define uint16 unsigned short -#define int32 int -#define uint32 unsigned int -#define int64 long long -#define uint64 unsigned long long -#define float32 float -#define float64 double -*/ -typedef char bool8; -typedef char int8; -typedef char uint8; -typedef short int16; -typedef unsigned short uint16; -typedef int int32; -typedef unsigned int uint32; -typedef long long int64; -typedef unsigned long long uint64; -typedef float float32; -typedef double float64; -//typedef double double float128; -#define float128 double double - -#define TRUE 1 -#define FALSE 0 - -#endif /* _BLIS_PRIMITIVE_DATA_TYPES_H */ - +/* + * Copyright 2009 OpenSourceStewardshipFoundation.org + * Licensed under GNU General Public License version 2 + * + * Author: seanhalle@yahoo.com + * + + */ + +#ifndef _BLIS_PRIMITIVE_DATA_TYPES_H +#define _BLIS_PRIMITIVE_DATA_TYPES_H + + +/*For portability, need primitive data types that have a well defined + * size, and well-defined layout into bytes + *To do this, provide BLIS standard aliases for all primitive data types + *These aliases must be used in all BLIS functions instead of the ANSI types + * + *These definitions will be replaced inside each specialization module + * according to the compiler used in that module and the hardware being + * specialized to. + */ +/* +#define int8 char +#define uint8 char +#define int16 short +#define uint16 unsigned short +#define int32 int +#define uint32 unsigned int +#define int64 long long +#define uint64 unsigned long long +#define float32 float +#define float64 double +*/ +typedef char bool8; +typedef char int8; +typedef char uint8; +typedef short int16; +typedef unsigned short uint16; +typedef int int32; +typedef unsigned int uint32; +typedef long long int64; +typedef unsigned long long uint64; +typedef float float32; +typedef double float64; +//typedef double double float128; +#define float128 double double + +#define TRUE 1 +#define FALSE 0 + +#endif /* _BLIS_PRIMITIVE_DATA_TYPES_H */ + diff -r 9c3107044f86 -r a49f02980151 probes.h --- a/probes.h Sat Nov 20 08:19:05 2010 +0100 +++ b/probes.h Thu May 12 14:23:41 2011 +0200 @@ -1,195 +1,195 @@ -/* - * Copyright 2009 OpenSourceStewardshipFoundation.org - * Licensed under GNU General Public License version 2 - * - * Author: seanhalle@yahoo.com - * - */ - -#ifndef _PROBES_H -#define _PROBES_H -#define __USE_GNU - -#include "VMS_primitive_data_types.h" - -#include - - - //when STATS__TURN_ON_PROBES is defined allows using probes to measure - // time intervals. The probes are macros that only compile to something - // when STATS__TURN_ON_PROBES is defined. The probes are saved in the - // master env -- but only when this is defined. - //The TSC probes use RDTSC instr, can be unreliable, Dbl uses gettimeofday -#define STATS__TURN_ON_PROBES -//#define STATS__USE_TSC_PROBES -#define STATS__USE_DBL_PROBES - -//typedef struct _IntervalProbe IntervalProbe; //in VMS.h - -struct _IntervalProbe - { - char *nameStr; - int32 probeID; - - int32 schedChoiceWasRecorded; - int32 coreNum; - int32 procrID; - float64 procrCreateSecs; - - #ifdef STATS__USE_TSC_PROBES - TSCount startStamp; - TSCount endStamp; - #else - struct timeval startStamp; - struct timeval endStamp; - #endif - float64 startSecs; - float64 endSecs; - float64 interval; - DblHist *hist;//if NULL, then is single interval probe - }; - - -//============================= Statistics ================================== - - //Frequency of TS counts - //TODO: change freq for each machine -#define TSCOUNT_FREQ 3180000000 - -inline TSCount getTSCount(); - - -//======================== Probes ============================= -// -// Use macros to allow turning probes off with a #define switch -#ifdef STATS__ENABLE_PROBES -int32 -VMS_impl__record_time_point_into_new_probe( char *nameStr,VirtProcr *animPr); -#define VMS__record_time_point_into_new_probe( nameStr, animPr ) \ - VMS_impl__record_time_point_in_new_probe( nameStr, animPr ) - -int32 -VMS_ext_impl__record_time_point_into_new_probe( char *nameStr ); -#define VMS_ext__record_time_point_into_new_probe( nameStr ) \ - VMS_ext_impl__record_time_point_into_new_probe( nameStr ) - - -int32 -VMS_impl__create_single_interval_probe( char *nameStr, VirtProcr *animPr ); -#define VMS__create_single_interval_probe( nameStr, animPr ) \ - VMS_impl__create_single_interval_probe( nameStr, animPr ) - - -int32 -VMS_impl__create_histogram_probe( int32 numBins, float64 startValue, - float64 binWidth, char *nameStr, VirtProcr *animPr ); -#define VMS__create_histogram_probe( numBins, startValue, \ - binWidth, nameStr, animPr ) \ - VMS_impl__create_histogram_probe( numBins, startValue, \ - binWidth, nameStr, animPr ) -void -VMS_impl__free_probe( IntervalProbe *probe ); -#define VMS__free_probe( probe ) \ - VMS_impl__free_probe( probe ) - -void -VMS_impl__index_probe_by_its_name( int32 probeID, VirtProcr *animPr ); -#define VMS__index_probe_by_its_name( probeID, animPr ) \ - VMS_impl__index_probe_by_its_name( probeID, animPr ) - -IntervalProbe * -VMS_impl__get_probe_by_name( char *probeName, VirtProcr *animPr ); -#define VMS__get_probe_by_name( probeID, animPr ) \ - VMS_impl__get_probe_by_name( probeName, animPr ) - -void -VMS_impl__record_sched_choice_into_probe( int32 probeID, VirtProcr *animPr ); -#define VMS__record_sched_choice_into_probe( probeID, animPr ) \ - VMS_impl__record_sched_choice_into_probe( probeID, animPr ) - -void -VMS_impl__record_interval_start_in_probe( int32 probeID ); -#define VMS__record_interval_start_in_probe( probeID ) \ - VMS_impl__record_interval_start_in_probe( probeID ) - -void -VMS_impl__record_interval_end_in_probe( int32 probeID ); -#define VMS__record_interval_end_in_probe( probeID ) \ - VMS_impl__record_interval_end_in_probe( probeID ) - -void -VMS_impl__print_stats_of_probe( int32 probeID ); -#define VMS__print_stats_of_probe( probeID ) \ - VMS_impl__print_stats_of_probe( probeID ) - -void -VMS_impl__print_stats_of_all_probes(); -#define VMS__print_stats_of_all_probes \ - VMS_impl__print_stats_of_all_probes - - -#else -int32 -VMS_impl__record_time_point_into_new_probe( char *nameStr,VirtProcr *animPr); -#define VMS__record_time_point_into_new_probe( nameStr, animPr ) \ - 0 /* do nothing */ - -int32 -VMS_ext_impl__record_time_point_into_new_probe( char *nameStr ); -#define VMS_ext__record_time_point_into_new_probe( nameStr ) \ - 0 /* do nothing */ - - -int32 -VMS_impl__create_single_interval_probe( char *nameStr, VirtProcr *animPr ); -#define VMS__create_single_interval_probe( nameStr, animPr ) \ - 0 /* do nothing */ - - -int32 -VMS_impl__create_histogram_probe( int32 numBins, float64 startValue, - float64 binWidth, char *nameStr, VirtProcr *animPr ); -#define VMS__create_histogram_probe( numBins, startValue, \ - binWidth, nameStr, animPr ) \ - 0 /* do nothing */ - -void -VMS_impl__index_probe_by_its_name( int32 probeID, VirtProcr *animPr ); -#define VMS__index_probe_by_its_name( probeID, animPr ) \ - /* do nothing */ - -IntervalProbe * -VMS_impl__get_probe_by_name( char *probeName, VirtProcr *animPr ); -#define VMS__get_probe_by_name( probeID, animPr ) \ - NULL /* do nothing */ - -void -VMS_impl__record_sched_choice_into_probe( int32 probeID, VirtProcr *animPr ); -#define VMS__record_sched_choice_into_probe( probeID, animPr ) \ - /* do nothing */ - -void -VMS_impl__record_interval_start_in_probe( int32 probeID ); -#define VMS__record_interval_start_in_probe( probeID ) \ - /* do nothing */ - -void -VMS_impl__record_interval_end_in_probe( int32 probeID ); -#define VMS__record_interval_end_in_probe( probeID ) \ - /* do nothing */ - -inline void doNothing(); -void -VMS_impl__print_stats_of_probe( int32 probeID ); -#define VMS__print_stats_of_probe( probeID ) \ - doNothing/* do nothing */ - -void -VMS_impl__print_stats_of_all_probes(); -#define VMS__print_stats_of_all_probes \ - doNothing/* do nothing */ - -#endif /* defined STATS__ENABLE_PROBES */ - -#endif /* _PROBES_H */ - +/* + * Copyright 2009 OpenSourceStewardshipFoundation.org + * Licensed under GNU General Public License version 2 + * + * Author: seanhalle@yahoo.com + * + */ + +#ifndef _PROBES_H +#define _PROBES_H +#define __USE_GNU + +#include "VMS_primitive_data_types.h" + +#include + + + //when STATS__TURN_ON_PROBES is defined allows using probes to measure + // time intervals. The probes are macros that only compile to something + // when STATS__TURN_ON_PROBES is defined. The probes are saved in the + // master env -- but only when this is defined. + //The TSC probes use RDTSC instr, can be unreliable, Dbl uses gettimeofday +#define STATS__TURN_ON_PROBES +//#define STATS__USE_TSC_PROBES +#define STATS__USE_DBL_PROBES + +//typedef struct _IntervalProbe IntervalProbe; //in VMS.h + +struct _IntervalProbe + { + char *nameStr; + int32 probeID; + + int32 schedChoiceWasRecorded; + int32 coreNum; + int32 procrID; + float64 procrCreateSecs; + + #ifdef STATS__USE_TSC_PROBES + TSCount startStamp; + TSCount endStamp; + #else + struct timeval startStamp; + struct timeval endStamp; + #endif + float64 startSecs; + float64 endSecs; + float64 interval; + DblHist *hist;//if NULL, then is single interval probe + }; + + +//============================= Statistics ================================== + + //Frequency of TS counts + //TODO: change freq for each machine +#define TSCOUNT_FREQ 3180000000 + +inline TSCount getTSCount(); + + +//======================== Probes ============================= +// +// Use macros to allow turning probes off with a #define switch +#ifdef STATS__ENABLE_PROBES +int32 +VMS_impl__record_time_point_into_new_probe( char *nameStr,VirtProcr *animPr); +#define VMS__record_time_point_into_new_probe( nameStr, animPr ) \ + VMS_impl__record_time_point_in_new_probe( nameStr, animPr ) + +int32 +VMS_ext_impl__record_time_point_into_new_probe( char *nameStr ); +#define VMS_ext__record_time_point_into_new_probe( nameStr ) \ + VMS_ext_impl__record_time_point_into_new_probe( nameStr ) + + +int32 +VMS_impl__create_single_interval_probe( char *nameStr, VirtProcr *animPr ); +#define VMS__create_single_interval_probe( nameStr, animPr ) \ + VMS_impl__create_single_interval_probe( nameStr, animPr ) + + +int32 +VMS_impl__create_histogram_probe( int32 numBins, float64 startValue, + float64 binWidth, char *nameStr, VirtProcr *animPr ); +#define VMS__create_histogram_probe( numBins, startValue, \ + binWidth, nameStr, animPr ) \ + VMS_impl__create_histogram_probe( numBins, startValue, \ + binWidth, nameStr, animPr ) +void +VMS_impl__free_probe( IntervalProbe *probe ); +#define VMS__free_probe( probe ) \ + VMS_impl__free_probe( probe ) + +void +VMS_impl__index_probe_by_its_name( int32 probeID, VirtProcr *animPr ); +#define VMS__index_probe_by_its_name( probeID, animPr ) \ + VMS_impl__index_probe_by_its_name( probeID, animPr ) + +IntervalProbe * +VMS_impl__get_probe_by_name( char *probeName, VirtProcr *animPr ); +#define VMS__get_probe_by_name( probeID, animPr ) \ + VMS_impl__get_probe_by_name( probeName, animPr ) + +void +VMS_impl__record_sched_choice_into_probe( int32 probeID, VirtProcr *animPr ); +#define VMS__record_sched_choice_into_probe( probeID, animPr ) \ + VMS_impl__record_sched_choice_into_probe( probeID, animPr ) + +void +VMS_impl__record_interval_start_in_probe( int32 probeID ); +#define VMS__record_interval_start_in_probe( probeID ) \ + VMS_impl__record_interval_start_in_probe( probeID ) + +void +VMS_impl__record_interval_end_in_probe( int32 probeID ); +#define VMS__record_interval_end_in_probe( probeID ) \ + VMS_impl__record_interval_end_in_probe( probeID ) + +void +VMS_impl__print_stats_of_probe( int32 probeID ); +#define VMS__print_stats_of_probe( probeID ) \ + VMS_impl__print_stats_of_probe( probeID ) + +void +VMS_impl__print_stats_of_all_probes(); +#define VMS__print_stats_of_all_probes \ + VMS_impl__print_stats_of_all_probes + + +#else +int32 +VMS_impl__record_time_point_into_new_probe( char *nameStr,VirtProcr *animPr); +#define VMS__record_time_point_into_new_probe( nameStr, animPr ) \ + 0 /* do nothing */ + +int32 +VMS_ext_impl__record_time_point_into_new_probe( char *nameStr ); +#define VMS_ext__record_time_point_into_new_probe( nameStr ) \ + 0 /* do nothing */ + + +int32 +VMS_impl__create_single_interval_probe( char *nameStr, VirtProcr *animPr ); +#define VMS__create_single_interval_probe( nameStr, animPr ) \ + 0 /* do nothing */ + + +int32 +VMS_impl__create_histogram_probe( int32 numBins, float64 startValue, + float64 binWidth, char *nameStr, VirtProcr *animPr ); +#define VMS__create_histogram_probe( numBins, startValue, \ + binWidth, nameStr, animPr ) \ + 0 /* do nothing */ + +void +VMS_impl__index_probe_by_its_name( int32 probeID, VirtProcr *animPr ); +#define VMS__index_probe_by_its_name( probeID, animPr ) \ + /* do nothing */ + +IntervalProbe * +VMS_impl__get_probe_by_name( char *probeName, VirtProcr *animPr ); +#define VMS__get_probe_by_name( probeID, animPr ) \ + NULL /* do nothing */ + +void +VMS_impl__record_sched_choice_into_probe( int32 probeID, VirtProcr *animPr ); +#define VMS__record_sched_choice_into_probe( probeID, animPr ) \ + /* do nothing */ + +void +VMS_impl__record_interval_start_in_probe( int32 probeID ); +#define VMS__record_interval_start_in_probe( probeID ) \ + /* do nothing */ + +void +VMS_impl__record_interval_end_in_probe( int32 probeID ); +#define VMS__record_interval_end_in_probe( probeID ) \ + /* do nothing */ + +inline void doNothing(); +void +VMS_impl__print_stats_of_probe( int32 probeID ); +#define VMS__print_stats_of_probe( probeID ) \ + doNothing/* do nothing */ + +void +VMS_impl__print_stats_of_all_probes(); +#define VMS__print_stats_of_all_probes \ + doNothing/* do nothing */ + +#endif /* defined STATS__ENABLE_PROBES */ + +#endif /* _PROBES_H */ + diff -r 9c3107044f86 -r a49f02980151 vmalloc.h --- a/vmalloc.h Sat Nov 20 08:19:05 2010 +0100 +++ b/vmalloc.h Thu May 12 14:23:41 2011 +0200 @@ -1,57 +1,57 @@ -/* - * Copyright 2009 OpenSourceCodeStewardshipFoundation.org - * Licensed under GNU General Public License version 2 - * - * Author: seanhalle@yahoo.com - * - * Created on November 14, 2009, 9:07 PM - */ - -#ifndef _VMALLOC_H -#define _VMALLOC_H - -#include -#include "VMS_primitive_data_types.h" - -typedef struct _MallocProlog MallocProlog; - -struct _MallocProlog - { - MallocProlog *nextChunkInFreeList; - MallocProlog *prevChunkInFreeList; - MallocProlog *nextHigherInMem; - MallocProlog *nextLowerInMem; - }; -//MallocProlog - -typedef struct - { - MallocProlog *firstChunkInFreeList; - int32 numInList; - } -FreeListHead; - -void * -VMS__malloc( int32 sizeRequested ); - -void -VMS__free( void *ptrToFree ); - -/*Allocates memory from the external system -- higher overhead - */ -void * -VMS__malloc_in_ext( int32 sizeRequested ); - -/*Frees memory that was allocated in the external system -- higher overhead - */ -void -VMS__free_in_ext( void *ptrToFree ); - - -MallocProlog * -VMS_ext__create_free_list(); - -void -VMS_ext__free_free_list( MallocProlog *freeListHead ); - +/* + * Copyright 2009 OpenSourceCodeStewardshipFoundation.org + * Licensed under GNU General Public License version 2 + * + * Author: seanhalle@yahoo.com + * + * Created on November 14, 2009, 9:07 PM + */ + +#ifndef _VMALLOC_H +#define _VMALLOC_H + +#include +#include "VMS_primitive_data_types.h" + +typedef struct _MallocProlog MallocProlog; + +struct _MallocProlog + { + MallocProlog *nextChunkInFreeList; + MallocProlog *prevChunkInFreeList; + MallocProlog *nextHigherInMem; + MallocProlog *nextLowerInMem; + }; +//MallocProlog + +typedef struct + { + MallocProlog *firstChunkInFreeList; + int32 numInList; + } +FreeListHead; + +void * +VMS__malloc( int32 sizeRequested ); + +void +VMS__free( void *ptrToFree ); + +/*Allocates memory from the external system -- higher overhead + */ +void * +VMS__malloc_in_ext( int32 sizeRequested ); + +/*Frees memory that was allocated in the external system -- higher overhead + */ +void +VMS__free_in_ext( void *ptrToFree ); + + +MallocProlog * +VMS_ext__create_free_list(); + +void +VMS_ext__free_free_list( MallocProlog *freeListHead ); + #endif \ No newline at end of file diff -r 9c3107044f86 -r a49f02980151 vutilities.h --- a/vutilities.h Sat Nov 20 08:19:05 2010 +0100 +++ b/vutilities.h Thu May 12 14:23:41 2011 +0200 @@ -1,20 +1,20 @@ -/* - * Copyright 2009 OpenSourceCodeStewardshipFoundation.org - * Licensed under GNU General Public License version 2 - * - * Author: seanhalle@yahoo.com - * - * Created on November 14, 2009, 9:07 PM - */ - - -#ifndef _UTILITIES_H -#define _UTILITIES_H - -#include -#include "VMS_primitive_data_types.h" - -inline char * -VMS__strDup( char *str ); - -#endif +/* + * Copyright 2009 OpenSourceCodeStewardshipFoundation.org + * Licensed under GNU General Public License version 2 + * + * Author: seanhalle@yahoo.com + * + * Created on November 14, 2009, 9:07 PM + */ + + +#ifndef _UTILITIES_H +#define _UTILITIES_H + +#include +#include "VMS_primitive_data_types.h" + +inline char * +VMS__strDup( char *str ); + +#endif