changeset 240:1cfcf49dc7ab Common_Ancestor

renamed Hardware_Dependent dir to HW_Dependent_Primitives
author Some Random Person <seanhalle@yahoo.com>
date Sun, 01 Apr 2012 13:53:46 -0700
parents 7ed97c961901
children e10973504ed3 b4f684e98d0b
files HW_Dependent_Primitives/VMS__HW_measurement.c HW_Dependent_Primitives/VMS__HW_measurement.h HW_Dependent_Primitives/VMS__primitives.c HW_Dependent_Primitives/VMS__primitives.h HW_Dependent_Primitives/VMS__primitives_asm.s Hardware_Dependent/VMS__HW_measurement.c Hardware_Dependent/VMS__HW_measurement.h Hardware_Dependent/VMS__primitives.c Hardware_Dependent/VMS__primitives.h Hardware_Dependent/VMS__primitives_asm.s
diffstat 10 files changed, 399 insertions(+), 399 deletions(-) [+]
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/HW_Dependent_Primitives/VMS__HW_measurement.c	Sun Apr 01 13:53:46 2012 -0700
     1.3 @@ -0,0 +1,74 @@
     1.4 +#include <unistd.h>
     1.5 +#include <fcntl.h>
     1.6 +#include <linux/types.h>
     1.7 +#include <linux/perf_event.h>
     1.8 +#include <errno.h>
     1.9 +#include <sys/syscall.h>
    1.10 +#include <linux/prctl.h>
    1.11 +
    1.12 +#include "../VMS.h"
    1.13 +
    1.14 +void setup_perf_counters(){
    1.15 +#ifdef HOLISTIC__TURN_ON_PERF_COUNTERS
    1.16 +    struct perf_event_attr hw_event;
    1.17 +   memset(&hw_event,0,sizeof(hw_event));
    1.18 +   	hw_event.type = PERF_TYPE_HARDWARE;
    1.19 +	hw_event.size = sizeof(hw_event);
    1.20 +	hw_event.disabled = 1;
    1.21 +        hw_event.freq = 0;
    1.22 +	hw_event.inherit = 1; /* children inherit it   */
    1.23 +	hw_event.pinned = 1; /* must always be on PMU */
    1.24 +	hw_event.exclusive = 0; /* only group on PMU     */
    1.25 +	hw_event.exclude_user = 0; /* don't count user      */
    1.26 +	hw_event.exclude_kernel = 0; /* ditto kernel          */
    1.27 +	hw_event.exclude_hv = 0; /* ditto hypervisor      */
    1.28 +	hw_event.exclude_idle = 0; /* don't count when idle */
    1.29 +	hw_event.mmap = 0; /* include mmap data     */
    1.30 +	hw_event.comm = 0; /* include comm data     */
    1.31 +
    1.32 +        int coreIdx;
    1.33 +   for( coreIdx = 0; coreIdx < NUM_CORES; coreIdx++ )
    1.34 +    {
    1.35 +       	hw_event.config = 0x0000000000000000; //cycles
    1.36 +        _VMSMasterEnv->cycles_counter_fd[coreIdx] = syscall(__NR_perf_event_open, &hw_event,
    1.37 + 		0,//pid_t pid, 
    1.38 +		coreIdx,//int cpu, 
    1.39 +		-1,//int group_fd,
    1.40 +		0//unsigned long flags
    1.41 +	);
    1.42 +        if (_VMSMasterEnv->cycles_counter_fd[coreIdx]<0){
    1.43 +            fprintf(stderr,"On core %d: ",coreIdx);
    1.44 +            perror("Failed to open cycles counter");
    1.45 +        }
    1.46 +        hw_event.config = 0x0000000000000001; //instrs
    1.47 +        _VMSMasterEnv->instrs_counter_fd[coreIdx] = syscall(__NR_perf_event_open, &hw_event,
    1.48 + 		0,//pid_t pid, 
    1.49 +		coreIdx,//int cpu, 
    1.50 +		-1,//int group_fd,
    1.51 +		0//unsigned long flags
    1.52 +	);
    1.53 +        if (_VMSMasterEnv->instrs_counter_fd[coreIdx]<0){
    1.54 +            fprintf(stderr,"On core %d: ",coreIdx);
    1.55 +            perror("Failed to open instrs counter");
    1.56 +        }
    1.57 +   }
    1.58 +        
    1.59 +   prctl(PR_TASK_PERF_EVENTS_ENABLE);
    1.60 +#endif
    1.61 +}
    1.62 +
    1.63 +__inline__ uint64_t rdtsc(){
    1.64 +    uint32_t lo, hi;
    1.65 +    __asm__ __volatile__ (      // serialize
    1.66 +    "xorl %%eax,%%eax \n        cpuid"
    1.67 +    ::: "%rax", "%rbx", "%rcx", "%rdx");
    1.68 +    __asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi)); 
    1.69 +   /* asm volatile("RDTSC;"                   
    1.70 +                 "movl %%eax, %0;"         
    1.71 +                 "movl %%edx, %1;"         
    1.72 +               : "=m" (lo), "=m" (hi)
    1.73 +               :                        
    1.74 +               : "%eax", "%edx"         
    1.75 +                ); */
    1.76 +    return (uint64_t)hi << 32 | lo;
    1.77 +}
    1.78 \ No newline at end of file
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/HW_Dependent_Primitives/VMS__HW_measurement.h	Sun Apr 01 13:53:46 2012 -0700
     2.3 @@ -0,0 +1,63 @@
     2.4 +/*
     2.5 + *  Copyright 2009 OpenSourceStewardshipFoundation.org
     2.6 + *  Licensed under GNU General Public License version 2
     2.7 + *
     2.8 + * Author: seanhalle@yahoo.com
     2.9 + * 
    2.10 + */
    2.11 +
    2.12 +#ifndef _VMS__HW_MEASUREMENT_H
    2.13 +#define	_VMS__HW_MEASUREMENT_H
    2.14 +#define _GNU_SOURCE
    2.15 +
    2.16 +
    2.17 +//===================  Macros to Capture Measurements  ======================
    2.18 +
    2.19 +typedef union
    2.20 + { uint32 lowHigh[2];
    2.21 +   uint64 longVal;
    2.22 + }
    2.23 +TSCountLowHigh;
    2.24 +
    2.25 +
    2.26 +//===================  Macros to Capture Measurements  ======================
    2.27 +//
    2.28 +//===== RDTSC wrapper ===== 
    2.29 +//Also runs with x86_64 code
    2.30 +#define saveTSCLowHigh(lowHighIn) \
    2.31 +   asm volatile("RDTSC;                   \
    2.32 +                 movl %%eax, %0;          \
    2.33 +                 movl %%edx, %1;"         \
    2.34 +   /* outputs */ : "=m" (lowHighIn.lowHigh[0]), "=m" (lowHighIn.lowHigh[1])\
    2.35 +   /* inputs  */ :                        \
    2.36 +   /* clobber */ : "%eax", "%edx"         \
    2.37 +                );
    2.38 +
    2.39 +#define saveTimeStampCountInto(low, high) \
    2.40 +   asm volatile("RDTSC;                   \
    2.41 +                 movl %%eax, %0;          \
    2.42 +                 movl %%edx, %1;"         \
    2.43 +   /* outputs */ : "=m" (low), "=m" (high)\
    2.44 +   /* inputs  */ :                        \
    2.45 +   /* clobber */ : "%eax", "%edx"         \
    2.46 +                );
    2.47 +
    2.48 +#define saveLowTimeStampCountInto(low)    \
    2.49 +   asm volatile("RDTSC;                   \
    2.50 +                 movl %%eax, %0;"         \
    2.51 +   /* outputs */ : "=m" (low)             \
    2.52 +   /* inputs  */ :                        \
    2.53 +   /* clobber */ : "%eax", "%edx"         \
    2.54 +                );
    2.55 +
    2.56 +inline TSCount getTSCount();
    2.57 +
    2.58 +
    2.59 +   //For code that calculates normalization-offset between TSC counts of
    2.60 +   // different cores.
    2.61 +//#define NUM_TSC_ROUND_TRIPS 10
    2.62 +
    2.63 +void setup_perf_counters();
    2.64 +uint64_t rdtsc(void);
    2.65 +#endif	/* */
    2.66 +
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/HW_Dependent_Primitives/VMS__primitives.c	Sun Apr 01 13:53:46 2012 -0700
     3.3 @@ -0,0 +1,53 @@
     3.4 +/*
     3.5 + * This File contains all hardware dependent C code.
     3.6 + */
     3.7 +
     3.8 +
     3.9 +#include "../VMS.h"
    3.10 +
    3.11 +/*Set up the stack with __cdecl structure on it
    3.12 + * Except doing a trick for 64 bits, where put top-level fn pointer on
    3.13 + * stack, then call an assembly helper that copies it into a reg and
    3.14 + * jumps to it.  So, set the resumeInstrPtr to the helper-assembly.
    3.15 + *No need to save registers on old stack frame, because there's no old
    3.16 + * animator state to return to
    3.17 + * 
    3.18 + *This was factored into separate function because it's used stand-alone in
    3.19 + * some wrapper-libraries (but only "int" version, to warn users to check
    3.20 + * carefully that it's safe)
    3.21 + */
    3.22 +inline void
    3.23 +VMS_int__point_slaveVP_to_Fn( SlaveVP *slaveVP, TopLevelFnPtr fnPtr,
    3.24 +                              void    *dataParam)
    3.25 + { void  *stackPtr;
    3.26 +
    3.27 +// Start of Hardware dependent part           
    3.28 +   
    3.29 +    //Set slave's instr pointer to a helper Fn that copies params from stack
    3.30 +   slaveVP->resumeInstrPtr  = (TopLevelFnPtr)&startUpTopLevelFn;
    3.31 +   
    3.32 +    //fnPtr takes two params -- void *dataParam & void *animSlv
    3.33 +    // Stack grows *down*, so start it at highest stack addr, minus room
    3.34 +    // for 2 params + return addr. 
    3.35 +   stackPtr = 
    3.36 +     (void *)slaveVP->startOfStack + VIRT_PROCR_STACK_SIZE - 4*sizeof(void*);
    3.37 +  
    3.38 +    //setup __cdecl on stack
    3.39 +    //Normally, return Addr is in loc pointed to by stackPtr, but doing a
    3.40 +    // trick for 64 bit arch, where put ptr to top-level fn there instead,
    3.41 +    // and set resumeInstrPtr to a helper-fn that copies the top-level
    3.42 +    // fn ptr and params into registers.
    3.43 +    //Then, dataParam is at stackPtr + 8 bytes, & animating SlaveVP above
    3.44 +   *((SlaveVP**)stackPtr + 2 ) = slaveVP; //rightmost param
    3.45 +   *((void**)stackPtr + 1 ) = dataParam;  //next  param to left
    3.46 +   *((void**)stackPtr) = (void*)fnPtr;    //copied to reg by helper Fn
    3.47 +   
    3.48 +  
    3.49 +// end of Hardware dependent part           
    3.50 +   
    3.51 +      //core controller will switch to stack & frame pointers stored in slave,
    3.52 +      // suspend will save processor's stack and frame into slave
    3.53 +   slaveVP->stackPtr = stackPtr; 
    3.54 +   slaveVP->framePtr = stackPtr; 
    3.55 + }
    3.56 +
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/HW_Dependent_Primitives/VMS__primitives.h	Sun Apr 01 13:53:46 2012 -0700
     4.3 @@ -0,0 +1,41 @@
     4.4 +/*
     4.5 + *  Copyright 2009 OpenSourceStewardshipFoundation.org
     4.6 + *  Licensed under GNU General Public License version 2
     4.7 + *
     4.8 + * Author: seanhalle@yahoo.com
     4.9 + * 
    4.10 + */
    4.11 +
    4.12 +#ifndef  _VMS__PRIMITIVES_H
    4.13 +#define	_VMS__PRIMITIVES_H
    4.14 +#define _GNU_SOURCE
    4.15 +
    4.16 +void 
    4.17 +recordCoreCtlrReturnLabelAddr(void **returnAddress);
    4.18 +
    4.19 +void 
    4.20 +switchToSlv(SlaveVP *nextSlave);
    4.21 +
    4.22 +void 
    4.23 +switchToCoreCtlr(SlaveVP *nextSlave);
    4.24 +
    4.25 +void 
    4.26 +masterSwitchToCoreCtlr(SlaveVP *nextSlave);
    4.27 +
    4.28 +void 
    4.29 +startUpTopLevelFn();
    4.30 +
    4.31 +void *
    4.32 +asmTerminateCoreCtlr(SlaveVP *currSlv);
    4.33 +
    4.34 +#define flushRegisters() \
    4.35 +        asm volatile ("":::"%rbx", "%r12", "%r13","%r14","%r15")
    4.36 +
    4.37 +void
    4.38 +VMS_int__save_return_into_ptd_to_loc_then_do_ret(void *ptdToLoc);
    4.39 +
    4.40 +void
    4.41 +VMS_int__return_to_addr_in_ptd_to_loc(void *ptdToLoc);
    4.42 +
    4.43 +#endif	/* _VMS__HW_DEPENDENT_H */
    4.44 +
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/HW_Dependent_Primitives/VMS__primitives_asm.s	Sun Apr 01 13:53:46 2012 -0700
     5.3 @@ -0,0 +1,168 @@
     5.4 +.data
     5.5 +
     5.6 +
     5.7 +.text
     5.8 +
     5.9 +//Save return label address for the coreCtlr to pointer
    5.10 +//Arguments: Pointer to variable holding address
    5.11 +.globl recordCoreCtlrReturnLabelAddr
    5.12 +recordCoreCtlrReturnLabelAddr:
    5.13 +    movq    $coreCtlrReturn, %rcx  #load label address
    5.14 +    movq    %rcx, (%rdi)           #save address to pointer
    5.15 +    ret
    5.16 +
    5.17 +
    5.18 +//Trick for 64 bit arch -- copies args from stack into regs, then does jmp to
    5.19 +// the top-level function, which was pointed to by the stack-ptr
    5.20 +.globl startUpTopLevelFn
    5.21 +startUpTopLevelFn:
    5.22 +    movq    %rdi      , %rsi #get second argument from first argument of switchSlv
    5.23 +    movq    0x08(%rsp), %rdi #get first argument from stack
    5.24 +    movq    (%rsp)    , %rax #get top-level function's addr from stack
    5.25 +    jmp     *%rax            #jump to the top-level function
    5.26 +
    5.27 +//Switches form CoreCtlr to either a normal Slv VP or the Master VP
    5.28 +//switch to VP's stack and frame ptr then jump to VP's next-instr-ptr
    5.29 +/* SlaveVP  offsets:
    5.30 + * 0x00  stackPtr
    5.31 + * 0x08 framePtr
    5.32 + * 0x10 resumeInstrPtr
    5.33 + * 0x18 coreCtlrFramePtr
    5.34 + * 0x20 coreCtlrStackPtr
    5.35 + *
    5.36 + * _VMSMasterEnv  offsets:
    5.37 + * 0x00 coreCtlrReturnPt
    5.38 + * 0x100 masterLock
    5.39 + */
    5.40 +.globl switchToSlv
    5.41 +switchToSlv:
    5.42 +    #SlaveVP in %rdi
    5.43 +    movq    %rsp      , 0x20(%rdi)   #save core ctlr stack pointer 
    5.44 +    movq    %rbp      , 0x18(%rdi)   #save core ctlr frame pointer
    5.45 +    movq    0x00(%rdi), %rsp         #restore stack pointer
    5.46 +    movq    0x08(%rdi), %rbp         #restore frame pointer
    5.47 +    movq    0x10(%rdi), %rax         #get jmp pointer
    5.48 +    jmp     *%rax                    #jmp to Slv
    5.49 +coreCtlrReturn:
    5.50 +    ret
    5.51 +
    5.52 +    
    5.53 +//switches to core controller. saves return address
    5.54 +/* SlaveVP  offsets:
    5.55 + * 0x00  stackPtr
    5.56 + * 0x08 framePtr
    5.57 + * 0x10 resumeInstrPtr
    5.58 + * 0x18 coreCtlrFramePtr
    5.59 + * 0x20 coreCtlrStackPtr
    5.60 + *
    5.61 + * _VMSMasterEnv  offsets:
    5.62 + * 0x00 coreCtlrReturnPt
    5.63 + * 0x100 masterLock
    5.64 + */
    5.65 +.globl switchToCoreCtlr
    5.66 +switchToCoreCtlr:
    5.67 +    #SlaveVP in %rdi
    5.68 +    movq    $SlvReturn, 0x10(%rdi)   #store return address
    5.69 +    movq    %rsp      , 0x00(%rdi)   #save stack pointer 
    5.70 +    movq    %rbp      , 0x08(%rdi)   #save frame pointer
    5.71 +    movq    0x20(%rdi), %rsp         #restore stack pointer
    5.72 +    movq    0x18(%rdi), %rbp         #restore frame pointer
    5.73 +    movq    $_VMSMasterEnv, %rcx
    5.74 +    movq        (%rcx), %rcx         #_VMSMasterEnv is pointer to struct
    5.75 +    movq    0x00(%rcx), %rax         #get CoreCtlrStartPt
    5.76 +    jmp     *%rax                    #jmp to CoreCtlr
    5.77 +SlvReturn:
    5.78 +    ret
    5.79 +
    5.80 +
    5.81 +
    5.82 +//switches to core controller from master. saves return address
    5.83 +//Releases masterLock so the next AnimationMaster can be executed
    5.84 +/* SlaveVP  offsets:
    5.85 + * 0x00  stackPtr
    5.86 + * 0x08 framePtr
    5.87 + * 0x10 resumeInstrPtr
    5.88 + * 0x18 coreCtlrFramePtr
    5.89 + * 0x20 coreCtlrStackPtr
    5.90 + *
    5.91 + * _VMSMasterEnv  offsets:
    5.92 + * 0x00 coreCtlrReturnPt
    5.93 + * 0x100 masterLock
    5.94 + */
    5.95 +.globl masterSwitchToCoreCtlr
    5.96 +masterSwitchToCoreCtlr:
    5.97 +    #SlaveVP in %rdi
    5.98 +    movq    $MasterReturn, 0x10(%rdi)   #store return address
    5.99 +    movq    %rsp      , 0x00(%rdi)   #save stack pointer 
   5.100 +    movq    %rbp      , 0x08(%rdi)   #save frame pointer
   5.101 +    movq    0x20(%rdi), %rsp         #restore stack pointer
   5.102 +    movq    0x18(%rdi), %rbp         #restore frame pointer
   5.103 +    movq    $_VMSMasterEnv, %rcx
   5.104 +    movq        (%rcx), %rcx         #_VMSMasterEnv is pointer to struct
   5.105 +    movq    0x00(%rcx), %rax         #get CoreCtlr return pt
   5.106 +    movl    $0x0      , 0x100(%rcx)  #release lock
   5.107 +    jmp     *%rax                    #jmp to CoreCtlr
   5.108 +MasterReturn:
   5.109 +    ret
   5.110 +
   5.111 +
   5.112 +/*Switch to terminateCoreCtlr
   5.113 + *This is called by endOSThreadFn, which is the top-level function given
   5.114 + * to a shutdown slave.  When such a slave gets switched to, by the core
   5.115 + * controller, it runs the top-level function, which calls this, which
   5.116 + * then calls terminateCoreCtlr, which ends the pthread.  Note, when get
   5.117 + * here, stack is already set up for switchSlv and Slv ptr is in %rdi.
   5.118 + *Do not save registers of Slv because this function will never return
   5.119 + *
   5.120 + * SlaveVP  offsets:
   5.121 + * 0x00  stackPtr
   5.122 + * 0x08 framePtr
   5.123 + * 0x10 resumeInstrPtr
   5.124 + * 0x18 coreCtlrFramePtr
   5.125 + * 0x20 coreCtlrStackPtr
   5.126 + *
   5.127 + * _VMSMasterEnv  offsets:
   5.128 + * 0x00 coreCtlrReturnPt
   5.129 + * 0x100 masterLock
   5.130 + */
   5.131 +.globl asmTerminateCoreCtlr
   5.132 +asmTerminateCoreCtlr:                #SlaveVP ptr is in %rdi
   5.133 +    movq    0x20(%rdi), %rsp         #restore stack pointer
   5.134 +    movq    0x18(%rdi), %rbp         #restore frame pointer
   5.135 +    movq    $terminateCoreCtlr, %rax
   5.136 +    jmp     *%rax                    #jmp to fn that ends the pthread
   5.137 +
   5.138 +
   5.139 +/*
   5.140 + * This one for the sequential version is special. It discards the current stack
   5.141 + * and returns directly from the coreCtlr after VMS_WL__dissipate_slaveVP was called
   5.142 + */
   5.143 +.globl asmTerminateCoreCtlrSeq
   5.144 +asmTerminateCoreCtlrSeq:
   5.145 +    #SlaveVP in %rdi
   5.146 +    movq    0x20(%rdi), %rsp         #restore stack pointer
   5.147 +    movq    0x18(%rdi), %rbp         #restore frame pointer
   5.148 +    #argument is in %rdi
   5.149 +    call    VMS_int__dissipate_slaveVP
   5.150 +    movq    %rbp      , %rsp        #goto the coreCtlrs stack
   5.151 +    pop     %rbp        #restore the old framepointer
   5.152 +    ret                 #return from core controller
   5.153 +    
   5.154 +
   5.155 +//Takes the return addr off the stack and saves into the loc pointed to by
   5.156 +// by the parameter passed in via rdi.  Return addr is at 0x8(%rbp) for 64bit
   5.157 +.globl VMS_int__save_return_into_ptd_to_loc_then_do_ret
   5.158 +VMS_int__save_return_into_ptd_to_loc_then_do_ret:
   5.159 +    movq 0x08(%rbp),   %rax  #get ret address, rbp is the same as in the calling function
   5.160 +    movq      %rax,   (%rdi) #write ret addr into addr passed as param field
   5.161 +    ret
   5.162 +
   5.163 +
   5.164 +//Assembly code changes the return addr on the stack to the one
   5.165 +// pointed to by the parameter, then returns. Stack's return addr is at 0x8(%rbp)
   5.166 +.globl VMS_int__return_to_addr_in_ptd_to_loc
   5.167 +VMS_int__return_to_addr_in_ptd_to_loc:
   5.168 +    movq   (%rdi),     %rax  #get return addr from addr passed as param
   5.169 +    movq    %rax, 0x08(%rbp) #write return addr to the stack of the caller
   5.170 +    ret
   5.171 +
     6.1 --- a/Hardware_Dependent/VMS__HW_measurement.c	Wed Mar 28 18:01:44 2012 +0200
     6.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.3 @@ -1,74 +0,0 @@
     6.4 -#include <unistd.h>
     6.5 -#include <fcntl.h>
     6.6 -#include <linux/types.h>
     6.7 -#include <linux/perf_event.h>
     6.8 -#include <errno.h>
     6.9 -#include <sys/syscall.h>
    6.10 -#include <linux/prctl.h>
    6.11 -
    6.12 -#include "../VMS.h"
    6.13 -
    6.14 -void setup_perf_counters(){
    6.15 -#ifdef HOLISTIC__TURN_ON_PERF_COUNTERS
    6.16 -    struct perf_event_attr hw_event;
    6.17 -   memset(&hw_event,0,sizeof(hw_event));
    6.18 -   	hw_event.type = PERF_TYPE_HARDWARE;
    6.19 -	hw_event.size = sizeof(hw_event);
    6.20 -	hw_event.disabled = 1;
    6.21 -        hw_event.freq = 0;
    6.22 -	hw_event.inherit = 1; /* children inherit it   */
    6.23 -	hw_event.pinned = 1; /* must always be on PMU */
    6.24 -	hw_event.exclusive = 0; /* only group on PMU     */
    6.25 -	hw_event.exclude_user = 0; /* don't count user      */
    6.26 -	hw_event.exclude_kernel = 0; /* ditto kernel          */
    6.27 -	hw_event.exclude_hv = 0; /* ditto hypervisor      */
    6.28 -	hw_event.exclude_idle = 0; /* don't count when idle */
    6.29 -	hw_event.mmap = 0; /* include mmap data     */
    6.30 -	hw_event.comm = 0; /* include comm data     */
    6.31 -
    6.32 -        int coreIdx;
    6.33 -   for( coreIdx = 0; coreIdx < NUM_CORES; coreIdx++ )
    6.34 -    {
    6.35 -       	hw_event.config = 0x0000000000000000; //cycles
    6.36 -        _VMSMasterEnv->cycles_counter_fd[coreIdx] = syscall(__NR_perf_event_open, &hw_event,
    6.37 - 		0,//pid_t pid, 
    6.38 -		coreIdx,//int cpu, 
    6.39 -		-1,//int group_fd,
    6.40 -		0//unsigned long flags
    6.41 -	);
    6.42 -        if (_VMSMasterEnv->cycles_counter_fd[coreIdx]<0){
    6.43 -            fprintf(stderr,"On core %d: ",coreIdx);
    6.44 -            perror("Failed to open cycles counter");
    6.45 -        }
    6.46 -        hw_event.config = 0x0000000000000001; //instrs
    6.47 -        _VMSMasterEnv->instrs_counter_fd[coreIdx] = syscall(__NR_perf_event_open, &hw_event,
    6.48 - 		0,//pid_t pid, 
    6.49 -		coreIdx,//int cpu, 
    6.50 -		-1,//int group_fd,
    6.51 -		0//unsigned long flags
    6.52 -	);
    6.53 -        if (_VMSMasterEnv->instrs_counter_fd[coreIdx]<0){
    6.54 -            fprintf(stderr,"On core %d: ",coreIdx);
    6.55 -            perror("Failed to open instrs counter");
    6.56 -        }
    6.57 -   }
    6.58 -        
    6.59 -   prctl(PR_TASK_PERF_EVENTS_ENABLE);
    6.60 -#endif
    6.61 -}
    6.62 -
    6.63 -__inline__ uint64_t rdtsc(){
    6.64 -    uint32_t lo, hi;
    6.65 -    __asm__ __volatile__ (      // serialize
    6.66 -    "xorl %%eax,%%eax \n        cpuid"
    6.67 -    ::: "%rax", "%rbx", "%rcx", "%rdx");
    6.68 -    __asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi)); 
    6.69 -   /* asm volatile("RDTSC;"                   
    6.70 -                 "movl %%eax, %0;"         
    6.71 -                 "movl %%edx, %1;"         
    6.72 -               : "=m" (lo), "=m" (hi)
    6.73 -               :                        
    6.74 -               : "%eax", "%edx"         
    6.75 -                ); */
    6.76 -    return (uint64_t)hi << 32 | lo;
    6.77 -}
    6.78 \ No newline at end of file
     7.1 --- a/Hardware_Dependent/VMS__HW_measurement.h	Wed Mar 28 18:01:44 2012 +0200
     7.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.3 @@ -1,63 +0,0 @@
     7.4 -/*
     7.5 - *  Copyright 2009 OpenSourceStewardshipFoundation.org
     7.6 - *  Licensed under GNU General Public License version 2
     7.7 - *
     7.8 - * Author: seanhalle@yahoo.com
     7.9 - * 
    7.10 - */
    7.11 -
    7.12 -#ifndef _VMS__HW_MEASUREMENT_H
    7.13 -#define	_VMS__HW_MEASUREMENT_H
    7.14 -#define _GNU_SOURCE
    7.15 -
    7.16 -
    7.17 -//===================  Macros to Capture Measurements  ======================
    7.18 -
    7.19 -typedef union
    7.20 - { uint32 lowHigh[2];
    7.21 -   uint64 longVal;
    7.22 - }
    7.23 -TSCountLowHigh;
    7.24 -
    7.25 -
    7.26 -//===================  Macros to Capture Measurements  ======================
    7.27 -//
    7.28 -//===== RDTSC wrapper ===== 
    7.29 -//Also runs with x86_64 code
    7.30 -#define saveTSCLowHigh(lowHighIn) \
    7.31 -   asm volatile("RDTSC;                   \
    7.32 -                 movl %%eax, %0;          \
    7.33 -                 movl %%edx, %1;"         \
    7.34 -   /* outputs */ : "=m" (lowHighIn.lowHigh[0]), "=m" (lowHighIn.lowHigh[1])\
    7.35 -   /* inputs  */ :                        \
    7.36 -   /* clobber */ : "%eax", "%edx"         \
    7.37 -                );
    7.38 -
    7.39 -#define saveTimeStampCountInto(low, high) \
    7.40 -   asm volatile("RDTSC;                   \
    7.41 -                 movl %%eax, %0;          \
    7.42 -                 movl %%edx, %1;"         \
    7.43 -   /* outputs */ : "=m" (low), "=m" (high)\
    7.44 -   /* inputs  */ :                        \
    7.45 -   /* clobber */ : "%eax", "%edx"         \
    7.46 -                );
    7.47 -
    7.48 -#define saveLowTimeStampCountInto(low)    \
    7.49 -   asm volatile("RDTSC;                   \
    7.50 -                 movl %%eax, %0;"         \
    7.51 -   /* outputs */ : "=m" (low)             \
    7.52 -   /* inputs  */ :                        \
    7.53 -   /* clobber */ : "%eax", "%edx"         \
    7.54 -                );
    7.55 -
    7.56 -inline TSCount getTSCount();
    7.57 -
    7.58 -
    7.59 -   //For code that calculates normalization-offset between TSC counts of
    7.60 -   // different cores.
    7.61 -//#define NUM_TSC_ROUND_TRIPS 10
    7.62 -
    7.63 -void setup_perf_counters();
    7.64 -uint64_t rdtsc(void);
    7.65 -#endif	/* */
    7.66 -
     8.1 --- a/Hardware_Dependent/VMS__primitives.c	Wed Mar 28 18:01:44 2012 +0200
     8.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.3 @@ -1,53 +0,0 @@
     8.4 -/*
     8.5 - * This File contains all hardware dependent C code.
     8.6 - */
     8.7 -
     8.8 -
     8.9 -#include "../VMS.h"
    8.10 -
    8.11 -/*Set up the stack with __cdecl structure on it
    8.12 - * Except doing a trick for 64 bits, where put top-level fn pointer on
    8.13 - * stack, then call an assembly helper that copies it into a reg and
    8.14 - * jumps to it.  So, set the resumeInstrPtr to the helper-assembly.
    8.15 - *No need to save registers on old stack frame, because there's no old
    8.16 - * animator state to return to
    8.17 - * 
    8.18 - *This was factored into separate function because it's used stand-alone in
    8.19 - * some wrapper-libraries (but only "int" version, to warn users to check
    8.20 - * carefully that it's safe)
    8.21 - */
    8.22 -inline void
    8.23 -VMS_int__point_slaveVP_to_Fn( SlaveVP *slaveVP, TopLevelFnPtr fnPtr,
    8.24 -                              void    *dataParam)
    8.25 - { void  *stackPtr;
    8.26 -
    8.27 -// Start of Hardware dependent part           
    8.28 -   
    8.29 -    //Set slave's instr pointer to a helper Fn that copies params from stack
    8.30 -   slaveVP->resumeInstrPtr  = (TopLevelFnPtr)&startUpTopLevelFn;
    8.31 -   
    8.32 -    //fnPtr takes two params -- void *dataParam & void *animSlv
    8.33 -    // Stack grows *down*, so start it at highest stack addr, minus room
    8.34 -    // for 2 params + return addr. 
    8.35 -   stackPtr = 
    8.36 -     (void *)slaveVP->startOfStack + VIRT_PROCR_STACK_SIZE - 4*sizeof(void*);
    8.37 -  
    8.38 -    //setup __cdecl on stack
    8.39 -    //Normally, return Addr is in loc pointed to by stackPtr, but doing a
    8.40 -    // trick for 64 bit arch, where put ptr to top-level fn there instead,
    8.41 -    // and set resumeInstrPtr to a helper-fn that copies the top-level
    8.42 -    // fn ptr and params into registers.
    8.43 -    //Then, dataParam is at stackPtr + 8 bytes, & animating SlaveVP above
    8.44 -   *((SlaveVP**)stackPtr + 2 ) = slaveVP; //rightmost param
    8.45 -   *((void**)stackPtr + 1 ) = dataParam;  //next  param to left
    8.46 -   *((void**)stackPtr) = (void*)fnPtr;    //copied to reg by helper Fn
    8.47 -   
    8.48 -  
    8.49 -// end of Hardware dependent part           
    8.50 -   
    8.51 -      //core controller will switch to stack & frame pointers stored in slave,
    8.52 -      // suspend will save processor's stack and frame into slave
    8.53 -   slaveVP->stackPtr = stackPtr; 
    8.54 -   slaveVP->framePtr = stackPtr; 
    8.55 - }
    8.56 -
     9.1 --- a/Hardware_Dependent/VMS__primitives.h	Wed Mar 28 18:01:44 2012 +0200
     9.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.3 @@ -1,41 +0,0 @@
     9.4 -/*
     9.5 - *  Copyright 2009 OpenSourceStewardshipFoundation.org
     9.6 - *  Licensed under GNU General Public License version 2
     9.7 - *
     9.8 - * Author: seanhalle@yahoo.com
     9.9 - * 
    9.10 - */
    9.11 -
    9.12 -#ifndef  _VMS__PRIMITIVES_H
    9.13 -#define	_VMS__PRIMITIVES_H
    9.14 -#define _GNU_SOURCE
    9.15 -
    9.16 -void 
    9.17 -recordCoreCtlrReturnLabelAddr(void **returnAddress);
    9.18 -
    9.19 -void 
    9.20 -switchToSlv(SlaveVP *nextSlave);
    9.21 -
    9.22 -void 
    9.23 -switchToCoreCtlr(SlaveVP *nextSlave);
    9.24 -
    9.25 -void 
    9.26 -masterSwitchToCoreCtlr(SlaveVP *nextSlave);
    9.27 -
    9.28 -void 
    9.29 -startUpTopLevelFn();
    9.30 -
    9.31 -void *
    9.32 -asmTerminateCoreCtlr(SlaveVP *currSlv);
    9.33 -
    9.34 -#define flushRegisters() \
    9.35 -        asm volatile ("":::"%rbx", "%r12", "%r13","%r14","%r15")
    9.36 -
    9.37 -void
    9.38 -VMS_int__save_return_into_ptd_to_loc_then_do_ret(void *ptdToLoc);
    9.39 -
    9.40 -void
    9.41 -VMS_int__return_to_addr_in_ptd_to_loc(void *ptdToLoc);
    9.42 -
    9.43 -#endif	/* _VMS__HW_DEPENDENT_H */
    9.44 -
    10.1 --- a/Hardware_Dependent/VMS__primitives_asm.s	Wed Mar 28 18:01:44 2012 +0200
    10.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.3 @@ -1,168 +0,0 @@
    10.4 -.data
    10.5 -
    10.6 -
    10.7 -.text
    10.8 -
    10.9 -//Save return label address for the coreCtlr to pointer
   10.10 -//Arguments: Pointer to variable holding address
   10.11 -.globl recordCoreCtlrReturnLabelAddr
   10.12 -recordCoreCtlrReturnLabelAddr:
   10.13 -    movq    $coreCtlrReturn, %rcx  #load label address
   10.14 -    movq    %rcx, (%rdi)           #save address to pointer
   10.15 -    ret
   10.16 -
   10.17 -
   10.18 -//Trick for 64 bit arch -- copies args from stack into regs, then does jmp to
   10.19 -// the top-level function, which was pointed to by the stack-ptr
   10.20 -.globl startUpTopLevelFn
   10.21 -startUpTopLevelFn:
   10.22 -    movq    %rdi      , %rsi #get second argument from first argument of switchSlv
   10.23 -    movq    0x08(%rsp), %rdi #get first argument from stack
   10.24 -    movq    (%rsp)    , %rax #get top-level function's addr from stack
   10.25 -    jmp     *%rax            #jump to the top-level function
   10.26 -
   10.27 -//Switches form CoreCtlr to either a normal Slv VP or the Master VP
   10.28 -//switch to VP's stack and frame ptr then jump to VP's next-instr-ptr
   10.29 -/* SlaveVP  offsets:
   10.30 - * 0x00  stackPtr
   10.31 - * 0x08 framePtr
   10.32 - * 0x10 resumeInstrPtr
   10.33 - * 0x18 coreCtlrFramePtr
   10.34 - * 0x20 coreCtlrStackPtr
   10.35 - *
   10.36 - * _VMSMasterEnv  offsets:
   10.37 - * 0x00 coreCtlrReturnPt
   10.38 - * 0x100 masterLock
   10.39 - */
   10.40 -.globl switchToSlv
   10.41 -switchToSlv:
   10.42 -    #SlaveVP in %rdi
   10.43 -    movq    %rsp      , 0x20(%rdi)   #save core ctlr stack pointer 
   10.44 -    movq    %rbp      , 0x18(%rdi)   #save core ctlr frame pointer
   10.45 -    movq    0x00(%rdi), %rsp         #restore stack pointer
   10.46 -    movq    0x08(%rdi), %rbp         #restore frame pointer
   10.47 -    movq    0x10(%rdi), %rax         #get jmp pointer
   10.48 -    jmp     *%rax                    #jmp to Slv
   10.49 -coreCtlrReturn:
   10.50 -    ret
   10.51 -
   10.52 -    
   10.53 -//switches to core controller. saves return address
   10.54 -/* SlaveVP  offsets:
   10.55 - * 0x00  stackPtr
   10.56 - * 0x08 framePtr
   10.57 - * 0x10 resumeInstrPtr
   10.58 - * 0x18 coreCtlrFramePtr
   10.59 - * 0x20 coreCtlrStackPtr
   10.60 - *
   10.61 - * _VMSMasterEnv  offsets:
   10.62 - * 0x00 coreCtlrReturnPt
   10.63 - * 0x100 masterLock
   10.64 - */
   10.65 -.globl switchToCoreCtlr
   10.66 -switchToCoreCtlr:
   10.67 -    #SlaveVP in %rdi
   10.68 -    movq    $SlvReturn, 0x10(%rdi)   #store return address
   10.69 -    movq    %rsp      , 0x00(%rdi)   #save stack pointer 
   10.70 -    movq    %rbp      , 0x08(%rdi)   #save frame pointer
   10.71 -    movq    0x20(%rdi), %rsp         #restore stack pointer
   10.72 -    movq    0x18(%rdi), %rbp         #restore frame pointer
   10.73 -    movq    $_VMSMasterEnv, %rcx
   10.74 -    movq        (%rcx), %rcx         #_VMSMasterEnv is pointer to struct
   10.75 -    movq    0x00(%rcx), %rax         #get CoreCtlrStartPt
   10.76 -    jmp     *%rax                    #jmp to CoreCtlr
   10.77 -SlvReturn:
   10.78 -    ret
   10.79 -
   10.80 -
   10.81 -
   10.82 -//switches to core controller from master. saves return address
   10.83 -//Releases masterLock so the next AnimationMaster can be executed
   10.84 -/* SlaveVP  offsets:
   10.85 - * 0x00  stackPtr
   10.86 - * 0x08 framePtr
   10.87 - * 0x10 resumeInstrPtr
   10.88 - * 0x18 coreCtlrFramePtr
   10.89 - * 0x20 coreCtlrStackPtr
   10.90 - *
   10.91 - * _VMSMasterEnv  offsets:
   10.92 - * 0x00 coreCtlrReturnPt
   10.93 - * 0x100 masterLock
   10.94 - */
   10.95 -.globl masterSwitchToCoreCtlr
   10.96 -masterSwitchToCoreCtlr:
   10.97 -    #SlaveVP in %rdi
   10.98 -    movq    $MasterReturn, 0x10(%rdi)   #store return address
   10.99 -    movq    %rsp      , 0x00(%rdi)   #save stack pointer 
  10.100 -    movq    %rbp      , 0x08(%rdi)   #save frame pointer
  10.101 -    movq    0x20(%rdi), %rsp         #restore stack pointer
  10.102 -    movq    0x18(%rdi), %rbp         #restore frame pointer
  10.103 -    movq    $_VMSMasterEnv, %rcx
  10.104 -    movq        (%rcx), %rcx         #_VMSMasterEnv is pointer to struct
  10.105 -    movq    0x00(%rcx), %rax         #get CoreCtlr return pt
  10.106 -    movl    $0x0      , 0x100(%rcx)  #release lock
  10.107 -    jmp     *%rax                    #jmp to CoreCtlr
  10.108 -MasterReturn:
  10.109 -    ret
  10.110 -
  10.111 -
  10.112 -/*Switch to terminateCoreCtlr
  10.113 - *This is called by endOSThreadFn, which is the top-level function given
  10.114 - * to a shutdown slave.  When such a slave gets switched to, by the core
  10.115 - * controller, it runs the top-level function, which calls this, which
  10.116 - * then calls terminateCoreCtlr, which ends the pthread.  Note, when get
  10.117 - * here, stack is already set up for switchSlv and Slv ptr is in %rdi.
  10.118 - *Do not save registers of Slv because this function will never return
  10.119 - *
  10.120 - * SlaveVP  offsets:
  10.121 - * 0x00  stackPtr
  10.122 - * 0x08 framePtr
  10.123 - * 0x10 resumeInstrPtr
  10.124 - * 0x18 coreCtlrFramePtr
  10.125 - * 0x20 coreCtlrStackPtr
  10.126 - *
  10.127 - * _VMSMasterEnv  offsets:
  10.128 - * 0x00 coreCtlrReturnPt
  10.129 - * 0x100 masterLock
  10.130 - */
  10.131 -.globl asmTerminateCoreCtlr
  10.132 -asmTerminateCoreCtlr:                #SlaveVP ptr is in %rdi
  10.133 -    movq    0x20(%rdi), %rsp         #restore stack pointer
  10.134 -    movq    0x18(%rdi), %rbp         #restore frame pointer
  10.135 -    movq    $terminateCoreCtlr, %rax
  10.136 -    jmp     *%rax                    #jmp to fn that ends the pthread
  10.137 -
  10.138 -
  10.139 -/*
  10.140 - * This one for the sequential version is special. It discards the current stack
  10.141 - * and returns directly from the coreCtlr after VMS_WL__dissipate_slaveVP was called
  10.142 - */
  10.143 -.globl asmTerminateCoreCtlrSeq
  10.144 -asmTerminateCoreCtlrSeq:
  10.145 -    #SlaveVP in %rdi
  10.146 -    movq    0x20(%rdi), %rsp         #restore stack pointer
  10.147 -    movq    0x18(%rdi), %rbp         #restore frame pointer
  10.148 -    #argument is in %rdi
  10.149 -    call    VMS_int__dissipate_slaveVP
  10.150 -    movq    %rbp      , %rsp        #goto the coreCtlrs stack
  10.151 -    pop     %rbp        #restore the old framepointer
  10.152 -    ret                 #return from core controller
  10.153 -    
  10.154 -
  10.155 -//Takes the return addr off the stack and saves into the loc pointed to by
  10.156 -// by the parameter passed in via rdi.  Return addr is at 0x8(%rbp) for 64bit
  10.157 -.globl VMS_int__save_return_into_ptd_to_loc_then_do_ret
  10.158 -VMS_int__save_return_into_ptd_to_loc_then_do_ret:
  10.159 -    movq 0x08(%rbp),   %rax  #get ret address, rbp is the same as in the calling function
  10.160 -    movq      %rax,   (%rdi) #write ret addr into addr passed as param field
  10.161 -    ret
  10.162 -
  10.163 -
  10.164 -//Assembly code changes the return addr on the stack to the one
  10.165 -// pointed to by the parameter, then returns. Stack's return addr is at 0x8(%rbp)
  10.166 -.globl VMS_int__return_to_addr_in_ptd_to_loc
  10.167 -VMS_int__return_to_addr_in_ptd_to_loc:
  10.168 -    movq   (%rdi),     %rax  #get return addr from addr passed as param
  10.169 -    movq    %rax, 0x08(%rbp) #write return addr to the stack of the caller
  10.170 -    ret
  10.171 -