changeset 8:9971d5905599 Dev_Univ tip

just capturing a point in the middle of development..
author Sean Halle <seanhalle@yahoo.com>
date Fri, 26 Jul 2013 12:12:34 -0700
parents 972ce554264c
children
files Defines/MEAS__macros_to_be_moved_to_langs.h Defines/PR_defs.h Defines/PR_defs__HW_constants.h PR.h PR__PI.h PR__WL.h PR__common.h PR__common_structs.h PR__int.h PR__structs.h Services_offered_by_PR/Measurement_and_Stats/MEAS__Counter_Recording.c Services_offered_by_PR/Measurement_and_Stats/MEAS__Counter_Recording.h Services_offered_by_PR/Measurement_and_Stats/MEAS__macros.h Services_offered_by_PR/Measurement_and_Stats/dependency.c Services_offered_by_PR/Measurement_and_Stats/dependency.h Services_offered_by_PR/Measurement_and_Stats/probes__wrapper_library.c Services_offered_by_PR/Measurement_and_Stats/probes__wrapper_library.h Services_offered_by_PR/Memory_Handling/vmalloc__structs.h Services_offered_by_PR/Memory_Handling/vmalloc__wrapper_library.h
diffstat 19 files changed, 1336 insertions(+), 1410 deletions(-) [+]
line diff
     1.1 --- a/Defines/MEAS__macros_to_be_moved_to_langs.h	Sun Jul 21 13:48:17 2013 -0700
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,64 +0,0 @@
     1.4 -/*
     1.5 - *  Copyright 2009 OpenSourceResearchInstitute.org
     1.6 - *  Licensed under GNU General Public License version 2
     1.7 - *
     1.8 - * Author: seanhalle@yahoo.com
     1.9 - * 
    1.10 - */
    1.11 -
    1.12 -#ifndef  _PR_LANG_SPEC_DEFS_H
    1.13 -#define	_PR_LANG_SPEC_DEFS_H
    1.14 -
    1.15 -
    1.16 -
    1.17 -//===================  Language-specific Measurement Stuff ===================
    1.18 -//
    1.19 -//TODO:  move these into the language implementation directories
    1.20 -//
    1.21 -
    1.22 -
    1.23 -//===========================================================================
    1.24 -//VCilk
    1.25 -
    1.26 -#ifdef VCILK
    1.27 -
    1.28 -/*These defines are used in the macros below*/
    1.29 -#define spawnHistIdx      1 //note: starts at 1
    1.30 -#define syncHistIdx       2
    1.31 -
    1.32 -#define MEAS__Make_Meas_Hists_for_VCilk( slave, magicNum ) \
    1.33 - do \
    1.34 - { VCilkLangEnv * \
    1.35 -   langEnv = PR_PI__get_lang_env_from_slave( slave, magicNum ); \ 
    1.36 -   langEnv->measHistsInfo = \
    1.37 -          makePrivDynArrayOfSize( (void***)&(_PRTopEnv->measHists), 200); \
    1.38 -   histInfo = langEnv->measHistsInfo;
    1.39 -    makeAMeasHist( histInfo, spawnHistIdx,      "Spawn",        50, 0, 200 ) \
    1.40 -    makeAMeasHist( histInfo, syncHistIdx,       "Sync",         50, 0, 200 ) \
    1.41 - }while(FALSE); /* macro magic to protect local vars from name collision */
    1.42 -
    1.43 -#define Meas_startSpawn fixme; /* changed names -- added __Cilk to end*/
    1.44 -    
    1.45 -#define Meas_startSpawn__Cilk \
    1.46 -    int32 startStamp, endStamp; \
    1.47 -    saveLowTimeStampCountInto( startStamp ); \
    1.48 -
    1.49 -#define Meas_endSpawn__Cilk \
    1.50 -    saveLowTimeStampCountInto( endStamp ); \
    1.51 -    addIntervalToHist( startStamp, endStamp, \
    1.52 -                             _PRTopEnv->measHists[ spawnHistIdx ] );
    1.53 -
    1.54 -#define Meas_startSync__Cilk \
    1.55 -    int32 startStamp, endStamp; \
    1.56 -    saveLowTimeStampCountInto( startStamp ); \
    1.57 -
    1.58 -#define Meas_endSync__Cilk \
    1.59 -    saveLowTimeStampCountInto( endStamp ); \
    1.60 -    addIntervalToHist( startStamp, endStamp, \
    1.61 -                             _PRTopEnv->measHists[ syncHistIdx ] );
    1.62 -#endif
    1.63 -
    1.64 -//===========================================================================
    1.65 -
    1.66 -#endif	/* _PR_DEFS_H */
    1.67 -
     2.1 --- a/Defines/PR_defs.h	Sun Jul 21 13:48:17 2013 -0700
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,43 +0,0 @@
     2.4 -/*
     2.5 - *  Copyright 2009 OpenSourceResearchInstitute.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  _PR_DEFS_MAIN_H
    2.13 -#define	_PR_DEFS_MAIN_H
    2.14 -#define _GNU_SOURCE
    2.15 -
    2.16 -//===========================  PR-wide defs  ===============================
    2.17 -
    2.18 -#define SUCCESS 0
    2.19 -
    2.20 -   //only after macro-expansion are the defs of writePrivQ, aso looked up
    2.21 -   // so these defs can be at the top, and writePrivQ defined later on..
    2.22 -#define writePRQ     writePrivQ
    2.23 -#define readPRQ      readPrivQ
    2.24 -#define makePRQ      makePrivQ
    2.25 -#define numInPRQ     numInPrivQ
    2.26 -#define PRQueueStruc PrivQueueStruc
    2.27 -
    2.28 -
    2.29 -/*The language should re-define this, but need a default in case it doesn't*/
    2.30 -#ifndef _LANG_NAME_
    2.31 -#define _LANG_NAME_ ""
    2.32 -#endif
    2.33 -
    2.34 -//======================  Hardware Constants ============================
    2.35 -#include "PR_defs__HW_constants.h"
    2.36 -
    2.37 -//======================  Macros  ======================
    2.38 -   //for turning macros and other PR features on and off
    2.39 -#include "PR_defs__turn_on_and_off.h"
    2.40 -
    2.41 -#include "../Services_Offered_by_PR/Debugging/DEBUG__macros.h"
    2.42 -#include "../Services_Offered_by_PR/Measurement_and_Stats/MEAS__macros.h"
    2.43 -
    2.44 -//===========================================================================
    2.45 -#endif	/*  */
    2.46 -
     3.1 --- a/Defines/PR_defs__HW_constants.h	Sun Jul 21 13:48:17 2013 -0700
     3.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.3 @@ -1,67 +0,0 @@
     3.4 -/*
     3.5 - *  Copyright 2012 OpenSourceResearchInstitute
     3.6 - *  Licensed under BSD
     3.7 - *
     3.8 - * Author: seanhalle@yahoo.com
     3.9 - * 
    3.10 - */
    3.11 -
    3.12 -#ifndef _PR_HW_SPEC_DEFS_H
    3.13 -#define	_PR_HW_SPEC_DEFS_H
    3.14 -#define _GNU_SOURCE
    3.15 -
    3.16 -
    3.17 -//=========================  Hardware related Constants =====================
    3.18 -   //This value is the number of hardware threads in the shared memory
    3.19 -   // machine
    3.20 -#define NUM_CORES        4
    3.21 -   //Now, check if sequential mode is on, and set num cores to 1, so that
    3.22 -   // lang plugin code doesn't have to check for sequential mode
    3.23 -#ifdef DEBUG__TURN_ON_SEQUENTIAL_MODE
    3.24 -   #undef  NUM_CORES
    3.25 -   #define NUM_CORES 1
    3.26 -#endif
    3.27 -
    3.28 -
    3.29 -   //tradeoff amortizing master fixed overhead vs imbalance potential
    3.30 -   // when work-stealing, can make bigger, at risk of losing cache affinity
    3.31 -#define NUM_ANIM_SLOTS  1
    3.32 -
    3.33 -   //number of PRLangEnv structs created inside a process -- can't start more
    3.34 -   // than this many langlets inside a single process
    3.35 -#define NUM_IN_COLLECTION 64
    3.36 -
    3.37 -   //These are for backoff inside core-loop, which reduces lock contention
    3.38 -#define NUM_REPS_W_NO_WORK_BEFORE_YIELD      10
    3.39 -#define NUM_REPS_W_NO_WORK_BEFORE_BACKOFF    2
    3.40 -#define MASTERLOCK_RETRIES_BEFORE_YIELD      100
    3.41 -#define NUM_TRIES_BEFORE_DO_BACKOFF          10
    3.42 -#define GET_LOCK_BACKOFF_WEIGHT 100
    3.43 -   
    3.44 -   // stack size in virtual processors created
    3.45 -#define VIRT_PROCR_STACK_SIZE 0x8000 /* 32K */
    3.46 -
    3.47 -   // memory for PR_int__malloc
    3.48 -#define MALLOC_ADDITIONAL_MEM_FROM_OS_SIZE 0x8000000 /* 128M */
    3.49 -
    3.50 -   //Frequency of TS counts -- have to do tests to verify
    3.51 -   //NOTE: turn off (in BIOS)  TURBO-BOOST and SPEED-STEP else won't be const
    3.52 -#define TSCOUNT_FREQ 3180000000
    3.53 -#define TSC_LOW_CYCLES 27
    3.54 -#define TSC_LOWHI_CYCLES 45
    3.55 -
    3.56 -#define CACHE_LINE_SZ  256
    3.57 -#define PAGE_SIZE     4096
    3.58 -
    3.59 -//To prevent false-sharing, aligns a variable to a cache-line boundary.
    3.60 -//No need to use for local vars because those are never shared between cores
    3.61 -#define __align_to_cacheline__ __attribute__ ((aligned(CACHE_LINE_SZ)))
    3.62 -
    3.63 -//aligns a pointer to cacheline. The memory area has to contain at least
    3.64 -//CACHE_LINE_SZ bytes more then needed
    3.65 -#define __align_address(ptr) ((void*)(((uintptr_t)(ptr))&((uintptr_t)(~0x0FF))))
    3.66 -
    3.67 -//===========================================================================
    3.68 -
    3.69 -#endif	/* _PR_DEFS_H */
    3.70 -
     4.1 --- a/PR.h	Sun Jul 21 13:48:17 2013 -0700
     4.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.3 @@ -1,100 +0,0 @@
     4.4 -/*
     4.5 - *  Copyright 2012 OpenSourceResearchInstitute.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 _PR_H
    4.13 -#define	_PR_H
    4.14 -#define _GNU_SOURCE
    4.15 -
    4.16 -#include "DynArray/DynArray.h"
    4.17 -#include "Hash_impl/PrivateHash.h"
    4.18 -#include "Histogram/Histogram.h"
    4.19 -#include "Queue_impl/PrivateQueue.h"
    4.20 -
    4.21 -#include "PR_primitive_data_types.h"
    4.22 -#include "Services_Offered_by_PR/Memory_Handling/vmalloc.h"
    4.23 -
    4.24 -#include <pthread.h>
    4.25 -#include <sys/time.h>
    4.26 -
    4.27 -//=================  Defines: included from separate files  =================
    4.28 -//
    4.29 -// Note: ALL defines are in other files, none are in here
    4.30 -//
    4.31 -#include "Defines/PR_defs.h"
    4.32 -
    4.33 -
    4.34 -//================================ Typedefs =================================
    4.35 -//
    4.36 -#include "PR__structs.h"
    4.37 -
    4.38 -//============================ HW Dependent Fns ================================
    4.39 -
    4.40 -#include "HW_Dependent_Primitives/PR__HW_measurement.h"
    4.41 -#include "HW_Dependent_Primitives/PR__primitives.h"
    4.42 -
    4.43 -
    4.44 -//=============================  Global Vars ================================
    4.45 -
    4.46 -volatile TopEnv      *_PRTopEnv __align_to_cacheline__;
    4.47 -
    4.48 -   //these are global, but only used for startup and shutdown
    4.49 -pthread_t       coreCtlrThdHandles[ NUM_CORES ]; //pthread's virt-procr state
    4.50 -ThdParams      *coreCtlrThdParams [ NUM_CORES ];
    4.51 -
    4.52 -pthread_mutex_t suspendLock;
    4.53 -pthread_cond_t  suspendCond;
    4.54 -
    4.55 -//=========================  Function Prototypes  ===========================
    4.56 -/* MEANING OF   WL  PI  SS  int PROS
    4.57 - * These indicate which places the function is safe to use.  They stand for:
    4.58 - * 
    4.59 - * WL   Wrapper Library -- wrapper lib code should only use these
    4.60 - * PI   Plugin          -- plugin code should only use these
    4.61 - * SS   Startup and Shutdown -- designates these relate to startup & shutdown
    4.62 - * int32internal to PR -- should not be used in wrapper lib or plugin
    4.63 - * PROS means "OS functions for applications to use"
    4.64 - * 
    4.65 - * PR_int__ functions touch internal PR data structs and are only safe
    4.66 - *  to be used inside the master lock.  However, occasionally, they appear
    4.67 - * in wrapper-lib or plugin code.  In those cases, very careful analysis
    4.68 - * has been done to be sure no concurrency issues could arise.
    4.69 - * 
    4.70 - * PR_WL__ functions are all safe for use outside the master lock.
    4.71 - * 
    4.72 - * PR_OS are only safe for applications to use -- they're like a second
    4.73 - * language mixed in -- but they can't be used inside plugin code, and
    4.74 - * aren't meant for use in wrapper libraries, because they are themselves
    4.75 - * wrapper-library calls!
    4.76 - */
    4.77 -
    4.78 -inline bool32 masterFunction( AnimSlot  *slot );
    4.79 -
    4.80 -//============== include internally used fn prototypes ================
    4.81 -
    4.82 -//include fn prototypes used internally in the proto-runtime implementation
    4.83 -#include "PR__int.h"
    4.84 -
    4.85 -//include fn prototypes used by plugin
    4.86 -#include "PR__PI.h"
    4.87 -
    4.88 -//include fn prototype used by wrapper library
    4.89 -#include "PR__WL.h"
    4.90 -
    4.91 -//=================================
    4.92 -#define implement_me() printf("Unimpl Fn: \n%s \n%s : %d\n", __FILE__, __FUNCTION__, __LINE__)
    4.93 -//#define fix_me printf("Fix me at: \n%s \n%s : %s\n", __FILE__, __FUNCTION__, __LINE__)
    4.94 -
    4.95 -
    4.96 -//========================= Services =======================
    4.97 -#include "Services_Offered_by_PR/Measurement_and_Stats/probes.h"
    4.98 -#include "Services_Offered_by_PR/Services_Language/PRServ.h"
    4.99 -//#include  "Services_Offered_by_PR/Services_Language/libPRServ.h"
   4.100 -
   4.101 -//================================================
   4.102 -#endif	/* _PR_H */
   4.103 -
     5.1 --- a/PR__PI.h	Sun Jul 21 13:48:17 2013 -0700
     5.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.3 @@ -1,195 +0,0 @@
     5.4 -/*
     5.5 - *  Copyright 2009 OpenSourceResearchInstitute.org
     5.6 - *  Licensed under GNU General Public License version 2
     5.7 - *
     5.8 - * Author: seanhalle@yahoo.com
     5.9 - * 
    5.10 - */
    5.11 -
    5.12 -#ifndef _PR__PI_H
    5.13 -#define	_PR__PI_H
    5.14 -#define _GNU_SOURCE
    5.15 -
    5.16 -
    5.17 -#include "PR_primitive_data_types.h"
    5.18 -
    5.19 -//=========================  Function Prototypes  ===========================
    5.20 -/* MEANING OF   WL  PI  SS  int PROS
    5.21 - * These indicate which places the function is safe to use.  They stand for:
    5.22 - * 
    5.23 - * WL   Wrapper Library -- wrapper lib code should only use these
    5.24 - * PI   Plugin          -- plugin code should only use these
    5.25 - * SS   Startup and Shutdown -- designates these relate to startup & shutdown
    5.26 - * int32internal to PR -- should not be used in wrapper lib or plugin
    5.27 - * PROS means "OS functions for applications to use"
    5.28 - * 
    5.29 - * PR_int__ functions touch internal PR data structs and are only safe
    5.30 - *  to be used inside the master lock.  However, occasionally, they appear
    5.31 - * in wrapper-lib or plugin code.  In those cases, very careful analysis
    5.32 - * has been done to be sure no concurrency issues could arise.
    5.33 - * 
    5.34 - * PR_WL__ functions are all safe for use outside the master lock.
    5.35 - * 
    5.36 - * PROS are only safe for applications to use -- they're like a second
    5.37 - * language mixed in -- but they can't be used inside plugin code, and
    5.38 - * aren't meant for use in wrapper libraries, because they are themselves
    5.39 - * wrapper-library calls!
    5.40 - */
    5.41 -
    5.42 -#define \
    5.43 -PR_PI__create_slaveVP   PR_int__create_slaveVP_helper
    5.44 -
    5.45 -//==============
    5.46 -//=== Lang Data
    5.47 -//=
    5.48 -#define \
    5.49 -PR_PI__give_lang_data_from_slave   PR_int__give_lang_data_from_slave
    5.50 -#define \
    5.51 -PR_SS__give_lang_data_from_slave   PR_int__give_lang_data_from_slave
    5.52 -
    5.53 -
    5.54 -//============
    5.55 -//=== Lang Env
    5.56 -//=
    5.57 -#define \
    5.58 -PR_PI__give_proto_lang_env_for_slave   PR_int__give_proto_lang_env_for_slave
    5.59 -#define \
    5.60 -PR_PI__give_lang_env_for_slave   PR_int__give_lang_env_for_slave
    5.61 -#define \
    5.62 -PR_PI__give_lang_env_from_process   PR_int__give_lang_env_from_process
    5.63 -
    5.64 -
    5.65 -//=========
    5.66 -//=== Meta Task
    5.67 -//=
    5.68 -#define \
    5.69 -PR_PI__give_lang_meta_task_from_slave    PR_int__give_lang_meta_task_from_slave
    5.70 -#define \
    5.71 -PR_PI__give_prolog_of_lang_meta_task   PR_int__give_prolog_of_lang_meta_task
    5.72 -
    5.73 -SlaveVP *
    5.74 -PR_PI__give_slave_lang_meta_task_is_assigned_to( void *langMetaTask );
    5.75 -
    5.76 -#define \
    5.77 -PR_PI__free_lang_meta_task_and_remove_from_slave    PR_int__free_lang_meta_task_and_remove_from_coll
    5.78 -
    5.79 -#define \
    5.80 -PR_PI__free_lang_meta_task    PR_int__free_lang_meta_task
    5.81 -
    5.82 -void
    5.83 -PR_PI__set_no_del_flag_in_lang_meta_task( void *langMetaTask );
    5.84 -void
    5.85 -PR_PI__clear_no_del_flag_in_lang_meta_task( void *langMetaTask );
    5.86 -
    5.87 -//==========
    5.88 -//===
    5.89 -//=
    5.90 -#define \
    5.91 -PR_PI__give_ID_from_lang_meta_task   PR__give_ID_from_lang_meta_task
    5.92 -#define \
    5.93 -PR_PI__give_ID_from_slave   PR__give_ID_from_slave
    5.94 -
    5.95 -//=============
    5.96 -//===
    5.97 -//=
    5.98 -#define \
    5.99 -PR_PI__put_slave_into_slot   PR_int__put_slave_into_slot
   5.100 -#define \
   5.101 -PR_PI__put_task_into_slot    PR_int__put_task_into_slot
   5.102 -
   5.103 -PRReqst *
   5.104 -PR_PI__take_next_request_out_of( SlaveVP *slaveWithReq );
   5.105 -
   5.106 -#define \
   5.107 -PR_PI__take_lang_reqst_from( req )   req->langReq
   5.108 -
   5.109 -void
   5.110 -PR_PI__resume_slave_in_PRServ( SlaveVP *slave );
   5.111 -
   5.112 -#define \
   5.113 -PR_PI__malloc   PR_int__malloc
   5.114 -#define \
   5.115 -PR_PI__malloc_aligned   PR_int__malloc_aligned
   5.116 -#define \
   5.117 -PR_PI__free  PR_int__free
   5.118 -
   5.119 -
   5.120 -#define \
   5.121 -PR_PI__throw_exception   PR_int__throw_exception
   5.122 -
   5.123 -//===============  Startup and Shutdown  ================
   5.124 -//===
   5.125 -//=
   5.126 -void
   5.127 -PR_SS__create_topEnv();
   5.128 -
   5.129 -AnimSlot **
   5.130 -PR_SS__create_anim_slots( int32 coreSlotsAreOn );
   5.131 -
   5.132 -void
   5.133 -PR_SS__create_the_coreCtlr_OS_threads();
   5.134 -
   5.135 -//===================
   5.136 -void *
   5.137 -PR_SS__create_lang_env( int32 size, SlaveVP *slave, int32 magicNum );
   5.138 -
   5.139 -void
   5.140 -PR_SS__register_assigner( SlaveAssigner assigner, SlaveVP *seedVP, int32 magicNum );
   5.141 -void
   5.142 -PR_SS__register_lang_shutdown_handler( LangShutdownHdlr shutdownHdlr, SlaveVP *seedVP,
   5.143 -                                  int32 magicNum );
   5.144 -void
   5.145 -PR_SS__register_lang_data_creator( LangDataCreator langDataCreator, 
   5.146 -                                              SlaveVP *seedVP, int32 magicNum );
   5.147 -void
   5.148 -PR_SS__register_lang_meta_task_creator( LangDataCreator langMetaTaskCreator, 
   5.149 -                                              SlaveVP *seedVP, int32 magicNum );
   5.150 -void
   5.151 -PR_SS__register_make_slave_ready_fn( MakeSlaveReadyFn fn, SlaveVP *seedVP,
   5.152 -                                                               int32 magicNum );
   5.153 -void
   5.154 -PR_SS__register_make_task_ready_fn( MakeTaskReadyFn fn, SlaveVP *seedVP,
   5.155 -                                                               int32 magicNum );
   5.156 -//===================
   5.157 -
   5.158 -void
   5.159 -PR_SS__end_process_normally( PRProcess *process );
   5.160 -
   5.161 -void
   5.162 -PR_SS__shutdown_OS_threads();
   5.163 -
   5.164 -SlaveVP* 
   5.165 -PR_SS__create_shutdown_slave();
   5.166 -
   5.167 -void
   5.168 -PR_SS__cleanup_at_end_of_shutdown();
   5.169 - 
   5.170 -void
   5.171 -PR_SS__print_out_measurements();
   5.172 -
   5.173 -void
   5.174 -PR_SS__wait_for_PR_to_shutdown();
   5.175 -
   5.176 -
   5.177 -//=============================
   5.178 -//===
   5.179 -//=
   5.180 -
   5.181 -#define \
   5.182 -PR_SS__give_proto_lang_env_for_slave   PR_int__give_proto_lang_env_for_slave
   5.183 -
   5.184 -#define \
   5.185 -PR_SS__give_lang_meta_task_from_slave   PR_int__give_lang_meta_task_from_slave
   5.186 -#define \
   5.187 -PR_SS__give_lang_env_for_slave   PR_int__give_lang_env_for_slave
   5.188 -#define \
   5.189 -PR_SS__give_lang_env_from_process   PR_int__give_lang_env_from_process
   5.190 -
   5.191 -#define \
   5.192 -PR_SS__malloc  PR_WL__malloc /*SS happens outside the Master*/
   5.193 -#define \
   5.194 -PR_SS__free    PR_WL__free
   5.195 -
   5.196 -//================================================
   5.197 -#endif	/* _PR__PI_H */
   5.198 -
     6.1 --- a/PR__WL.h	Sun Jul 21 13:48:17 2013 -0700
     6.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.3 @@ -1,154 +0,0 @@
     6.4 -/*
     6.5 - *  Copyright 2009 OpenSourceResearchInstitute.org
     6.6 - *  Licensed under GNU General Public License version 2
     6.7 - *
     6.8 - * Author: seanhalle@yahoo.com
     6.9 - * 
    6.10 - */
    6.11 -
    6.12 - 
    6.13 - 
    6.14 -/* This header defines the PR functions available to the language's
    6.15 - *  wrapper library.
    6.16 - */
    6.17 - 
    6.18 -#ifndef _PR__WL_H
    6.19 -#define	_PR__WL_H
    6.20 -#define _GNU_SOURCE
    6.21 -
    6.22 -#include "PR__common/PR__primitive_data_types.h"
    6.23 -#include "PR__common/PR__common_structs.h"
    6.24 -//=========================  Function Prototypes  ===========================
    6.25 -/* MEANING OF   WL  PI  SS  int PROS
    6.26 - * These indicate which places the function is safe to use.  They stand for:
    6.27 - * 
    6.28 - * WL   Wrapper Library -- wrapper lib code should only use these
    6.29 - * PI   Plugin          -- plugin code should only use these
    6.30 - * SS   Startup and Shutdown -- designates these relate to startup & shutdown
    6.31 - * int32internal to PR -- should not be used in wrapper lib or plugin
    6.32 - * PROS means "OS functions for applications to use"
    6.33 - * 
    6.34 - * PR_int__ functions touch internal PR data structs and are only safe
    6.35 - *  to be used inside the master lock.  However, occasionally, they appear
    6.36 - * in wrapper-lib or plugin code.  In those cases, very careful analysis
    6.37 - * has been done to be sure no concurrency issues could arise.
    6.38 - * 
    6.39 - * PR_WL__ functions are all safe for use outside the master lock.
    6.40 - * 
    6.41 - * PROS are only safe for applications to use -- they're like a second
    6.42 - * language mixed in -- but they can't be used inside plugin code, and
    6.43 - * aren't meant for use in wrapper libraries, because they are themselves
    6.44 - * wrapper-library calls!
    6.45 - */
    6.46 -
    6.47 -//============== Top level Fns called from main   ===============
    6.48 -void
    6.49 -PR__start();
    6.50 -
    6.51 -PRProcess *
    6.52 -PR__create_process( BirthFnPtr seed_Fn, void *seedData );
    6.53 -
    6.54 -void
    6.55 -PR__end_seedVP( SlaveVP *seedSlv );
    6.56 -
    6.57 -void
    6.58 -PR__end_process_from_inside( SlaveVP *seedSlv );
    6.59 -
    6.60 -void *
    6.61 -PR__give_results_from_process_when_ready( PRProcess *process );
    6.62 -
    6.63 -void
    6.64 -PR__wait_for_process_to_end( PRProcess *process );
    6.65 -
    6.66 -void
    6.67 -PR__wait_for_all_activity_to_end();
    6.68 -
    6.69 -void
    6.70 -PR__shutdown();
    6.71 -
    6.72 -#define \
    6.73 -PR__create_taskID_of_size   PR_WL__create_taskID_of_size
    6.74 -
    6.75 -inline
    6.76 -int32 *
    6.77 -PR__give_ID_from_slave( SlaveVP *animSlv, int32 magicNumber );
    6.78 -
    6.79 -inline
    6.80 -int32 *
    6.81 -PR__give_ID_from_lang_meta_task( void *_task );
    6.82 -
    6.83 -#define \
    6.84 -PR__malloc  PR_WL__malloc
    6.85 -
    6.86 -#define \
    6.87 -PR__free    PR_WL__free
    6.88 -
    6.89 -
    6.90 -
    6.91 -//============== include internally used fn prototypes ================
    6.92 -#include "PR__int.h"
    6.93 -
    6.94 -
    6.95 -#define \
    6.96 -PR_WL__create_slaveVP   PR_int__create_slaveVP_helper
    6.97 -
    6.98 -#define \
    6.99 -PR_WL__give_lang_meta_task_from_slave   PR_int__give_lang_meta_task_from_slave
   6.100 -
   6.101 -#define \
   6.102 -PR_WL__give_prolog_of_lang_meta_task   PR_int__give_prolog_of_lang_meta_task
   6.103 -
   6.104 -//==============  Request Related  ===============
   6.105 -
   6.106 -void
   6.107 -PR_WL__suspend_slaveVP_and_send_req( SlaveVP *callingSlv );
   6.108 -
   6.109 -inline void
   6.110 -PR_WL__add_lang_request_in_mallocd_PRReqst( void *langReqData, 
   6.111 -                                                          SlaveVP *callingSlv );
   6.112 -
   6.113 -inline void
   6.114 -PR_WL__send_lang_request( void *langReq, RequestHandler handler, 
   6.115 -                                          SlaveVP *callingSlv, int32 magicNum );
   6.116 -
   6.117 -void
   6.118 -PR_WL__send_create_slaveVP_req( void *langReq, int32 *ID, CreateHandler handler, 
   6.119 -                                SlaveVP *reqstingSlv, int32 magicNum );
   6.120 -
   6.121 -void inline
   6.122 -PR_WL__send_end_slave_req( void *langReq, RequestHandler handler, 
   6.123 -                                       SlaveVP *slvToDissipate, int32 magicNum );
   6.124 -
   6.125 -inline void
   6.126 -PR_WL__send_service_request( void *langReqData, SlaveVP *callingSlv );
   6.127 -
   6.128 -inline void
   6.129 -PR_WL__send_lang_shutdown_request( SlaveVP *callingSlv, int32 magicNum );
   6.130 -
   6.131 -inline 
   6.132 -int32 *
   6.133 -PR_WL__create_taskID_of_size( int32 numInts );
   6.134 -
   6.135 -//======================== MEASUREMENT ======================
   6.136 -uint64
   6.137 -PR_WL__give_num_plugin_cycles();
   6.138 -uint32
   6.139 -PR_WL__give_num_plugin_animations();
   6.140 -
   6.141 -
   6.142 -//========================= Utilities =======================
   6.143 -void
   6.144 -PR_WL__throw_exception( char *msgStr, SlaveVP *reqstSlv,  PRExcp *excpData );
   6.145 -#define PR_App__throw_exception PR_WL__throw_exception
   6.146 -
   6.147 -
   6.148 -//=======================================================================
   6.149 -
   6.150 -//========================= Services =======================
   6.151 -//#include "Services_Offered_by_PR/Measurement_and_Stats/probes.h"
   6.152 -//#include  "Services_Offered_by_PR/Services_Language/PRServ.h"
   6.153 -//#include  "Services_Offered_by_PR/Services_Language/libPRServ.h"
   6.154 -
   6.155 -//================================================
   6.156 -#endif	/* _PR_H */
   6.157 -
     7.1 --- a/PR__common.h	Sun Jul 21 13:48:17 2013 -0700
     7.2 +++ b/PR__common.h	Fri Jul 26 12:12:34 2013 -0700
     7.3 @@ -17,7 +17,10 @@
     7.4  
     7.5  #include "PR__primitive_data_types.h"
     7.6  #include "PR__common_structs.h"
     7.7 -//#include "Services_Offered_by_PR/Memory_Handling/vmalloc.h"
     7.8 +#include "Services_Offered_by_PR/Memory_Handling/vmalloc__wrapper_library.h"
     7.9 +#include "Services_offered_by_PR/Debugging/DEBUG__macros.h"
    7.10 +#include "Services_offered_by_PR/Measurement_and_Stats/MEAS__macros.h"
    7.11 +#include "Services_offered_by_PR/Measurement_and_Stats/probes__wrapper_library.h"
    7.12  
    7.13  //#include <pthread.h>
    7.14  //#include <sys/time.h>
     8.1 --- a/PR__common_structs.h	Sun Jul 21 13:48:17 2013 -0700
     8.2 +++ b/PR__common_structs.h	Fri Jul 26 12:12:34 2013 -0700
     8.3 @@ -6,13 +6,27 @@
     8.4   * 
     8.5   */
     8.6  
     8.7 -#ifndef _PR__structs_H
     8.8 -#define	_PR__structs_H
     8.9 +#ifndef _PR__common_structs_H
    8.10 +#define	_PR__common_structs_H
    8.11  #define _GNU_SOURCE
    8.12  
    8.13 -//#include <pthread.h>
    8.14 -//#include <sys/time.h>
    8.15 +#include <pthread.h>
    8.16 +#include <sys/time.h>
    8.17  
    8.18 +#include "PR_defs__turn_on_and_off.h"
    8.19 +#include "PR__primitive_data_types.h"
    8.20 +#include "Services_offered_by_PR/Measurement_and_Stats/MEAS__macros.h"
    8.21 +#include "Services_offered_by_PR/Debugging/DEBUG__macros.h"
    8.22 +
    8.23 +
    8.24 +#include "Histogram/Histogram.h"     //reqd by PRProcess
    8.25 +#include "Hash_impl/PrivateHash.h"   //reqd by PRProcess
    8.26 +#include "DynArray/DynArray.h"       //reqd by PRProcess
    8.27 +#include "Queue_impl/PrivateQueue.h" //reqd by PRLangEnv, in turn reqd by PRProcess
    8.28 +
    8.29 +
    8.30 +//#include "HW_Dependent_Primitives/PR__HW_measurement.h"
    8.31 +//#include "HW_Dependent_Primitives/PR__primitives.h"
    8.32  
    8.33  //================================ Typedefs =================================
    8.34  //===
    8.35 @@ -21,17 +35,17 @@
    8.36  
    8.37  //typedef unsigned long long    TSCount;
    8.38  
    8.39 -//typedef struct _AnimSlot      AnimSlot;
    8.40 -//typedef struct _PRReqst       PRReqst;
    8.41 +typedef struct _AnimSlot      AnimSlot;
    8.42 +typedef struct _PRReqst       PRReqst;
    8.43  typedef struct _SlaveVP       SlaveVP;
    8.44  //typedef struct _MasterVP      MasterVP;
    8.45  typedef struct _IntervalProbe IntervalProbe;
    8.46 -//typedef struct _PRLangEnv     PRLangEnv;  //a prolog
    8.47 +typedef struct _PRLangEnv     PRLangEnv;  //a prolog
    8.48  typedef struct _PRMetaTask    PRMetaTask; //a prolog
    8.49 -//typedef struct _PRLangData    PRLangData; //a prolog
    8.50 -//typedef struct _PRCollElem    PRCollElem; //generic form of the prologs
    8.51 +typedef struct _PRLangData    PRLangData; //a prolog
    8.52 +typedef struct _PRCollElem    PRCollElem; //generic form of the prologs
    8.53  
    8.54 -//typedef bool32   (*SlaveAssigner)  ( void *, AnimSlot* ); //langEnv, slot for HW info
    8.55 +typedef bool32   (*SlaveAssigner)  ( void *, AnimSlot* ); //langEnv, slot for HW info
    8.56  typedef void     (*RequestHandler) ( void *, SlaveVP *, void * ); //req, slv, langEnv
    8.57  typedef void    *(*CreateHandler)  ( void *, SlaveVP *, void * ); //req, slv, langEnv
    8.58  typedef void     (*LangShutdownHdlr) ( void * ); //langEnv
    8.59 @@ -39,20 +53,15 @@
    8.60  typedef void     (*LangDataFreer)    ( void * ); //lang data to free
    8.61  typedef void    *(*LangMetaTaskCreator)( SlaveVP * );  //when slave has no meta task for magic num 
    8.62  typedef void     (*LangMetaTaskFreer)  ( void * ); //lang meta task to free
    8.63 -//typedef void     (*MakeSlaveReadyFn)   ( SlaveVP *, void * ); //slave and langEnv
    8.64 -//typedef void     (*MakeTaskReadyFn)    ( void *, void * ); //langTask and langEnv
    8.65 +typedef void     (*MakeSlaveReadyFn)   ( SlaveVP *, void * ); //slave and langEnv
    8.66 +typedef void     (*MakeTaskReadyFn)    ( void *, void * ); //langTask and langEnv
    8.67  typedef void     (*BirthFnPtr)  ( void *, SlaveVP * ); //initData, animSlv
    8.68  typedef void       BirthFn      ( void *, SlaveVP * ); //initData, animSlv
    8.69 -//typedef void     (*ResumeSlvFnPtr) ( SlaveVP *, void * );
    8.70 +typedef void     (*ResumeSlvFnPtr) ( SlaveVP *, void * );
    8.71        //=========== MEASUREMENT STUFF ==========
    8.72 -//        MEAS__Insert_Counter_Handler
    8.73 +        MEAS__Insert_Counter_Handler
    8.74        //========================================
    8.75  
    8.76 -//============================ HW Dependent Fns ================================
    8.77 -
    8.78 -//#include "HW_Dependent_Primitives/PR__HW_measurement.h"
    8.79 -//#include "HW_Dependent_Primitives/PR__primitives.h"
    8.80 -
    8.81  
    8.82  typedef struct
    8.83   { //These are set by the plugin during startup and the application
    8.84 @@ -68,7 +77,7 @@
    8.85   * stores information about what percent of CPU time the program is getting, 
    8.86   * 
    8.87   */
    8.88 -/*
    8.89 +
    8.90  typedef struct
    8.91   { 
    8.92     int32     numEnvsWithWork;
    8.93 @@ -112,7 +121,7 @@
    8.94        //==========================================
    8.95   }
    8.96  PRProcess;
    8.97 -*/
    8.98 +
    8.99  
   8.100  //============= Request Related ===========
   8.101  //
   8.102 @@ -255,82 +264,6 @@
   8.103     MultiLang      
   8.104   };
   8.105   
   8.106 -/* The one and only global variable, holds many odds and ends
   8.107 - */
   8.108 -typedef struct
   8.109 - {    //The offsets of these fields are hard-coded into assembly
   8.110 -   void            *coreCtlrReturnPt;    //offset to this field used in asm
   8.111 -   int8             falseSharePad1[256 - sizeof(void*)];
   8.112 -   int32            masterLock;          //offset to this field used in asm
   8.113 -   int8             falseSharePad2[256 - sizeof(int32)];
   8.114 -   int32            wrapperLock;         //offset to this field used in asm
   8.115 -   int8             falseSharePad3[256 - sizeof(int32)];
   8.116 -   int32            mallocLock;          //offset to this field used in asm
   8.117 -   int8             falseSharePad4[256 - sizeof(int32)];
   8.118 -      //============ below this, no fields are used in asm =============
   8.119 -
   8.120 -      //Basic PR infrastructure
   8.121 -//   enum PRMode      mode;
   8.122 -   SlaveVP        **masterVPs;
   8.123 -   AnimSlot      ***allAnimSlots;
   8.124 -   PrivQueueStruc  *slaveRecycleQ;
   8.125 -   SlaveVP         *slotTaskSlvs[NUM_CORES][NUM_ANIM_SLOTS];
   8.126 -   SlaveVP         *idleSlv[NUM_CORES][NUM_ANIM_SLOTS];
   8.127 -   
   8.128 -      //Memory management related
   8.129 -   MallocArrays    *freeLists;
   8.130 -   int32            amtOfOutstandingMem;//total currently allocated
   8.131 -
   8.132 -      //Random number seeds -- random nums used in various places  
   8.133 -   uint32_t         seed1;
   8.134 -   uint32_t         seed2;
   8.135 -
   8.136 -   PRSysMetaInfo   *metaInfo; //info about this PR system -- vers, build, etc
   8.137 -   
   8.138 -   //============== This only used by multi-lang mode ============
   8.139 -   PRProcess      **processes;
   8.140 -   int32            numProcesses;
   8.141 -   int32            currProcessIdx;    //used to choose which process gets slot
   8.142 -   int32            firstProcessReady; //use while starting up coreCtlr
   8.143 -   
   8.144 -      //initialize flags for waiting for activity within PR to complete
   8.145 -   bool32           allActivityIsDone;
   8.146 -   pthread_mutex_t  activityDoneLock;
   8.147 -   pthread_cond_t   activityDoneCond;   
   8.148 -
   8.149 -   SlaveAssigner    overrideAssigner;
   8.150 -   
   8.151 -   //============== Below this is only used by single-lang mode ==============
   8.152 -   void            *protoLangEnv;
   8.153 -      //Slave creation -- global count of slaves existing, across langs and processes
   8.154 -   int32            numSlavesCreated;  //used to give unique ID to processor
   8.155 -   int32            numTasksCreated;   //to give unique ID to a task
   8.156 -   int32            numSlavesAlive;
   8.157 -
   8.158 -   bool32          *coreIsDone;
   8.159 -   int32            numCoresDone;
   8.160 -   int32            shutdownInitiated;
   8.161 -   
   8.162 -   
   8.163 -      //=========== MEASUREMENT STUFF =============
   8.164 -       IntervalProbe   **intervalProbes;
   8.165 -       PrivDynArrayInfo *dynIntervalProbesInfo;
   8.166 -       HashTable        *probeNameHashTbl;
   8.167 -       int32             masterCreateProbeID;
   8.168 -       float64           createPtInSecs; //real-clock time PR initialized
   8.169 -       Histogram       **measHists;
   8.170 -       PrivDynArrayInfo *measHistsInfo;
   8.171 -       MEAS__Insert_Susp_Meas_Fields_into_MasterEnv;
   8.172 -       MEAS__Insert_Master_Meas_Fields_into_MasterEnv;
   8.173 -       MEAS__Insert_Master_Lock_Meas_Fields_into_MasterEnv;
   8.174 -       MEAS__Insert_Malloc_Meas_Fields_into_MasterEnv;
   8.175 -       MEAS__Insert_Plugin_Meas_Fields_into_MasterEnv;
   8.176 -       MEAS__Insert_System_Meas_Fields_into_MasterEnv;
   8.177 -       MEAS__Insert_Counter_Meas_Fields_into_MasterEnv;
   8.178 -      //==========================================
   8.179 - }
   8.180 -TopEnv;
   8.181 -
   8.182  
   8.183  //===================== These are prologs ====================
   8.184  //===A prolog is data immediately before pointer returned by a create function.
   8.185 @@ -413,19 +346,6 @@
   8.186   }
   8.187  PRExcp; //exception
   8.188  
   8.189 -//=======================  OS Thread related  ===============================
   8.190 -
   8.191 -void * coreController( void *paramsIn );  //standard PThreads fn prototype
   8.192 -void * coreCtlr_Seq( void *paramsIn );  //standard PThreads fn prototype
   8.193 -void animationMaster( void *initData, SlaveVP *masterVP );
   8.194 -
   8.195 -
   8.196 -typedef struct
   8.197 - {
   8.198 -   void           *endThdPt;
   8.199 -   unsigned int    coreNum;
   8.200 - }
   8.201 -ThdParams;
   8.202  
   8.203  #endif	/* _PR__structs_H */
   8.204  
     9.1 --- a/PR__int.h	Sun Jul 21 13:48:17 2013 -0700
     9.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.3 @@ -1,244 +0,0 @@
     9.4 -/*
     9.5 - *  Copyright 2009 OpenSourceResearchInstitute.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 _PR_INT_H
    9.13 -#define	_PR_INT_H
    9.14 -#define _GNU_SOURCE
    9.15 -
    9.16 -
    9.17 -/* MEANING OF   WL  PI  SS  int
    9.18 - * These indicate which places the function is safe to use.  They stand for:
    9.19 - * WL: Wrapper Library
    9.20 - * PI: Plugin 
    9.21 - * SS: Startup and Shutdown
    9.22 - * int: internal to the PR implementation
    9.23 - */
    9.24 -
    9.25 -inline
    9.26 -void
    9.27 -PR_int__reset_slaveVP_to_BirthFn( SlaveVP *slaveVP, BirthFnPtr fnPtr,
    9.28 -                              void    *dataParam);
    9.29 -
    9.30 -inline
    9.31 -void
    9.32 -PR_int__point_slaveVP_to_OneParamFn( SlaveVP *slaveVP, void *fnPtr,
    9.33 -                              void    *param);
    9.34 -
    9.35 -inline
    9.36 -void
    9.37 -PR_int__point_slaveVP_to_TwoParamFn( SlaveVP *slaveVP, void *fnPtr,
    9.38 -                             void    *param1, void *param2);
    9.39 -
    9.40 -//===========================================================================
    9.41 -//
    9.42 -//===========================================================================
    9.43 -inline
    9.44 -SlaveVP *
    9.45 -PR_int__create_slaveVP_helper( BirthFnPtr fnPtr, void *dataParam );
    9.46 -
    9.47 -inline
    9.48 -SlaveVP *
    9.49 -PR_int__create_slaveVP( BirthFnPtr fnPtr, void *dataParam, PRProcess *process );
    9.50 -
    9.51 -SlaveVP *
    9.52 -PR_int__get_recycled_slot_slave( );
    9.53 -
    9.54 -SlaveVP *
    9.55 -PR_int__create_slot_slave( );
    9.56 -
    9.57 -inline 
    9.58 -void
    9.59 -PR_int__replace_with_new_slot_slv( SlaveVP *slave );
    9.60 -
    9.61 -void 
    9.62 -idle_fn(void* data, SlaveVP *animatingSlv);
    9.63 -
    9.64 -inline
    9.65 -void
    9.66 -PR_int__put_task_into_slot( void *task, AnimSlot *slot );
    9.67 -
    9.68 -inline
    9.69 -void
    9.70 -PR_int__put_slave_into_slot( SlaveVP *slave, AnimSlot *slot );
    9.71 -
    9.72 -void inline
    9.73 -PRHandle__ServiceReq(  SlaveVP *requestingSlv );
    9.74 -
    9.75 -void
    9.76 -PR_int__free_slaveVP( SlaveVP *slave );
    9.77 -
    9.78 -void
    9.79 -PR_int__recycle_slaveVP( SlaveVP *slave );
    9.80 -
    9.81 -void
    9.82 -freeLangDataAsElem( void *elem );
    9.83 -
    9.84 -void
    9.85 -freeMetaTaskAsElem( void *elem );
    9.86 -
    9.87 -
    9.88 -//=============================
    9.89 -//=== Lange Env
    9.90 -//=
    9.91 -inline 
    9.92 -void *
    9.93 -PR_int__give_lang_env( PRLangEnv *protoLangEnv );
    9.94 -
    9.95 -inline 
    9.96 -PRLangEnv *
    9.97 -PR_int__give_proto_lang_env( void *langEnv );
    9.98 -
    9.99 -//inline
   9.100 -void *
   9.101 -PR_int__create_lang_env_in_process( int32 size, PRProcess *process, int32 magicNum );
   9.102 -
   9.103 -inline
   9.104 -void *
   9.105 -PR_int__remove_lang_env_from_process_and_free( void *langEnv );
   9.106 -
   9.107 -inline
   9.108 -void *
   9.109 -PR_int__give_lang_env_of_req( PRReqst *req, SlaveVP *requestingSlv );
   9.110 -
   9.111 -inline
   9.112 -void *
   9.113 -PR_int__give_lang_env_for_slave( SlaveVP *slave, int32 magicNum );
   9.114 -//No WL version -- not safe!  if use env in WL, be sure data rd & wr is stable
   9.115 -
   9.116 -inline
   9.117 -PRLangEnv *
   9.118 -PR_int__give_proto_lang_env_for_slave( SlaveVP *slave, int32 magicNumber );
   9.119 -//No WL version -- not safe!  if use env in WL, be sure data rd & wr is stable
   9.120 -
   9.121 -inline
   9.122 -void *
   9.123 -PR_int__give_lang_env_from_process( PRProcess *process, int32 magicNum );
   9.124 -//No WL version -- not safe!  if use env in WL, be sure data rd & wr is stable
   9.125 -
   9.126 -inline
   9.127 -PRLangEnv *
   9.128 -PR_int__give_proto_lang_env_from_process( PRProcess *process, int32 magicNum );
   9.129 -
   9.130 -//=======================
   9.131 -//=== Meta Task
   9.132 -//=
   9.133 -inline 
   9.134 -PRMetaTask *
   9.135 -PR_int__give_prolog_of_lang_meta_task( void *task );
   9.136 -
   9.137 -inline
   9.138 -void *
   9.139 -PR_int__give_lang_meta_task_of_prolog( PRMetaTask *metaTask);
   9.140 -
   9.141 -inline
   9.142 -void *
   9.143 -PR_int__create_lang_meta_task( int32 size, LangMetaTaskFreer freer, int32 magicNum );
   9.144 -
   9.145 -inline
   9.146 -void *
   9.147 -PR_int__create_lang_meta_task_in_slave( int32 size, LangMetaTaskFreer freer,
   9.148 -                                        SlaveVP *slave, int32 magicNum );
   9.149 -
   9.150 -inline
   9.151 -PRMetaTask *
   9.152 -PR_int__create_generic_slave_meta_task( void *initData );
   9.153 -
   9.154 -void
   9.155 -PR_int__free_lang_meta_task_and_remove_from_coll( void *langMetaTask );
   9.156 -
   9.157 -inline
   9.158 -void
   9.159 -PR_int__insert_meta_task_into_slave( PRMetaTask *task, SlaveVP *slave );
   9.160 -
   9.161 -inline
   9.162 -void
   9.163 -PR_int__insert_lang_meta_task_into_slave__ML( void *langMetaTask, SlaveVP *slave );
   9.164 -
   9.165 -inline
   9.166 -void *
   9.167 -PR_int__give_lang_meta_task_from_slave( SlaveVP *slave, int32 magicNumer );
   9.168 -
   9.169 -inline
   9.170 -SlaveVP *
   9.171 -PR_PI__give_slave_lang_meta_task_is_assigned_to( void *langMetaTask );
   9.172 -
   9.173 -//==============
   9.174 -//=== Lang Data
   9.175 -//=
   9.176 -inline
   9.177 -void *
   9.178 -PR_PI__create_lang_data_in_slave( int32 size, LangDataFreer freer,
   9.179 -                                   SlaveVP *slave, int32 magicNum );
   9.180 -
   9.181 -inline
   9.182 -void *
   9.183 -PR_int__give_lang_data_from_slave( SlaveVP *slave, int32 magicNumer );
   9.184 -#define PR_WL__give_lang_data  PR_int__give_lang_data_from_slave
   9.185 -
   9.186 -inline
   9.187 -void *
   9.188 -PR_int__give_lang_data_of_prolog( PRLangData *langData);
   9.189 -
   9.190 -//==================================================
   9.191 -//===  Collection
   9.192 -//=
   9.193 -PRCollElem ** //return an array of pointers
   9.194 -PR_int__make_collection_of_size( int32 numInColl );
   9.195 -
   9.196 -inline
   9.197 -void
   9.198 -PR_int__insert_elem_into_collection( PRCollElem *elem, PRCollElem **coll, int32 hash );
   9.199 -
   9.200 -inline
   9.201 -void *
   9.202 -PR_int__lookup_elem_in_collection( int32 hash, PRCollElem **coll );
   9.203 -
   9.204 -inline
   9.205 -void
   9.206 -PR_int__remove_elem_from_collection( int32 hash, PRCollElem **coll );
   9.207 -
   9.208 -inline
   9.209 -void
   9.210 -PR_int__set_collection_to_empty( PRCollElem **coll );
   9.211 -
   9.212 -inline
   9.213 -void
   9.214 -PR_int__apply_Fn_to_all_in_collection( void (*Fn)(void *), PRCollElem **coll );
   9.215 -
   9.216 -//===========
   9.217 -//===
   9.218 -//=
   9.219 -void
   9.220 -PR_int__error( char *msgStr );
   9.221 -
   9.222 -void
   9.223 -PR_int__throw_exception( char *msgStr, SlaveVP *reqstSlv, PRExcp *excpData );
   9.224 -
   9.225 -char *
   9.226 -PR_int__strDup( char *str );
   9.227 -
   9.228 -inline void
   9.229 -PR_int__get_wrapper_lock();
   9.230 -
   9.231 -inline void
   9.232 -PR_int__get_malloc_lock();
   9.233 -
   9.234 -#define PR_int__release_master_lock()  _PRTopEnv->masterLock  = UNLOCKED
   9.235 -
   9.236 -#define PR_int__release_wrapper_lock() _PRTopEnv->wrapperLock = UNLOCKED
   9.237 -
   9.238 -#define PR_int__release_malloc_lock()  _PRTopEnv->mallocLock  = UNLOCKED
   9.239 -
   9.240 -inline uint32_t
   9.241 -PR_int__randomNumber();
   9.242 -
   9.243 -inline void
   9.244 -PR_int__backoff_for_TooLongToGetLock( int32 numTriesToGetLock );
   9.245 -
   9.246 -#endif	/* _PR_INT_H */
   9.247 -
    10.1 --- a/PR__structs.h	Sun Jul 21 13:48:17 2013 -0700
    10.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.3 @@ -1,432 +0,0 @@
    10.4 -/*
    10.5 - *  Copyright 2009 OpenSourceResearchInstitute.org
    10.6 - *  Licensed under GNU General Public License version 2
    10.7 - *
    10.8 - * Author: seanhalle@yahoo.com
    10.9 - * 
   10.10 - */
   10.11 -
   10.12 -#ifndef _PR__structs_H
   10.13 -#define	_PR__structs_H
   10.14 -#define _GNU_SOURCE
   10.15 -
   10.16 -#include "PR_primitive_data_types.h"
   10.17 -
   10.18 -#include <pthread.h>
   10.19 -#include <sys/time.h>
   10.20 -
   10.21 -
   10.22 -//================================ Typedefs =================================
   10.23 -//===
   10.24 -//=
   10.25 -#define ZERO 0
   10.26 -
   10.27 -typedef unsigned long long    TSCount;
   10.28 -
   10.29 -typedef struct _AnimSlot      AnimSlot;
   10.30 -typedef struct _PRReqst       PRReqst;
   10.31 -typedef struct _SlaveVP       SlaveVP;
   10.32 -typedef struct _MasterVP      MasterVP;
   10.33 -typedef struct _IntervalProbe IntervalProbe;
   10.34 -typedef struct _PRLangEnv     PRLangEnv;  //a prolog
   10.35 -typedef struct _PRMetaTask    PRMetaTask; //a prolog
   10.36 -typedef struct _PRLangData    PRLangData; //a prolog
   10.37 -typedef struct _PRCollElem    PRCollElem; //generic form of the prologs
   10.38 -
   10.39 -typedef bool32   (*SlaveAssigner)  ( void *, AnimSlot* ); //langEnv, slot for HW info
   10.40 -typedef void     (*RequestHandler) ( void *, SlaveVP *, void * ); //req, slv, langEnv
   10.41 -typedef void    *(*CreateHandler)  ( void *, SlaveVP *, void * ); //req, slv, langEnv
   10.42 -typedef void     (*LangShutdownHdlr) ( void * ); //langEnv
   10.43 -typedef void    *(*LangDataCreator)  ( SlaveVP * ); 
   10.44 -typedef void     (*LangDataFreer)    ( void * ); //lang data to free
   10.45 -typedef void    *(*LangMetaTaskCreator)( SlaveVP * );  //when slave has no meta task for magic num 
   10.46 -typedef void     (*LangMetaTaskFreer)  ( void * ); //lang meta task to free
   10.47 -typedef void     (*MakeSlaveReadyFn)   ( SlaveVP *, void * ); //slave and langEnv
   10.48 -typedef void     (*MakeTaskReadyFn)    ( void *, void * ); //langTask and langEnv
   10.49 -typedef void     (*BirthFnPtr)  ( void *, SlaveVP * ); //initData, animSlv
   10.50 -typedef void       BirthFn      ( void *, SlaveVP * ); //initData, animSlv
   10.51 -typedef void     (*ResumeSlvFnPtr) ( SlaveVP *, void * );
   10.52 -      //=========== MEASUREMENT STUFF ==========
   10.53 -        MEAS__Insert_Counter_Handler
   10.54 -      //========================================
   10.55 -
   10.56 -//============================ HW Dependent Fns ================================
   10.57 -
   10.58 -#include "HW_Dependent_Primitives/PR__HW_measurement.h"
   10.59 -#include "HW_Dependent_Primitives/PR__primitives.h"
   10.60 -
   10.61 -
   10.62 -typedef struct
   10.63 - { //These are set by the plugin during startup and the application
   10.64 -   char *assignerInfo;
   10.65 -   char *appInfo;
   10.66 -   char *inputInfo;
   10.67 - }
   10.68 -PRSysMetaInfo;
   10.69 -
   10.70 -//=====================  Process Data Struct  ======================
   10.71 -
   10.72 -/*This structure holds all the information PR needs to manage a program.  PR
   10.73 - * stores information about what percent of CPU time the program is getting, 
   10.74 - * 
   10.75 - */
   10.76 -typedef struct
   10.77 - { 
   10.78 -   int32     numEnvsWithWork;
   10.79 -   void     *resultToReturn;
   10.80 -    
   10.81 -   PRLangEnv **langEnvs;     //used as a hash table
   10.82 -   PRLangEnv **protoLangEnvsList; //for fast linear scan of envs
   10.83 -   int32      numLangEnvs;   //for fast linear scan of envs
   10.84 -    
   10.85 -   SlaveVP        *seedSlv;
   10.86 -   
   10.87 -   int32           numLiveGenericSlvs;
   10.88 -   int32           numLiveTasks;
   10.89 -
   10.90 -   SlaveAssigner   overrideAssigner;
   10.91 -  
   10.92 -   
   10.93 -   
   10.94 -      //These are used to coord with an OS thread waiting for process to end
   10.95 -   bool32          hasWaitingToEnd;
   10.96 -   bool32          executionIsComplete;
   10.97 -   pthread_mutex_t doneLock;
   10.98 -   pthread_cond_t  doneCond;   
   10.99 -   pthread_mutex_t doneAckLock; //waiter gets, then releases when done waiting
  10.100 -
  10.101 -      //=========== MEASUREMENT STUFF =============
  10.102 -       IntervalProbe   **intervalProbes;
  10.103 -       PrivDynArrayInfo *dynIntervalProbesInfo;
  10.104 -       HashTable        *probeNameHashTbl;
  10.105 -       int32             masterCreateProbeID;
  10.106 -       float64           createPtInSecs; //real-clock time PR initialized
  10.107 -       Histogram       **measHists;
  10.108 -       PrivDynArrayInfo *measHistsInfo;
  10.109 -       MEAS__Insert_Susp_Meas_Fields_into_MasterEnv;
  10.110 -       MEAS__Insert_Master_Meas_Fields_into_MasterEnv;
  10.111 -       MEAS__Insert_Master_Lock_Meas_Fields_into_MasterEnv;
  10.112 -       MEAS__Insert_Malloc_Meas_Fields_into_MasterEnv;
  10.113 -       MEAS__Insert_Plugin_Meas_Fields_into_MasterEnv;
  10.114 -       MEAS__Insert_System_Meas_Fields_into_MasterEnv;
  10.115 -       MEAS__Insert_Counter_Meas_Fields_into_MasterEnv;
  10.116 -      //==========================================
  10.117 - }
  10.118 -PRProcess;
  10.119 -
  10.120 -
  10.121 -//============= Request Related ===========
  10.122 -//
  10.123 -
  10.124 -enum PRReqstType  //avoid starting enums at 0, for debug reasons
  10.125 - {
  10.126 -   TaskCreate = 1,
  10.127 -   TaskEnd,
  10.128 -   SlvCreate,
  10.129 -   SlvDissipate,
  10.130 -   Language,
  10.131 -   Service,       //To invoke a PR provided equivalent of a language request (ex: probe)
  10.132 -   Hardware,
  10.133 -   IO,
  10.134 -   OSCall, 
  10.135 -   LangShutdown,
  10.136 -   ProcessEnd,
  10.137 -   PRShutdown
  10.138 - };
  10.139 -
  10.140 -
  10.141 -struct _PRReqst
  10.142 - {
  10.143 -   enum PRReqstType   reqType;//used for special forms that have PR behavior
  10.144 -   void              *langReq;
  10.145 -   PRProcess         *processReqIsIn;
  10.146 -   int32              langMagicNumber;
  10.147 -   SlaveVP           *requestingSlave;
  10.148 -   
  10.149 -   BirthFnPtr      topLevelFn;
  10.150 -   void              *initData;
  10.151 -   int32             *ID;
  10.152 -   
  10.153 -      //The request handling structure is a bit messy..  for special forms, 
  10.154 -      // such as create and dissipate, the language inserts pointer to handler
  10.155 -      // fn directly into the request..  might change to this for all requests
  10.156 -   RequestHandler    handler; //pointer to handler fn 
  10.157 -   CreateHandler     createHdlr; //special because returns something
  10.158 -   int32             createSuspendedGroup; //must be non-zero
  10.159 -   
  10.160 -   PRReqst *nextReqst;
  10.161 - };
  10.162 -//PRReqst
  10.163 -
  10.164 -enum PRServiceReqType   //These are equivalent to lang requests, but for
  10.165 - {                    // PR's services available directly to app, like OS
  10.166 -   make_probe = 1,    // and probe services -- like a PR-wide built-in lang
  10.167 -   throw_excp,
  10.168 -   openFile,
  10.169 -   otherIO
  10.170 - };
  10.171 -
  10.172 -typedef struct
  10.173 - { enum PRServiceReqType   reqType;
  10.174 -   SlaveVP             *requestingSlv;
  10.175 -   char                *nameStr;  //for create probe
  10.176 -   char                *msgStr;   //for exception
  10.177 -   void                *exceptionData;
  10.178 - }
  10.179 -PRServiceReq;
  10.180 -
  10.181 -
  10.182 -//====================  Core data structures  ===================
  10.183 -
  10.184 -typedef struct
  10.185 - {
  10.186 -   //for future expansion
  10.187 - }
  10.188 -SlotPerfInfo;
  10.189 -
  10.190 -struct _AnimSlot
  10.191 - {
  10.192 -   int32         workIsDone;
  10.193 -   int32         needsWorkAssigned;
  10.194 -   SlaveVP      *slaveAssignedToSlot;
  10.195 -   
  10.196 -   int32         slotIdx;  //needed by Holistic Model's data gathering
  10.197 -   int32         coreSlotIsOn;
  10.198 -   SlotPerfInfo *perfInfo; //used by assigner to pick best slave for core
  10.199 - };
  10.200 -//AnimSlot
  10.201 -
  10.202 -enum VPtype 
  10.203 - { SlotTaskSlv = 1,//Slave tied to an anim slot, only animates tasks
  10.204 -   FreeTaskSlv,   //When a suspended task ends, the slave becomes this
  10.205 -   GenericSlv,     //the VP is explicitly seen in the app code, or task suspends
  10.206 -   SeedSlv,
  10.207 -   Master_VP,
  10.208 -   ShutdownVP,
  10.209 -   IdleVP
  10.210 - };
  10.211 - 
  10.212 -/*This structure embodies the state of a slaveVP.  It is reused for masterVP
  10.213 - * and shutdownVPs.
  10.214 - */
  10.215 -struct _SlaveVP
  10.216 - {    //The offsets of these fields are hard-coded into assembly
  10.217 -   void       *stackPtr;         //save the core's stack ptr when suspend
  10.218 -   void       *framePtr;         //save core's frame ptr when suspend
  10.219 -   void       *resumeInstrPtr;   //save core's program-counter when suspend
  10.220 -   void       *coreCtlrFramePtr; //restore before jmp back to core controller
  10.221 -   void       *coreCtlrStackPtr; //restore before jmp back to core controller
  10.222 -   
  10.223 -      //============ below this, no fields are used in asm =============
  10.224 -   
  10.225 -   void       *startOfStack;  //used to free, and to point slave to Fn
  10.226 -   PRProcess  *processSlaveIsIn;
  10.227 -   enum VPtype typeOfVP;      //Slave vs Master vs Shutdown..
  10.228 -   int32       slaveNum;      //each slave given it's seq in creation
  10.229 -   int32      *ID;       //App defines meaning of each int in array
  10.230 -   int32       coreAnimatedBy; 
  10.231 -   int32       numTimesAssignedToASlot;   //Each assign is for one work-unit, so is an ID
  10.232 -      //note, a scheduling decision is uniquely identified by the triple:
  10.233 -      // <slaveNum, coreAnimatedBy, numTimesAssignedToASlot> -- used in record & replay
  10.234 -   
  10.235 -      //for comm -- between master and coreCtlr & btwn wrapper lib and plugin
  10.236 -   AnimSlot   *animSlotAssignedTo;
  10.237 -   PRReqst    *request;      //wrapper lib puts in requests, plugin takes out
  10.238 -   void       *dataRetFromReq;//Return vals from plugin to Wrapper Lib
  10.239 -
  10.240 -      //For language specific data that needs to be in the slave
  10.241 -      //These are accessed  directly for single-lang, but multi-lang places
  10.242 -      // a holder here instead, then uses magic num to get lang's version
  10.243 -   PRLangData  **langDatas;  //Lang saves lang-specific things in slave here
  10.244 -   PRMetaTask  **metaTasks;
  10.245 -
  10.246 -        //=========== MEASUREMENT STUFF ==========
  10.247 -         MEAS__Insert_Meas_Fields_into_Slave;
  10.248 -         float64     createPtInSecs;  //time VP created, in seconds
  10.249 -        //========================================
  10.250 -         
  10.251 -//   int8       cacheLinePad[512 - sizeof(contents)]; //for false sharing
  10.252 - };
  10.253 -//SlaveVP
  10.254 -
  10.255 - 
  10.256 -enum PRMode
  10.257 - { SingleLang = 1,
  10.258 -   StandaloneWTasks,
  10.259 -   MultiLang      
  10.260 - };
  10.261 - 
  10.262 -/* The one and only global variable, holds many odds and ends
  10.263 - */
  10.264 -typedef struct
  10.265 - {    //The offsets of these fields are hard-coded into assembly
  10.266 -   void            *coreCtlrReturnPt;    //offset to this field used in asm
  10.267 -   int8             falseSharePad1[256 - sizeof(void*)];
  10.268 -   int32            masterLock;          //offset to this field used in asm
  10.269 -   int8             falseSharePad2[256 - sizeof(int32)];
  10.270 -   int32            wrapperLock;         //offset to this field used in asm
  10.271 -   int8             falseSharePad3[256 - sizeof(int32)];
  10.272 -   int32            mallocLock;          //offset to this field used in asm
  10.273 -   int8             falseSharePad4[256 - sizeof(int32)];
  10.274 -      //============ below this, no fields are used in asm =============
  10.275 -
  10.276 -      //Basic PR infrastructure
  10.277 -//   enum PRMode      mode;
  10.278 -   SlaveVP        **masterVPs;
  10.279 -   AnimSlot      ***allAnimSlots;
  10.280 -   PrivQueueStruc  *slaveRecycleQ;
  10.281 -   SlaveVP         *slotTaskSlvs[NUM_CORES][NUM_ANIM_SLOTS];
  10.282 -   SlaveVP         *idleSlv[NUM_CORES][NUM_ANIM_SLOTS];
  10.283 -   
  10.284 -      //Memory management related
  10.285 -   MallocArrays    *freeLists;
  10.286 -   int32            amtOfOutstandingMem;//total currently allocated
  10.287 -
  10.288 -      //Random number seeds -- random nums used in various places  
  10.289 -   uint32_t         seed1;
  10.290 -   uint32_t         seed2;
  10.291 -
  10.292 -   PRSysMetaInfo   *metaInfo; //info about this PR system -- vers, build, etc
  10.293 -   
  10.294 -   //============== This only used by multi-lang mode ============
  10.295 -   PRProcess      **processes;
  10.296 -   int32            numProcesses;
  10.297 -   int32            currProcessIdx;    //used to choose which process gets slot
  10.298 -   int32            firstProcessReady; //use while starting up coreCtlr
  10.299 -   
  10.300 -      //initialize flags for waiting for activity within PR to complete
  10.301 -   bool32           allActivityIsDone;
  10.302 -   pthread_mutex_t  activityDoneLock;
  10.303 -   pthread_cond_t   activityDoneCond;   
  10.304 -
  10.305 -   SlaveAssigner    overrideAssigner;
  10.306 -   
  10.307 -   //============== Below this is only used by single-lang mode ==============
  10.308 -   void            *protoLangEnv;
  10.309 -      //Slave creation -- global count of slaves existing, across langs and processes
  10.310 -   int32            numSlavesCreated;  //used to give unique ID to processor
  10.311 -   int32            numTasksCreated;   //to give unique ID to a task
  10.312 -   int32            numSlavesAlive;
  10.313 -
  10.314 -   bool32          *coreIsDone;
  10.315 -   int32            numCoresDone;
  10.316 -   int32            shutdownInitiated;
  10.317 -   
  10.318 -   
  10.319 -      //=========== MEASUREMENT STUFF =============
  10.320 -       IntervalProbe   **intervalProbes;
  10.321 -       PrivDynArrayInfo *dynIntervalProbesInfo;
  10.322 -       HashTable        *probeNameHashTbl;
  10.323 -       int32             masterCreateProbeID;
  10.324 -       float64           createPtInSecs; //real-clock time PR initialized
  10.325 -       Histogram       **measHists;
  10.326 -       PrivDynArrayInfo *measHistsInfo;
  10.327 -       MEAS__Insert_Susp_Meas_Fields_into_MasterEnv;
  10.328 -       MEAS__Insert_Master_Meas_Fields_into_MasterEnv;
  10.329 -       MEAS__Insert_Master_Lock_Meas_Fields_into_MasterEnv;
  10.330 -       MEAS__Insert_Malloc_Meas_Fields_into_MasterEnv;
  10.331 -       MEAS__Insert_Plugin_Meas_Fields_into_MasterEnv;
  10.332 -       MEAS__Insert_System_Meas_Fields_into_MasterEnv;
  10.333 -       MEAS__Insert_Counter_Meas_Fields_into_MasterEnv;
  10.334 -      //==========================================
  10.335 - }
  10.336 -TopEnv;
  10.337 -
  10.338 -
  10.339 -//===================== These are prologs ====================
  10.340 -//===A prolog is data immediately before pointer returned by a create function.
  10.341 -//=
  10.342 -struct _PRLangEnv
  10.343 - { //============== First two must match PRCollElem ==============
  10.344 -   int32     langMagicNumber; //indexes into hash array of langEnvs in PRProcess
  10.345 -   PRLangEnv *chainedLangEnv;   //chains to langEnvs with same hash
  10.346 -   //=============================================================
  10.347 -   
  10.348 -   SlaveAssigner    workAssigner;
  10.349 -   LangShutdownHdlr shutdownHdlr; //called when lang ended or process shutdown
  10.350 -   LangDataCreator  langDataCreator;
  10.351 -   LangMetaTaskCreator langMetaTaskCreator;
  10.352 -   MakeSlaveReadyFn makeSlaveReadyFn;
  10.353 -   MakeTaskReadyFn  makeTaskReadyFn;
  10.354 -     
  10.355 -      //when multi-lang, master polls lang env's to find one with work in it..
  10.356 -      // in single-lang case, flag ignored, master always asks lang for work
  10.357 -   int32           hasWork;
  10.358 -   PRProcess      *processEnvIsIn;
  10.359 -   
  10.360 -   int32           idxInProcess; //index into array of langEnvs in the process
  10.361 -   
  10.362 -   int32           numReadyWork;
  10.363 -   
  10.364 -   int32           numLiveWork;
  10.365 -   PrivQueueStruc *waitingForWorkToEndQ;
  10.366 - };
  10.367 -//PRLangEnv -- this is the prolog of every lang's lang env
  10.368 -
  10.369 -enum PRTaskType
  10.370 - { GenericSlave = 1,
  10.371 -   SlotTask,
  10.372 -   FreeTask
  10.373 - };
  10.374 -
  10.375 -struct _PRMetaTask
  10.376 - { //============== First two must match PRCollElem ==============
  10.377 -   int32           langMagicNumber;
  10.378 -   PRMetaTask     *chainedMetaTask;
  10.379 -   //=============================================================
  10.380 -   enum PRTaskType taskType;
  10.381 -   int32          *ID;              //is standard PR ID
  10.382 -   PRProcess      *processTaskIsIn;
  10.383 -   SlaveVP        *slaveAssignedTo; //not valid until task animated
  10.384 -   BirthFnPtr   topLevelFn;      //This is the Fn executes as the task
  10.385 -   void           *initData;        //The data taken by the function
  10.386 -   LangMetaTaskFreer freer;
  10.387 -   bool32          goAheadAndFree;
  10.388 -
  10.389 -   //NOTE: info needed for "wait" functionality is inside lang's metaTask
  10.390 - };
  10.391 -//PRMetaTask -- prolog of every lang's meta task
  10.392 -
  10.393 -struct _PRLangData
  10.394 - { //============== First two must match PRCollElem ==============
  10.395 -   int32         langMagicNumber;
  10.396 -   PRLangData   *chainedLangData;
  10.397 -   //=============================================================
  10.398 -   LangDataFreer  freer;
  10.399 -   bool32         goAheadAndFree;
  10.400 -   SlaveVP       *slaveAssignedTo;
  10.401 - };
  10.402 -//PRLangData -- this is the prolog of each lang's lang data
  10.403 -
  10.404 -struct _PRCollElem
  10.405 - {
  10.406 -   int32       hash;
  10.407 -   PRCollElem *chained;
  10.408 - };
  10.409 -//PRCollElem -- this is generic form of all the prologs
  10.410 -
  10.411 -
  10.412 -
  10.413 -//=========================  Extra Stuff Data Strucs  =======================
  10.414 -typedef struct
  10.415 - {
  10.416 -
  10.417 - }
  10.418 -PRExcp; //exception
  10.419 -
  10.420 -//=======================  OS Thread related  ===============================
  10.421 -
  10.422 -void * coreController( void *paramsIn );  //standard PThreads fn prototype
  10.423 -void * coreCtlr_Seq( void *paramsIn );  //standard PThreads fn prototype
  10.424 -void animationMaster( void *initData, SlaveVP *masterVP );
  10.425 -
  10.426 -
  10.427 -typedef struct
  10.428 - {
  10.429 -   void           *endThdPt;
  10.430 -   unsigned int    coreNum;
  10.431 - }
  10.432 -ThdParams;
  10.433 -
  10.434 -#endif	/* _PR__structs_H */
  10.435 -
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/Services_offered_by_PR/Measurement_and_Stats/MEAS__Counter_Recording.c	Fri Jul 26 12:12:34 2013 -0700
    11.3 @@ -0,0 +1,156 @@
    11.4 +/*
    11.5 + * 
    11.6 + * author: Nina Engelhardt
    11.7 + */
    11.8 +
    11.9 +#include "MEAS__Counter_Recording.h"
   11.10 +//#include "PR__common_includes/PR__common_structs.h"
   11.11 +//#include "PRServ__wrapper_library/PRServ__wrapper_library.h"
   11.12 +
   11.13 +#ifdef HOLISTIC__TURN_ON_PERF_COUNTERS
   11.14 +
   11.15 +void 
   11.16 +MEAS__init_counter_data_structs_for_Lang( SlaveVP *slave, int32 magicNum )
   11.17 + {
   11.18 +   PRServLangEnv *langEnv = 
   11.19 +                (PRServLangEnv *)PR_SS__give_lang_env_for_slave( slave, magicNum );
   11.20 +   int i;
   11.21 +   for(i=0;i<NUM_CORES;i++)
   11.22 +    { langEnv->counterList[i] = makeListOfArrays(sizeof(CounterEvent), 128);
   11.23 +    }
   11.24 + }
   11.25 +
   11.26 +/*Pass file by side effect..
   11.27 + *The reason is that using doAllInListOfArrays, to which one passes the pointer
   11.28 + * to a function, which is then applied to all the elements..  but, that fn
   11.29 + * can only take one input -- the element from the list of arrays..  so, it
   11.30 + * can't also be passed the file..  hence pass the file by side effect
   11.31 + * 
   11.32 + *However, multiple cores could be trying to do this..  so, create a separate
   11.33 + * lock just for counters, and acquire that when set the file, then release
   11.34 + * once all the printing is done.
   11.35 + */
   11.36 +void 
   11.37 +MEAS__set_counter_file(FILE* f)
   11.38 + {
   11.39 +   acquire counter lock
   11.40 +   counterfile = f;
   11.41 + }
   11.42 +
   11.43 +MEAS__release_counter_file()
   11.44 + {
   11.45 +   release counter lock
   11.46 + }
   11.47 +
   11.48 +void 
   11.49 +MEAS__addToListOfArraysCounterEvent(CounterEvent value, ListOfArrays* list)
   11.50 + {
   11.51 +   int offset_in_fragment = list->next_free_index % list->num_entries_per_fragment; 
   11.52 +   if(offset_in_fragment == 0)
   11.53 +    { void* newBlock = malloc(list->entry_size * list->num_entries_per_fragment); 
   11.54 +     addToDynArray(newBlock,list->dim1info); 
   11.55 +    } 
   11.56 +   CounterEvent* typedFragment = (CounterEvent*) ((list->dim1)[list->dim1info->numInArray -1]); 
   11.57 +   typedFragment[offset_in_fragment] = value; 
   11.58 +   list->next_free_index++; 
   11.59 + }
   11.60 +
   11.61 +void 
   11.62 +MEAS__counter_handler(int evt_type, int vpid, int task, SlaveVP* pr, uint64 cycles, uint64 instrs)
   11.63 + {
   11.64 +   if (pr->typeOfVP == Master_VP || pr->typeOfVP == ShutdownVP)
   11.65 +    { //Only save values for application work, done in a SlaveVP
   11.66 +      return;
   11.67 +    }
   11.68 +
   11.69 +   //Note: have made many changes without compiler flag turned on, nor test..
   11.70 +   PRLangEnv *langEnv = 
   11.71 +      PR_int__give_proto_lang_env_from_slave( pr, magicNum);
   11.72 +
   11.73 +   CounterEvent e;
   11.74 +   e.event_type = evt_type;
   11.75 +   e.vp = vpid;
   11.76 +   e.task = task;
   11.77 +
   11.78 +   e.cycles = cycles;
   11.79 +   e.instrs = instrs;
   11.80 +
   11.81 +   if(pr)
   11.82 +    { e.coreID = pr->coreAnimatedBy;
   11.83 +      e.slot = pr->animSlotAssignedTo;
   11.84 +    } 
   11.85 +   else 
   11.86 +    { e.coreID = -1;
   11.87 +      e.slot = NULL;
   11.88 +    }
   11.89 +
   11.90 +   int corenum;
   11.91 +
   11.92 +   if(pr) 
   11.93 +      corenum = pr->coreAnimatedBy; 
   11.94 +   else 
   11.95 +      return; 
   11.96 +
   11.97 +   if(evt_type==Work_start || evt_type==Work_end || evt_type==AppResponderInvocation_start)
   11.98 +    { addToListOfArrays_ext(CounterEvent,e,langEnv->counterList[corenum]);
   11.99 +    } 
  11.100 +   else 
  11.101 +    { MEAS__addToListOfArraysCounterEvent(e,langEnv->counterList[corenum]);
  11.102 +    }
  11.103 + }
  11.104 +
  11.105 +
  11.106 +
  11.107 +void 
  11.108 +MEAS__print_counter_event_to_file( void* _e )
  11.109 + {
  11.110 +   CounterEvent* e = (CounterEvent*) _e;
  11.111 +   fprintf(counterfile, "event, ");
  11.112 +   switch(e->event_type)
  11.113 +    {
  11.114 +      case AppResponderInvocation_start:
  11.115 +          fprintf(counterfile, "AppResponderInvocation_start");
  11.116 +          break;
  11.117 +      case AppResponder_start:
  11.118 +          fprintf(counterfile, "AppResponder_start");
  11.119 +          break;
  11.120 +      case AppResponder_end:
  11.121 +          fprintf(counterfile, "AppResponder_end");
  11.122 +          break;
  11.123 +      case AssignerInvocation_start:
  11.124 +          fprintf(counterfile, "AssignerInvocation_start");
  11.125 +          break;
  11.126 +      case NextAssigner_start:
  11.127 +          fprintf(counterfile, "NextAssigner_start");
  11.128 +          break;
  11.129 +      case Assigner_start:
  11.130 +          fprintf(counterfile, "Assigner_start");
  11.131 +          break;
  11.132 +      case Assigner_end:
  11.133 +          fprintf(counterfile, "Assigner_end");
  11.134 +          break;
  11.135 +      case Work_end:
  11.136 +          fprintf(counterfile, "Work_end");
  11.137 +          break;
  11.138 +      case Work_start:
  11.139 +          fprintf(counterfile, "Work_start");
  11.140 +          break;
  11.141 +      case HwResponderInvocation_start:
  11.142 +          fprintf(counterfile, "HwResponderInvocation_start");
  11.143 +          break;
  11.144 +      case Timestamp_start:
  11.145 +          fprintf(counterfile, "Timestamp_start");
  11.146 +          break;
  11.147 +      case Timestamp_end:
  11.148 +          fprintf(counterfile, "Timestamp_end");
  11.149 +          break;
  11.150 +      default:
  11.151 +          fprintf(counterfile, "unknown event");
  11.152 +    }
  11.153 +   fprintf(counterfile,", %d, %d, %llu, %llu",e->vp,e->task,e->cycles,e->instrs);
  11.154 +   if(e->coreID >=0)
  11.155 +   fprintf(counterfile,", %d",e->coreID);
  11.156 +   fprintf(counterfile,"\n");
  11.157 +   fflush(counterfile);
  11.158 + }
  11.159 +#endif
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/Services_offered_by_PR/Measurement_and_Stats/MEAS__Counter_Recording.h	Fri Jul 26 12:12:34 2013 -0700
    12.3 @@ -0,0 +1,36 @@
    12.4 +/* 
    12.5 + * File:   MEAS__Counter_Recording.h
    12.6 + * Author: nengel
    12.7 + *
    12.8 + * Created on January 11, 2012, 3:03 PM
    12.9 + */
   12.10 +
   12.11 +#ifndef MEAS__COUNTER_RECORDING_H
   12.12 +#define	MEAS__COUNTER_RECORDING_H
   12.13 +
   12.14 +#include "PR__common_includes/PR__common_structs.h"
   12.15 +
   12.16 +typedef struct 
   12.17 + {
   12.18 +   int event_type;
   12.19 +   int coreID;
   12.20 +   AnimSlot* slot;
   12.21 +   int vp;
   12.22 +   int task;
   12.23 +   uint64 cycles;
   12.24 +   uint64 instrs;
   12.25 + } 
   12.26 +CounterEvent;
   12.27 +
   12.28 +FILE* counterfile; //pass file handle via side effect because
   12.29 +                   // doAllInListOfArrays only takes Fns with a single input
   12.30 +
   12.31 +void MEAS__init_counter_data_structs_for_lang( SlaveVP *slv, int32 magicNum );
   12.32 +
   12.33 +void MEAS__counter_handler(int evt_type, int vpid, int task, SlaveVP* pr, uint64 cycles, uint64 instrs);
   12.34 +
   12.35 +void MEAS__set_counter_file(FILE* f);
   12.36 +
   12.37 +void MEAS__print_counter_event_to_file( void* _e );
   12.38 +#endif	/* PRServ_COUNTER_RECORDING_H */
   12.39 +
    13.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.2 +++ b/Services_offered_by_PR/Measurement_and_Stats/MEAS__macros.h	Fri Jul 26 12:12:34 2013 -0700
    13.3 @@ -0,0 +1,514 @@
    13.4 +/*
    13.5 + *  Copyright 2009 OpenSourceResearchInstitute.org
    13.6 + *  Licensed under GNU General Public License version 2
    13.7 + *
    13.8 + * Author: seanhalle@yahoo.com
    13.9 + * 
   13.10 + */
   13.11 +
   13.12 +#ifndef _MEAS_MACROS_H
   13.13 +#define _MEAS_MACROS_H
   13.14 +#define _GNU_SOURCE
   13.15 +
   13.16 +//==================  Macros define types of meas want  =====================
   13.17 +//
   13.18 +/*Generic measurement macro -- has name-space collision potential, which
   13.19 + * compiler will catch..  so only use one pair inside a given set of 
   13.20 + * curly braces. 
   13.21 + */
   13.22 +//TODO: finish generic capture interval in hist
   13.23 +enum histograms
   13.24 + { generic1
   13.25 + };
   13.26 +   #define MEAS__Capture_Pre_Point \
   13.27 +      int32 startStamp, endStamp; \
   13.28 +      saveLowTimeStampCountInto( startStamp );
   13.29 +
   13.30 +   #define MEAS__Capture_Post_Point( histName ) \
   13.31 +      saveLowTimeStampCountInto( endStamp ); \
   13.32 +      addIntervalToHist( startStamp, endStamp, _PRTopEnv->histName ); 
   13.33 +
   13.34 +
   13.35 +
   13.36 +
   13.37 +//==================  Macros define types of meas want  =====================
   13.38 +
   13.39 +#ifdef MEAS__TURN_ON_SUSP_MEAS
   13.40 +   #define MEAS__Insert_Susp_Meas_Fields_into_Slave \
   13.41 +       uint32  preSuspTSCLow; \
   13.42 +       uint32  postSuspTSCLow;
   13.43 +
   13.44 +   #define MEAS__Insert_Susp_Meas_Fields_into_MasterEnv \
   13.45 +       Histogram       *suspLowTimeHist; \
   13.46 +       Histogram       *suspHighTimeHist;
   13.47 +
   13.48 +   #define MEAS__Make_Meas_Hists_for_Susp_Meas \
   13.49 +      _PRTopEnv->suspLowTimeHist  = makeFixedBinHistExt( 100, 0, 200,\
   13.50 +                                                    "master_low_time_hist");\
   13.51 +      _PRTopEnv->suspHighTimeHist  = makeFixedBinHistExt( 100, 0, 200,\
   13.52 +                                                    "master_high_time_hist");
   13.53 +      
   13.54 +      //record time stamp: compare to time-stamp recorded below
   13.55 +   #define MEAS__Capture_Pre_Susp_Point \
   13.56 +      saveLowTimeStampCountInto( animatingSlv->preSuspTSCLow );
   13.57 +   
   13.58 +      //NOTE: only take low part of count -- do sanity check when take diff
   13.59 +   #define MEAS__Capture_Post_Susp_Point \
   13.60 +      saveLowTimeStampCountInto( animatingSlv->postSuspTSCLow );\
   13.61 +      addIntervalToHist( preSuspTSCLow, postSuspTSCLow,\
   13.62 +                         _PRTopEnv->suspLowTimeHist ); \
   13.63 +      addIntervalToHist( preSuspTSCLow, postSuspTSCLow,\
   13.64 +                         _PRTopEnv->suspHighTimeHist );
   13.65 +
   13.66 +   #define MEAS__Print_Hists_for_Susp_Meas \
   13.67 +      printHist( _PRTopEnv->pluginTimeHist );
   13.68 +      
   13.69 +#else
   13.70 +   #define MEAS__Insert_Susp_Meas_Fields_into_Slave     
   13.71 +   #define MEAS__Insert_Susp_Meas_Fields_into_MasterEnv 
   13.72 +   #define MEAS__Make_Meas_Hists_for_Susp_Meas 
   13.73 +   #define MEAS__Capture_Pre_Susp_Point
   13.74 +   #define MEAS__Capture_Post_Susp_Point   
   13.75 +   #define MEAS__Print_Hists_for_Susp_Meas 
   13.76 +#endif
   13.77 +
   13.78 +#ifdef MEAS__TURN_ON_MASTER_MEAS
   13.79 +   #define MEAS__Insert_Master_Meas_Fields_into_Slave \
   13.80 +       uint32  startMasterTSCLow; \
   13.81 +       uint32  endMasterTSCLow;
   13.82 +
   13.83 +   #define MEAS__Insert_Master_Meas_Fields_into_MasterEnv \
   13.84 +       Histogram       *masterLowTimeHist; \
   13.85 +       Histogram       *masterHighTimeHist;
   13.86 +
   13.87 +   #define MEAS__Make_Meas_Hists_for_Master_Meas \
   13.88 +      _PRTopEnv->masterLowTimeHist  = makeFixedBinHistExt( 100, 0, 200,\
   13.89 +                                                    "master_low_time_hist");\
   13.90 +      _PRTopEnv->masterHighTimeHist  = makeFixedBinHistExt( 100, 0, 200,\
   13.91 +                                                    "master_high_time_hist");
   13.92 +
   13.93 +      //Total Master time includes one coreloop time -- just assume the core
   13.94 +      // loop time is same for Master as for AppSlvs, even though it may be
   13.95 +      // smaller due to higher predictability of the fixed jmp.
   13.96 +   #define MEAS__Capture_Pre_Master_Point\
   13.97 +      saveLowTimeStampCountInto( masterVP->startMasterTSCLow );
   13.98 +
   13.99 +   #define MEAS__Capture_Post_Master_Point \
  13.100 +      saveLowTimeStampCountInto( masterVP->endMasterTSCLow );\
  13.101 +      addIntervalToHist( startMasterTSCLow, endMasterTSCLow,\
  13.102 +                         _PRTopEnv->masterLowTimeHist ); \
  13.103 +      addIntervalToHist( startMasterTSCLow, endMasterTSCLow,\
  13.104 +                         _PRTopEnv->masterHighTimeHist );
  13.105 +
  13.106 +   #define MEAS__Print_Hists_for_Master_Meas \
  13.107 +      printHist( _PRTopEnv->pluginTimeHist );
  13.108 +
  13.109 +#else
  13.110 +   #define MEAS__Insert_Master_Meas_Fields_into_Slave
  13.111 +   #define MEAS__Insert_Master_Meas_Fields_into_MasterEnv 
  13.112 +   #define MEAS__Make_Meas_Hists_for_Master_Meas
  13.113 +   #define MEAS__Capture_Pre_Master_Point 
  13.114 +   #define MEAS__Capture_Post_Master_Point 
  13.115 +   #define MEAS__Print_Hists_for_Master_Meas 
  13.116 +#endif
  13.117 +
  13.118 +      
  13.119 +#ifdef MEAS__TURN_ON_MASTER_LOCK_MEAS
  13.120 +   #define MEAS__Insert_Master_Lock_Meas_Fields_into_MasterEnv \
  13.121 +       Histogram       *masterLockLowTimeHist; \
  13.122 +       Histogram       *masterLockHighTimeHist;
  13.123 +
  13.124 +   #define MEAS__Make_Meas_Hists_for_Master_Lock_Meas \
  13.125 +      _PRTopEnv->masterLockLowTimeHist  = makeFixedBinHist( 50, 0, 2, \
  13.126 +                                               "master lock low time hist");\
  13.127 +      _PRTopEnv->masterLockHighTimeHist  = makeFixedBinHist( 50, 0, 100,\
  13.128 +                                               "master lock high time hist");
  13.129 +
  13.130 +   #define MEAS__Capture_Pre_Master_Lock_Point \
  13.131 +      int32 startStamp, endStamp; \
  13.132 +      saveLowTimeStampCountInto( startStamp );
  13.133 +
  13.134 +   #define MEAS__Capture_Post_Master_Lock_Point \
  13.135 +      saveLowTimeStampCountInto( endStamp ); \
  13.136 +      addIntervalToHist( startStamp, endStamp,\
  13.137 +                         _PRTopEnv->masterLockLowTimeHist ); \
  13.138 +      addIntervalToHist( startStamp, endStamp,\
  13.139 +                         _PRTopEnv->masterLockHighTimeHist );
  13.140 +
  13.141 +   #define MEAS__Print_Hists_for_Master_Lock_Meas \
  13.142 +      printHist( _PRTopEnv->masterLockLowTimeHist ); \
  13.143 +      printHist( _PRTopEnv->masterLockHighTimeHist );
  13.144 +      
  13.145 +#else
  13.146 +   #define MEAS__Insert_Master_Lock_Meas_Fields_into_MasterEnv
  13.147 +   #define MEAS__Make_Meas_Hists_for_Master_Lock_Meas
  13.148 +   #define MEAS__Capture_Pre_Master_Lock_Point 
  13.149 +   #define MEAS__Capture_Post_Master_Lock_Point 
  13.150 +   #define MEAS__Print_Hists_for_Master_Lock_Meas
  13.151 +#endif
  13.152 +
  13.153 +
  13.154 +#ifdef MEAS__TURN_ON_MALLOC_MEAS
  13.155 +   #define MEAS__Insert_Malloc_Meas_Fields_into_MasterEnv\
  13.156 +       Histogram       *mallocTimeHist; \
  13.157 +       Histogram       *freeTimeHist;
  13.158 +
  13.159 +   #define MEAS__Make_Meas_Hists_for_Malloc_Meas \
  13.160 +      _PRTopEnv->mallocTimeHist  = makeFixedBinHistExt( 100, 0, 30,\
  13.161 +                                                       "malloc_time_hist");\
  13.162 +      _PRTopEnv->freeTimeHist  = makeFixedBinHistExt( 100, 0, 30,\
  13.163 +                                                       "free_time_hist");
  13.164 +
  13.165 +   #define MEAS__Capture_Pre_Malloc_Point \
  13.166 +      int32 startStamp, endStamp; \
  13.167 +      saveLowTimeStampCountInto( startStamp );
  13.168 +
  13.169 +   #define MEAS__Capture_Post_Malloc_Point \
  13.170 +      saveLowTimeStampCountInto( endStamp ); \
  13.171 +      addIntervalToHist( startStamp, endStamp,\
  13.172 +                         _PRTopEnv->mallocTimeHist ); 
  13.173 +
  13.174 +   #define MEAS__Capture_Pre_Free_Point \
  13.175 +      int32 startStamp, endStamp; \
  13.176 +      saveLowTimeStampCountInto( startStamp );
  13.177 +
  13.178 +   #define MEAS__Capture_Post_Free_Point \
  13.179 +      saveLowTimeStampCountInto( endStamp ); \
  13.180 +      addIntervalToHist( startStamp, endStamp,\
  13.181 +                         _PRTopEnv->freeTimeHist ); 
  13.182 +
  13.183 +   #define MEAS__Print_Hists_for_Malloc_Meas \
  13.184 +      printHist( _PRTopEnv->mallocTimeHist   ); \
  13.185 +      saveHistToFile( _PRTopEnv->mallocTimeHist   ); \
  13.186 +      printHist( _PRTopEnv->freeTimeHist     ); \
  13.187 +      saveHistToFile( _PRTopEnv->freeTimeHist     ); \
  13.188 +      freeHistExt( _PRTopEnv->mallocTimeHist ); \
  13.189 +      freeHistExt( _PRTopEnv->freeTimeHist   );
  13.190 +      
  13.191 +#else
  13.192 +   #define MEAS__Insert_Malloc_Meas_Fields_into_MasterEnv
  13.193 +   #define MEAS__Make_Meas_Hists_for_Malloc_Meas 
  13.194 +   #define MEAS__Capture_Pre_Malloc_Point
  13.195 +   #define MEAS__Capture_Post_Malloc_Point
  13.196 +   #define MEAS__Capture_Pre_Free_Point
  13.197 +   #define MEAS__Capture_Post_Free_Point
  13.198 +   #define MEAS__Print_Hists_for_Malloc_Meas 
  13.199 +#endif
  13.200 +
  13.201 +
  13.202 +
  13.203 +#ifdef MEAS__TURN_ON_PLUGIN_MEAS 
  13.204 +   #define MEAS__Insert_Plugin_Meas_Fields_into_MasterEnv \
  13.205 +      Histogram       *reqHdlrLowTimeHist; \
  13.206 +      Histogram       *reqHdlrHighTimeHist;
  13.207 +          
  13.208 +   #define MEAS__Make_Meas_Hists_for_Plugin_Meas \
  13.209 +      _PRTopEnv->reqHdlrLowTimeHist  = makeFixedBinHistExt( 100, 0, 200,\
  13.210 +                                                    "plugin_low_time_hist");\
  13.211 +      _PRTopEnv->reqHdlrHighTimeHist  = makeFixedBinHistExt( 100, 0, 200,\
  13.212 +                                                    "plugin_high_time_hist");
  13.213 +
  13.214 +   #define MEAS__startReqHdlr \
  13.215 +      int32 startStamp1, endStamp1; \
  13.216 +      saveLowTimeStampCountInto( startStamp1 );
  13.217 +
  13.218 +   #define MEAS__endReqHdlr \
  13.219 +      saveLowTimeStampCountInto( endStamp1 ); \
  13.220 +      addIntervalToHist( startStamp1, endStamp1, \
  13.221 +                           _PRTopEnv->reqHdlrLowTimeHist ); \
  13.222 +      addIntervalToHist( startStamp1, endStamp1, \
  13.223 +                           _PRTopEnv->reqHdlrHighTimeHist );
  13.224 +
  13.225 +   #define MEAS__Print_Hists_for_Plugin_Meas \
  13.226 +      printHist( _PRTopEnv->reqHdlrLowTimeHist ); \
  13.227 +      saveHistToFile( _PRTopEnv->reqHdlrLowTimeHist ); \
  13.228 +      printHist( _PRTopEnv->reqHdlrHighTimeHist ); \
  13.229 +      saveHistToFile( _PRTopEnv->reqHdlrHighTimeHist ); \
  13.230 +      freeHistExt( _PRTopEnv->reqHdlrLowTimeHist ); \
  13.231 +      freeHistExt( _PRTopEnv->reqHdlrHighTimeHist );
  13.232 +#else
  13.233 +   #define MEAS__Insert_Plugin_Meas_Fields_into_MasterEnv
  13.234 +   #define MEAS__Make_Meas_Hists_for_Plugin_Meas
  13.235 +   #define MEAS__startReqHdlr 
  13.236 +   #define MEAS__endReqHdlr 
  13.237 +   #define MEAS__Print_Hists_for_Plugin_Meas 
  13.238 +
  13.239 +#endif
  13.240 +
  13.241 +      
  13.242 +#ifdef MEAS__TURN_ON_SYSTEM_MEAS
  13.243 +   #define MEAS__Insert_System_Meas_Fields_into_Slave \
  13.244 +      TSCountLowHigh  startSusp; \
  13.245 +      uint64  totalSuspCycles; \
  13.246 +      uint32  numGoodSusp;
  13.247 +
  13.248 +   #define MEAS__Insert_System_Meas_Fields_into_MasterEnv \
  13.249 +       TSCountLowHigh   startMaster; \
  13.250 +       uint64           totalMasterCycles; \
  13.251 +       uint32           numMasterAnimations; \
  13.252 +       TSCountLowHigh   startReqHdlr; \
  13.253 +       uint64           totalPluginCycles; \
  13.254 +       uint32           numPluginAnimations; \
  13.255 +       uint64           cyclesTillStartAnimationMaster; \
  13.256 +       TSCountLowHigh   endAnimationMaster;
  13.257 +
  13.258 +   #define MEAS__startAnimationMaster_forSys \
  13.259 +      TSCountLowHigh startStamp1, endStamp1; \
  13.260 +      saveTSCLowHigh( endStamp1 ); \
  13.261 +      _PRTopEnv->cyclesTillStartAnimationMaster = \
  13.262 +      endStamp1.longVal - masterVP->startSusp.longVal;
  13.263 +
  13.264 +   #define Meas_startReqHdlr_forSys \
  13.265 +        saveTSCLowHigh( startStamp1 ); \
  13.266 +        _PRTopEnv->startReqHdlr.longVal = startStamp1.longVal;
  13.267 + 
  13.268 +   #define MEAS__endAnimationMaster_forSys \
  13.269 +      saveTSCLowHigh( startStamp1 ); \
  13.270 +      _PRTopEnv->endAnimationMaster.longVal = startStamp1.longVal;
  13.271 +
  13.272 +   /*A TSC is stored in VP first thing inside wrapper-lib
  13.273 +    * Now, measures cycles from there to here
  13.274 +    * Master and Plugin will add this value to other trace-seg measures
  13.275 +    */
  13.276 +   #define MEAS__Capture_End_Susp_in_CoreCtlr_ForSys\
  13.277 +          saveTSCLowHigh(endSusp); \
  13.278 +          numCycles = endSusp.longVal - currVP->startSusp.longVal; \
  13.279 +          /*sanity check (400K is about 20K iters)*/ \
  13.280 +          if( numCycles < 400000 ) \
  13.281 +           { currVP->totalSuspCycles += numCycles; \
  13.282 +             currVP->numGoodSusp++; \
  13.283 +           } \
  13.284 +             /*recorded every time, but only read if currVP == MasterVP*/ \
  13.285 +          _PRTopEnv->startMaster.longVal = endSusp.longVal;
  13.286 +
  13.287 +#else
  13.288 +   #define MEAS__Insert_System_Meas_Fields_into_Slave 
  13.289 +   #define MEAS__Insert_System_Meas_Fields_into_MasterEnv 
  13.290 +   #define MEAS__Make_Meas_Hists_for_System_Meas
  13.291 +   #define MEAS__startAnimationMaster_forSys 
  13.292 +   #define MEAS__startReqHdlr_forSys
  13.293 +   #define MEAS__endAnimationMaster_forSys
  13.294 +   #define MEAS__Capture_End_Susp_in_CoreCtlr_ForSys
  13.295 +   #define MEAS__Print_Hists_for_System_Meas 
  13.296 +#endif
  13.297 +
  13.298 +#ifdef HOLISTIC__TURN_ON_PERF_COUNTERS
  13.299 +   
  13.300 +   #define MEAS__Insert_Counter_Handler \
  13.301 +   typedef void (*CounterHandler) (int,int,int,SlaveVP*,uint64,uint64,uint64);
  13.302 + 
  13.303 +   enum eventType {
  13.304 +    DebugEvt = 0,
  13.305 +    AppResponderInvocation_start,
  13.306 +    AppResponder_start,
  13.307 +    AppResponder_end,
  13.308 +    AssignerInvocation_start,
  13.309 +    NextAssigner_start,
  13.310 +    Assigner_start,
  13.311 +    Assigner_end,
  13.312 +    Work_start,
  13.313 +    Work_end,
  13.314 +    HwResponderInvocation_start,
  13.315 +    Timestamp_start,
  13.316 +    Timestamp_end
  13.317 +   };
  13.318 +   
  13.319 +   #define saveCyclesAndInstrs(core,cycles,instrs,cachem) do{ \
  13.320 +   int cycles_fd = _PRTopEnv->cycles_counter_fd[core]; \
  13.321 +   int instrs_fd = _PRTopEnv->instrs_counter_fd[core]; \
  13.322 +   int cachem_fd = _PRTopEnv->cachem_counter_fd[core]; \
  13.323 +   int nread;                                           \
  13.324 +                                                        \
  13.325 +   nread = read(cycles_fd,&(cycles),sizeof(cycles));    \
  13.326 +   if(nread<0){                                         \
  13.327 +       perror("Error reading cycles counter");          \
  13.328 +       cycles = 0;                                      \
  13.329 +   }                                                    \
  13.330 +                                                        \
  13.331 +   nread = read(instrs_fd,&(instrs),sizeof(instrs));    \
  13.332 +   if(nread<0){                                         \
  13.333 +       perror("Error reading cycles counter");          \
  13.334 +       instrs = 0;                                      \
  13.335 +   }                                                    \
  13.336 +   nread = read(cachem_fd,&(cachem),sizeof(cachem));    \
  13.337 +   if(nread<0){                                         \
  13.338 +       perror("Error reading last level cache miss counter");          \
  13.339 +       cachem = 0;                                      \
  13.340 +   }                                                    \
  13.341 +   } while (0) 
  13.342 +
  13.343 +   #define MEAS__Insert_Counter_Meas_Fields_into_MasterEnv \
  13.344 +     int cycles_counter_fd[NUM_CORES]; \
  13.345 +     int instrs_counter_fd[NUM_CORES]; \
  13.346 +     int cachem_counter_fd[NUM_CORES]; \
  13.347 +     uint64 start_master_lock[NUM_CORES][3]; \
  13.348 +     CounterHandler counterHandler;
  13.349 +
  13.350 +   #define HOLISTIC__Setup_Perf_Counters setup_perf_counters();
  13.351 +   
  13.352 +
  13.353 +   #define HOLISTIC__CoreCtrl_Setup \
  13.354 +   CounterHandler counterHandler = _PRTopEnv->counterHandler; \
  13.355 +   SlaveVP      *lastVPBeforeMaster = NULL; \
  13.356 +   /*if(thisCoresThdParams->coreNum == 0){ \
  13.357 +       uint64 initval = tsc_offset_send(thisCoresThdParams,0); \
  13.358 +       while(!coreCtlrThdParams[NUM_CORES - 2]->ret_tsc); \
  13.359 +   } \
  13.360 +   if(0 < (thisCoresThdParams->coreNum) && (thisCoresThdParams->coreNum) < (NUM_CORES - 1)){ \
  13.361 +       ThdParams* sendCoresThdParams = coreCtlrThdParams[thisCoresThdParams->coreNum - 1]; \
  13.362 +       int sndctr = tsc_offset_resp(sendCoresThdParams, 0); \
  13.363 +       uint64 initval = tsc_offset_send(thisCoresThdParams,0); \
  13.364 +       while(!coreCtlrThdParams[NUM_CORES - 2]->ret_tsc); \
  13.365 +   }  \
  13.366 +   if(thisCoresThdParams->coreNum == (NUM_CORES - 1)){ \
  13.367 +       ThdParams* sendCoresThdParams = coreCtlrThdParams[thisCoresThdParams->coreNum - 1]; \
  13.368 +       int sndctr = tsc_offset_resp(sendCoresThdParams,0); \
  13.369 +   }*/
  13.370 +   
  13.371 +   
  13.372 +   #define HOLISTIC__Insert_Master_Global_Vars \
  13.373 +        int vpid,task; \
  13.374 +        CounterHandler counterHandler = _PRTopEnv->counterHandler;
  13.375 +   
  13.376 +   #define HOLISTIC__Record_last_work lastVPBeforeMaster = currVP;
  13.377 +
  13.378 +   #define HOLISTIC__Record_AppResponderInvocation_start \
  13.379 +      uint64 cycles,instrs,cachem; \
  13.380 +      saveCyclesAndInstrs(thisCoresIdx,cycles, instrs,cachem); \
  13.381 +      if(lastVPBeforeMaster){ \
  13.382 +        (*counterHandler)(AppResponderInvocation_start,lastVPBeforeMaster->slaveNum,lastVPBeforeMaster->numTimesAssignedToASlot,lastVPBeforeMaster,cycles,instrs,cachem); \
  13.383 +        lastVPBeforeMaster = NULL; \
  13.384 +      } else { \
  13.385 +          _PRTopEnv->start_master_lock[thisCoresIdx][0] = cycles; \
  13.386 +          _PRTopEnv->start_master_lock[thisCoresIdx][1] = instrs; \
  13.387 +          _PRTopEnv->start_master_lock[thisCoresIdx][2] = cachem; \
  13.388 +      }
  13.389 + 
  13.390 +           /* Request Handler may call resume() on the VP, but we want to 
  13.391 +                * account the whole interval to the same task. Therefore, need
  13.392 +                * to save task ID at the beginning.
  13.393 +                * 
  13.394 +                * Using this value as "end of AppResponder Invocation Time"
  13.395 +                * is possible if there is only one SchedSlot per core -
  13.396 +                * invoking processor is last to be treated here! If more than
  13.397 +                * one slot, MasterLoop processing time for all but the last VP
  13.398 +                * would be erroneously counted as invocation time.
  13.399 +                */
  13.400 +   #define HOLISTIC__Record_AppResponder_start \
  13.401 +               vpid = currSlot->slaveAssignedToSlot->slaveNum; \
  13.402 +               task = currSlot->slaveAssignedToSlot->numTimesAssignedToASlot; \
  13.403 +               uint64 cycles, instrs, cachem; \
  13.404 +               saveCyclesAndInstrs(thisCoresIdx,cycles, instrs,cachem); \
  13.405 +               (*counterHandler)(AppResponder_start,vpid,task,currSlot->slaveAssignedToSlot,cycles,instrs,cachem);
  13.406 +
  13.407 +   #define HOLISTIC__Record_AppResponder_end \
  13.408 +        uint64 cycles2,instrs2,cachem2; \
  13.409 +        saveCyclesAndInstrs(thisCoresIdx,cycles2, instrs2,cachem2); \
  13.410 +        (*counterHandler)(AppResponder_end,vpid,task,currSlot->slaveAssignedToSlot,cycles2,instrs2,cachem2); \
  13.411 +        (*counterHandler)(Timestamp_end,vpid,task,currSlot->slaveAssignedToSlot,rdtsc(),0,0);
  13.412 +
  13.413 +   
  13.414 +   /* Don't know who to account time to yet - goes to assigned VP
  13.415 +    * after the call.
  13.416 +    */
  13.417 +   #define HOLISTIC__Record_Assigner_start \
  13.418 +       int empty = FALSE; \
  13.419 +       if(currSlot->slaveAssignedToSlot == NULL){ \
  13.420 +           empty= TRUE; \
  13.421 +       } \
  13.422 +       uint64 tmp_cycles, tmp_instrs, tmp_cachem; \
  13.423 +       saveCyclesAndInstrs(thisCoresIdx,tmp_cycles,tmp_instrs,tmp_cachem); \
  13.424 +       uint64 tsc = rdtsc(); \
  13.425 +       if(vpid > 0) { \
  13.426 +           (*counterHandler)(NextAssigner_start,vpid,task,currSlot->slaveAssignedToSlot,tmp_cycles,tmp_instrs,tmp_cachem); \
  13.427 +           vpid = 0; \
  13.428 +           task = 0; \
  13.429 +        }
  13.430 +
  13.431 +   #define HOLISTIC__Record_Assigner_end \
  13.432 +        uint64 cycles,instrs,cachem; \
  13.433 +        saveCyclesAndInstrs(thisCoresIdx,cycles,instrs,cachem); \
  13.434 +        if(empty){ \
  13.435 +            (*counterHandler)(AssignerInvocation_start,assignedSlaveVP->slaveNum,assignedSlaveVP->numTimesAssignedToASlot,assignedSlaveVP,_PRTopEnv->start_master_lock[thisCoresIdx][0],_PRTopEnv->start_master_lock[thisCoresIdx][1],masterEnv->start_master_lock[thisCoresIdx][2]); \
  13.436 +        } \
  13.437 +        (*counterHandler)(Timestamp_start,assignedSlaveVP->slaveNum,assignedSlaveVP->numTimesAssignedToASlot,assignedSlaveVP,tsc,0,0); \
  13.438 +        (*counterHandler)(Assigner_start,assignedSlaveVP->slaveNum,assignedSlaveVP->numTimesAssignedToASlot,assignedSlaveVP,tmp_cycles,tmp_instrs,tmp_cachem); \
  13.439 +        (*counterHandler)(Assigner_end,assignedSlaveVP->slaveNum,assignedSlaveVP->numTimesAssignedToASlot,assignedSlaveVP,cycles,instrs,tmp_cachem);
  13.440 +
  13.441 +   #define HOLISTIC__Record_Work_start \
  13.442 +        if(currVP){ \
  13.443 +                uint64 cycles,instrs,cachem; \
  13.444 +                saveCyclesAndInstrs(thisCoresIdx,cycles, instrs,cachem); \
  13.445 +                (*counterHandler)(Work_start,currVP->slaveNum,currVP->numTimesAssignedToASlot,currVP,cycles,instrs,cachem); \
  13.446 +        }
  13.447 +   
  13.448 +   #define HOLISTIC__Record_Work_end \
  13.449 +       if(currVP){ \
  13.450 +               uint64 cycles,instrs,cachem; \
  13.451 +               saveCyclesAndInstrs(thisCoresIdx,cycles, instrs,cachem); \
  13.452 +               (*counterHandler)(Work_end,currVP->slaveNum,currVP->numTimesAssignedToASlot,currVP,cycles,instrs,cachem); \
  13.453 +       }
  13.454 +
  13.455 +   #define HOLISTIC__Record_HwResponderInvocation_start \
  13.456 +        uint64 cycles,instrs,cachem; \
  13.457 +        saveCyclesAndInstrs(animatingSlv->coreAnimatedBy,cycles, instrs,cachem); \
  13.458 +        (*(_PRTopEnv->counterHandler))(HwResponderInvocation_start,animatingSlv->slaveNum,animatingSlv->numTimesAssignedToASlot,animatingSlv,cycles,instrs,cachem); 
  13.459 +        
  13.460 +
  13.461 +   #define getReturnAddressBeforeLibraryCall(vp_ptr, res_ptr) do{     \
  13.462 +void* frame_ptr0 = vp_ptr->framePtr;                               \
  13.463 +void* frame_ptr1 = *((void**)frame_ptr0);                          \
  13.464 +void* frame_ptr2 = *((void**)frame_ptr1);                          \
  13.465 +void* frame_ptr3 = *((void**)frame_ptr2);                          \
  13.466 +void* ret_addr = *((void**)frame_ptr3 + 1);                        \
  13.467 +*res_ptr = ret_addr;                                               \
  13.468 +} while (0)
  13.469 +
  13.470 +#else  
  13.471 +   #define MEAS__Insert_Counter_Handler
  13.472 +   #define MEAS__Insert_Counter_Meas_Fields_into_MasterEnv
  13.473 +   #define HOLISTIC__Setup_Perf_Counters
  13.474 +   #define HOLISTIC__CoreCtrl_Setup
  13.475 +   #define HOLISTIC__Insert_Master_Global_Vars
  13.476 +   #define HOLISTIC__Record_last_work
  13.477 +   #define HOLISTIC__Record_AppResponderInvocation_start
  13.478 +   #define HOLISTIC__Record_AppResponder_start
  13.479 +   #define HOLISTIC__Record_AppResponder_end
  13.480 +   #define HOLISTIC__Record_Assigner_start
  13.481 +   #define HOLISTIC__Record_Assigner_end
  13.482 +   #define HOLISTIC__Record_Work_start
  13.483 +   #define HOLISTIC__Record_Work_end
  13.484 +   #define HOLISTIC__Record_HwResponderInvocation_start
  13.485 +   #define getReturnAddressBeforeLibraryCall(vp_ptr, res_ptr)
  13.486 +#endif
  13.487 +
  13.488 +//Experiment in two-step macros -- if doesn't work, insert each separately
  13.489 +#define MEAS__Insert_Meas_Fields_into_Slave  \
  13.490 +   MEAS__Insert_Susp_Meas_Fields_into_Slave \
  13.491 +   MEAS__Insert_Master_Meas_Fields_into_Slave \
  13.492 +   MEAS__Insert_System_Meas_Fields_into_Slave 
  13.493 +
  13.494 +
  13.495 +//======================  Histogram Macros -- Create ========================
  13.496 +//
  13.497 +//
  13.498 +
  13.499 +//The language implementation should include a definition of this macro,
  13.500 +// which creates all the histograms the language uses to collect measurements
  13.501 +// of plugin operation -- so, if the language didn't define it, must
  13.502 +// define it here (as empty), to avoid compile error
  13.503 +#ifndef MEAS__Make_Meas_Hists_for_Language
  13.504 +#define MEAS__Make_Meas_Hists_for_Language
  13.505 +#endif
  13.506 +
  13.507 +#define makeAMeasHist( histInfo, idx, name, numBins, startVal, binWidth ) \
  13.508 +      makeHighestDynArrayIndexBeAtLeast( _PRTopEnv->measHistsInfo, idx ); \
  13.509 +      _PRTopEnv->measHists[idx] =  \
  13.510 +                       makeFixedBinHist( numBins, startVal, binWidth, name );
  13.511 +
  13.512 +//==============================  Probes  ===================================
  13.513 +
  13.514 +
  13.515 +//===========================================================================
  13.516 +#endif	/* _PR_DEFS_MEAS_H */
  13.517 +
    14.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.2 +++ b/Services_offered_by_PR/Measurement_and_Stats/dependency.c	Fri Jul 26 12:12:34 2013 -0700
    14.3 @@ -0,0 +1,79 @@
    14.4 +
    14.5 +
    14.6 +#include "dependency.h"
    14.7 +
    14.8 +Dependency* new_dependency(int from_vp, int from_task, int to_vp, int to_task){
    14.9 +    Dependency* newDep = (Dependency*) PR_int__malloc(sizeof(Dependency));
   14.10 +    if (newDep!=NULL){
   14.11 +        newDep->from_vp = from_vp;
   14.12 +        newDep->from_task = from_task;
   14.13 +        newDep->to_vp = to_vp;
   14.14 +        newDep->to_task = to_task;
   14.15 +    }
   14.16 +    return newDep;
   14.17 +}
   14.18 +
   14.19 +NtoN* new_NtoN(int id){
   14.20 +    NtoN* newn = (NtoN*) PR_int__malloc(sizeof(NtoN));
   14.21 +    newn->id = id;
   14.22 +    newn->senders = makeListOfArrays(sizeof(Unit), 64);
   14.23 +    newn->receivers = makeListOfArrays(sizeof(Unit), 64);
   14.24 +    return newn;
   14.25 +}
   14.26 +
   14.27 +int set_dependency_file(FILE* file){
   14.28 +    dependency_file = file;
   14.29 +}
   14.30 +
   14.31 +void print_ctl_dependency_to_file(void* _dep){
   14.32 +    Dependency* dep = (Dependency*) _dep;
   14.33 +    if(!dep) return;
   14.34 +    fprintf(dependency_file,"ctlDep,%d,%d,%d,%d\n",dep->from_vp,dep->from_task,dep->to_vp,dep->to_task);
   14.35 +}
   14.36 +
   14.37 +void print_comm_dependency_to_file(void* _dep){
   14.38 +    Dependency* dep = (Dependency*) _dep;
   14.39 +    if(!dep) return;
   14.40 +    fprintf(dependency_file,"commDep,%d,%d,%d,%d\n",dep->from_vp,dep->from_task,dep->to_vp,dep->to_task);
   14.41 +}
   14.42 +
   14.43 +void print_dyn_dependency_to_file(void* _dep){
   14.44 +    Dependency* dep = (Dependency*) _dep;
   14.45 +    if(!dep) return;
   14.46 +    fprintf(dependency_file,"dynDep,%d,%d,%d,%d\n",dep->from_vp,dep->from_task,dep->to_vp,dep->to_task);
   14.47 +}
   14.48 +
   14.49 +void print_hw_dependency_to_file(void* _dep){
   14.50 +    Dependency* dep = (Dependency*) _dep;
   14.51 +    if(!dep) return;
   14.52 +    fprintf(dependency_file,"hwDep,%d,%d,%d,%d\n",dep->from_vp,dep->from_task,dep->to_vp,dep->to_task);
   14.53 +}
   14.54 +
   14.55 +void print_dependency_to_file(void* _dep){
   14.56 +    Dependency* dep = (Dependency*) _dep;
   14.57 +    if(!dep) return;
   14.58 +    fprintf(dependency_file,"VP_%d_%d -> VP_%d_%d;\n",dep->from_vp,dep->from_task,dep->to_vp,dep->to_task);
   14.59 +}
   14.60 +
   14.61 +void print_unit_to_file(void* _unit){
   14.62 +    Unit* unit = (Unit*) _unit;
   14.63 +    if(!unit) return;
   14.64 +    fprintf(dependency_file,"unit,%d,%d\n",unit->vp,unit->task);
   14.65 +}
   14.66 +
   14.67 +void print_nton_set_helper(void* _u){
   14.68 +    Unit* u = (Unit*) _u;
   14.69 +    if(!u) return;
   14.70 +    fprintf(dependency_file,",%d,%d",u->vp,u->task);
   14.71 +}
   14.72 +
   14.73 +void print_nton_to_file(void* _nton){
   14.74 +    NtoN* nton = (NtoN*) _nton;
   14.75 +    if(!nton) return;
   14.76 +    //assert(nton->senders->next_free_index==nton->receivers->next_free_index);
   14.77 +    int numInSet = nton->senders->next_free_index;
   14.78 +    fprintf(dependency_file,"NtoN,%d",numInSet);
   14.79 +    forAllInListOfArraysDo(nton->senders,&print_nton_set_helper);
   14.80 +    forAllInListOfArraysDo(nton->receivers,&print_nton_set_helper);
   14.81 +    fprintf(dependency_file,"\n");
   14.82 +}
   14.83 \ No newline at end of file
    15.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.2 +++ b/Services_offered_by_PR/Measurement_and_Stats/dependency.h	Fri Jul 26 12:12:34 2013 -0700
    15.3 @@ -0,0 +1,57 @@
    15.4 +/* 
    15.5 + * File:   dependency.h
    15.6 + * Author: Nina Engelhardt
    15.7 + *
    15.8 + * Created on 29. August 2011, 17:41
    15.9 + */
   15.10 +
   15.11 +#ifndef  _PR__DEPENDENCY_H
   15.12 +#define	_PR__DEPENDENCY_H
   15.13 +
   15.14 +
   15.15 +#include <stdio.h>
   15.16 +#include "PR__common_includes/PR__primitive_data_types.h"
   15.17 +#include "ListOfArrays/ListOfArrays.h"
   15.18 +
   15.19 +typedef struct {
   15.20 +    int vp;
   15.21 +    int task;
   15.22 +} Unit;
   15.23 +
   15.24 +typedef struct {
   15.25 +    int from_vp;
   15.26 +    int from_task;
   15.27 +    int to_vp;
   15.28 +    int to_task;
   15.29 +} Dependency; 
   15.30 +
   15.31 +typedef struct {
   15.32 +    int32 id;
   15.33 +    ListOfArrays* senders;
   15.34 +    ListOfArrays* receivers;
   15.35 +} NtoN;
   15.36 +
   15.37 +FILE* dependency_file;
   15.38 +
   15.39 +Dependency* new_dependency(int from_vp, int from_task, int to_vp, int to_task);
   15.40 +
   15.41 +NtoN* new_NtoN(int id);
   15.42 +
   15.43 +int set_dependency_file(FILE* file);
   15.44 +
   15.45 +void print_ctl_dependency_to_file(void* _dep);
   15.46 +
   15.47 +void print_comm_dependency_to_file(void* _dep);
   15.48 +
   15.49 +void print_dyn_dependency_to_file(void* _dep);
   15.50 +
   15.51 +void print_hw_dependency_to_file(void* _dep);
   15.52 +
   15.53 +void print_dependency_to_file(void* dep);
   15.54 +
   15.55 +void print_unit_to_file(void* unit);
   15.56 +
   15.57 +void print_nton_to_file(void* _nton);
   15.58 +
   15.59 +#endif	/* DEPENDENCY_H */
   15.60 +
    16.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.2 +++ b/Services_offered_by_PR/Measurement_and_Stats/probes__wrapper_library.c	Fri Jul 26 12:12:34 2013 -0700
    16.3 @@ -0,0 +1,151 @@
    16.4 +/*
    16.5 + * Copyright 2010  OpenSourceStewardshipFoundation
    16.6 + *
    16.7 + * Licensed under BSD
    16.8 + */
    16.9 +
   16.10 +#include <stdio.h>
   16.11 +#include <malloc.h>
   16.12 +#include <sys/time.h>
   16.13 +
   16.14 +#include "probes__wrapper_library.h"
   16.15 +
   16.16 +
   16.17 +
   16.18 +//====================  Probes =================
   16.19 +/*
   16.20 + * In practice, probe operations are called from the app, from inside slaves
   16.21 + *  -- so have to be sure each probe is single-Slv owned, and be sure that
   16.22 + *  any place common structures are modified it's done inside the master.
   16.23 + * So -- the only place common structures are modified is during creation.
   16.24 + *  after that, all mods are to individual instances.
   16.25 + *
   16.26 + * Thniking perhaps should change the semantics to be that probes are
   16.27 + *  attached to the virtual processor -- and then everything is guaranteed
   16.28 + *  to be isolated -- except then can't take any intervals that span Slvs,
   16.29 + *  and would have to transfer the probes to Master env when Slv dissipates..
   16.30 + *  gets messy..
   16.31 + *
   16.32 + * For now, just making so that probe creation causes a suspend, so that
   16.33 + *  the dynamic array in the master env is only modified from the master
   16.34 + * 
   16.35 + */
   16.36 +
   16.37 +//============================  Helpers ===========================
   16.38 +inline void 
   16.39 +doNothing()
   16.40 + {
   16.41 + }
   16.42 +
   16.43 +float64 inline
   16.44 +giveInterval( struct timeval _start, struct timeval _end )
   16.45 + { float64 start, end;
   16.46 +   start = _start.tv_sec + _start.tv_usec / 1000000.0;
   16.47 +   end   = _end.tv_sec   + _end.tv_usec   / 1000000.0;
   16.48 +   return end - start;
   16.49 + }
   16.50 +          
   16.51 +//=================================================================
   16.52 +IntervalProbe *
   16.53 +create_generic_probe( char *nameStr, SlaveVP *animSlv )
   16.54 + {
   16.55 +   PRServiceReq reqData;
   16.56 +
   16.57 +   reqData.reqType  = make_probe;
   16.58 +   reqData.nameStr  = nameStr;
   16.59 +
   16.60 +   PR_WL__send_service_request( &reqData, animSlv );
   16.61 +
   16.62 +   return animSlv->dataRetFromReq;
   16.63 + }
   16.64 +
   16.65 +/*Use this version from outside PR -- it uses external malloc, and modifies
   16.66 + * dynamic array, so can't be animated in a slave Slv
   16.67 + */
   16.68 +/* Can't access _PRTopEnv in a wrapper library
   16.69 +IntervalProbe *
   16.70 +ext__create_generic_probe( char *nameStr )
   16.71 + { IntervalProbe *newProbe;
   16.72 +   int32          nameLen;
   16.73 +
   16.74 +   newProbe          = malloc( sizeof(IntervalProbe) );
   16.75 +   nameLen = strlen( nameStr );
   16.76 +   newProbe->nameStr = malloc( nameLen );
   16.77 +   memcpy( newProbe->nameStr, nameStr, nameLen );
   16.78 +   newProbe->hist    = NULL;
   16.79 +   newProbe->schedChoiceWasRecorded = FALSE;
   16.80 +   newProbe->probeID =
   16.81 +             addToDynArray( newProbe, _PRTopEnv->dynIntervalProbesInfo );
   16.82 +
   16.83 +   return newProbe;
   16.84 + }
   16.85 +*/
   16.86 +//============================ Fns def in header =======================
   16.87 +
   16.88 +int32
   16.89 +PR_impl__create_single_interval_probe( char *nameStr, SlaveVP *animSlv )
   16.90 + { IntervalProbe *newProbe;
   16.91 +
   16.92 +   newProbe = create_generic_probe( nameStr, animSlv );
   16.93 +   
   16.94 +   return newProbe->probeID;
   16.95 + }
   16.96 +
   16.97 +int32
   16.98 +PR_impl__create_histogram_probe( int32   numBins, float64    startValue,
   16.99 +               float64 binWidth, char   *nameStr, SlaveVP *animSlv )
  16.100 + { IntervalProbe *newProbe;
  16.101 +
  16.102 +   newProbe = create_generic_probe( nameStr, animSlv );
  16.103 +   
  16.104 +#ifdef PROBES__USE_TIME_OF_DAY_PROBES
  16.105 +   DblHist *hist;
  16.106 +   hist =  makeDblHistogram( numBins, startValue, binWidth );
  16.107 +#else
  16.108 +   Histogram *hist;
  16.109 +   hist =  makeHistogram( numBins, startValue, binWidth );
  16.110 +#endif
  16.111 +   newProbe->hist = hist;
  16.112 +   return newProbe->probeID;
  16.113 + }
  16.114 +
  16.115 +
  16.116 +int32
  16.117 +PR_impl__record_time_point_into_new_probe( char *nameStr, SlaveVP *animSlv)
  16.118 + { IntervalProbe *newProbe;
  16.119 +   struct timeval *startStamp;
  16.120 +   float64 startSecs;
  16.121 +
  16.122 +   newProbe           = create_generic_probe( nameStr, animSlv );
  16.123 +   newProbe->endSecs  = 0;
  16.124 +
  16.125 +   
  16.126 +   gettimeofday( &(newProbe->startStamp), NULL);
  16.127 +
  16.128 +      //turn into a double
  16.129 +   startStamp = &(newProbe->startStamp);
  16.130 +   startSecs = startStamp->tv_sec + ( startStamp->tv_usec / 1000000.0 );
  16.131 +   newProbe->startSecs = startSecs;
  16.132 +
  16.133 +   return newProbe->probeID;
  16.134 + }
  16.135 +
  16.136 +int32
  16.137 +PR_ext_impl__record_time_point_into_new_probe( char *nameStr )
  16.138 + { IntervalProbe *newProbe;
  16.139 +   struct timeval *startStamp;
  16.140 +   float64 startSecs;
  16.141 +
  16.142 +   newProbe           = ext__create_generic_probe( nameStr );
  16.143 +   newProbe->endSecs  = 0;
  16.144 +
  16.145 +   gettimeofday( &(newProbe->startStamp), NULL);
  16.146 +
  16.147 +      //turn into a double
  16.148 +   startStamp = &(newProbe->startStamp);
  16.149 +   startSecs = startStamp->tv_sec + ( startStamp->tv_usec / 1000000.0 );
  16.150 +   newProbe->startSecs = startSecs;
  16.151 +
  16.152 +   return newProbe->probeID;
  16.153 + }
  16.154 +
    17.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    17.2 +++ b/Services_offered_by_PR/Measurement_and_Stats/probes__wrapper_library.h	Fri Jul 26 12:12:34 2013 -0700
    17.3 @@ -0,0 +1,192 @@
    17.4 +/*
    17.5 + *  Copyright 2009 OpenSourceStewardshipFoundation.org
    17.6 + *  Licensed under GNU General Public License version 2
    17.7 + *
    17.8 + * Author: seanhalle@yahoo.com
    17.9 + * 
   17.10 + */
   17.11 +
   17.12 +#ifndef _PROBES_wrapper_library_H
   17.13 +#define	_PROBES_wrapper_library_H
   17.14 +#define _GNU_SOURCE
   17.15 +
   17.16 +#include "PR__common_includes/PR__common_structs.h"
   17.17 +
   17.18 +#include <sys/time.h>
   17.19 +
   17.20 +/*Note on order of include files:  
   17.21 + * This file relies on #defines that appear in other files, which must come
   17.22 + * first in the #include sequence..
   17.23 + */
   17.24 +
   17.25 +/*Use these aliases in application code*/
   17.26 +#define PR_App__record_time_point_into_new_probe PR_WL__record_time_point_into_new_probe
   17.27 +#define PR_App__create_single_interval_probe   PR_WL__create_single_interval_probe
   17.28 +#define PR_App__create_histogram_probe         PR_WL__create_histogram_probe
   17.29 +#define PR_App__index_probe_by_its_name        PR_WL__index_probe_by_its_name
   17.30 +#define PR_App__get_probe_by_name              PR_WL__get_probe_by_name
   17.31 +#define PR_App__record_sched_choice_into_probe PR_WL__record_sched_choice_into_probe
   17.32 +#define PR_App__record_interval_start_in_probe PR_WL__record_interval_start_in_probe 
   17.33 +#define PR_App__record_interval_end_in_probe   PR_WL__record_interval_end_in_probe
   17.34 +#define PR_App__print_stats_of_probe           PR_WL__print_stats_of_probe
   17.35 +#define PR_App__print_stats_of_all_probes      PR_WL__print_stats_of_all_probes 
   17.36 +
   17.37 +
   17.38 +//==========================
   17.39 +#ifdef PROBES__USE_TSC_PROBES
   17.40 +   #define PROBES__Insert_timestamps_and_intervals_into_probe_struct \
   17.41 +   TSCount    startStamp; \
   17.42 +   TSCount    endStamp; \
   17.43 +   TSCount    interval; \
   17.44 +   Histogram *hist; /*if left NULL, then is single interval probe*/
   17.45 +#endif
   17.46 +#ifdef PROBES__USE_TIME_OF_DAY_PROBES
   17.47 +   #define PROBES__Insert_timestamps_and_intervals_into_probe_struct \
   17.48 +   struct timeval  startStamp; \
   17.49 +   struct timeval  endStamp; \
   17.50 +   float64         startSecs; \
   17.51 +   float64         endSecs; \
   17.52 +   float64         interval; \
   17.53 +   DblHist        *hist; /*if NULL, then is single interval probe*/
   17.54 +#endif
   17.55 +#ifdef PROBES__USE_PERF_CTR_PROBES
   17.56 +   #define PROBES__Insert_timestamps_and_intervals_into_probe_struct \
   17.57 +   int64  startStamp; \
   17.58 +   int64  endStamp; \
   17.59 +   int64  interval; \
   17.60 +   Histogram *hist; /*if left NULL, then is single interval probe*/
   17.61 +#endif
   17.62 +
   17.63 +//typedef struct _IntervalProbe IntervalProbe; -- is in PR.h
   17.64 +struct _IntervalProbe
   17.65 + {
   17.66 +   char           *nameStr;
   17.67 +   int32           probeID;
   17.68 +
   17.69 +   int32           schedChoiceWasRecorded;
   17.70 +   int32           coreNum;
   17.71 +   int32           slaveNum;
   17.72 +   float64         slaveCreateSecs;
   17.73 +   PROBES__Insert_timestamps_and_intervals_into_probe_struct;
   17.74 + };
   17.75 +
   17.76 +//=========================== NEVER USE THESE ==========================
   17.77 +/*NEVER use these in any code!!  These are here only for use in the macros
   17.78 + * defined in this file!!
   17.79 + */
   17.80 +int32
   17.81 +PR_impl__create_single_interval_probe( char *nameStr, SlaveVP *animSlv );
   17.82 +
   17.83 +int32
   17.84 +PR_impl__create_histogram_probe( int32   numBins, float64    startValue,
   17.85 +               float64 binWidth, char    *nameStr, SlaveVP *animSlv );
   17.86 +
   17.87 +int32
   17.88 +PR_impl__record_time_point_into_new_probe( char *nameStr, SlaveVP *animSlv);
   17.89 +
   17.90 +int32
   17.91 +PR_ext_impl__record_time_point_into_new_probe( char *nameStr );
   17.92 +
   17.93 +void
   17.94 +PR_impl__free_probe( IntervalProbe *probe );
   17.95 +
   17.96 +void
   17.97 +PR_impl__index_probe_by_its_name( int32 probeID, SlaveVP *animSlv );
   17.98 +
   17.99 +IntervalProbe *
  17.100 +PR_impl__get_probe_by_name( char *probeName, SlaveVP *animSlv );
  17.101 +
  17.102 +void
  17.103 +PR_impl__record_sched_choice_into_probe( int32 probeID, SlaveVP *animSlv );
  17.104 +
  17.105 +void
  17.106 +PR_impl__record_interval_start_in_probe( int32 probeID );
  17.107 +
  17.108 +void
  17.109 +PR_impl__record_interval_end_in_probe( int32 probeID );
  17.110 +
  17.111 +void
  17.112 +PR_impl__print_stats_of_probe( IntervalProbe *probe );
  17.113 +
  17.114 +void
  17.115 +PR_impl__print_stats_of_all_probes();
  17.116 +
  17.117 +
  17.118 +//======================== Probes =============================
  17.119 +//
  17.120 +// Use macros to allow turning probes off with a #define switch
  17.121 +// This means probes have zero impact on performance when off
  17.122 +//=============================================================
  17.123 +
  17.124 +#ifdef PROBES__TURN_ON_STATS_PROBES
  17.125 +
  17.126 +   #define PROBES__Create_Probe_Bookkeeping_Vars \
  17.127 +      _PRTopEnv->dynIntervalProbesInfo = \
  17.128 +       makePrivDynArrayOfSize( (void***)&(_PRTopEnv->intervalProbes), 200); \
  17.129 +      \
  17.130 +      _PRTopEnv->probeNameHashTbl = makeHashTable( 1000, &PR__free ); \
  17.131 +      \
  17.132 +      /*put creation time directly into master env, for fast retrieval*/ \
  17.133 +   struct timeval timeStamp; \
  17.134 +   gettimeofday( &(timeStamp), NULL); \
  17.135 +   _PRTopEnv->createPtInSecs = \
  17.136 +                           timeStamp.tv_sec +(timeStamp.tv_usec/1000000.0);
  17.137 +
  17.138 +   #define PR_WL__record_time_point_into_new_probe( nameStr, animSlv ) \
  17.139 +           PR_impl__record_time_point_in_new_probe( nameStr, animSlv )
  17.140 +
  17.141 +   #define PR_ext__record_time_point_into_new_probe( nameStr ) \
  17.142 +           PR_ext_impl__record_time_point_into_new_probe( nameStr )
  17.143 +
  17.144 +   #define PR_WL__create_single_interval_probe( nameStr, animSlv ) \
  17.145 +           PR_impl__create_single_interval_probe( nameStr, animSlv )
  17.146 +
  17.147 +   #define PR_WL__create_histogram_probe(      numBins, startValue,              \
  17.148 +                                             binWidth, nameStr, animSlv )       \
  17.149 +           PR_impl__create_histogram_probe( numBins, startValue,              \
  17.150 +                                             binWidth, nameStr, animSlv )
  17.151 +   #define PR_int__free_probe( probe ) \
  17.152 +           PR_impl__free_probe( probe )
  17.153 +
  17.154 +   #define PR_WL__index_probe_by_its_name( probeID, animSlv ) \
  17.155 +           PR_impl__index_probe_by_its_name( probeID, animSlv )
  17.156 +
  17.157 +   #define PR_WL__get_probe_by_name( probeID, animSlv ) \
  17.158 +           PR_impl__get_probe_by_name( probeName, animSlv )
  17.159 +
  17.160 +   #define PR_WL__record_sched_choice_into_probe( probeID, animSlv ) \
  17.161 +           PR_impl__record_sched_choice_into_probe( probeID, animSlv )
  17.162 +
  17.163 +   #define PR_WL__record_interval_start_in_probe( probeID ) \
  17.164 +           PR_impl__record_interval_start_in_probe( probeID )
  17.165 +
  17.166 +   #define PR_WL__record_interval_end_in_probe( probeID ) \
  17.167 +           PR_impl__record_interval_end_in_probe( probeID )
  17.168 +
  17.169 +   #define PR_WL__print_stats_of_probe( probeID ) \
  17.170 +           PR_impl__print_stats_of_probe( probeID )
  17.171 +
  17.172 +   #define PR_WL__print_stats_of_all_probes() \
  17.173 +           PR_impl__print_stats_of_all_probes()
  17.174 +
  17.175 +
  17.176 +#else
  17.177 +   #define PROBES__Create_Probe_Bookkeeping_Vars
  17.178 +   #define PR_WL__record_time_point_into_new_probe( nameStr, animSlv ) 0 /* do nothing */
  17.179 +   #define PR_ext__record_time_point_into_new_probe( nameStr )  0 /* do nothing */
  17.180 +   #define PR_WL__create_single_interval_probe( nameStr, animSlv ) 0 /* do nothing */
  17.181 +   #define PR_WL__create_histogram_probe( numBins, startValue,              \
  17.182 +                                             binWidth, nameStr, animSlv )       \
  17.183 +          0 /* do nothing */
  17.184 +   #define PR_WL__index_probe_by_its_name( probeID, animSlv ) /* do nothing */
  17.185 +   #define PR_WL__get_probe_by_name( probeID, animSlv ) NULL /* do nothing */
  17.186 +   #define PR_WL__record_sched_choice_into_probe( probeID, animSlv ) /* do nothing */
  17.187 +   #define PR_WL__record_interval_start_in_probe( probeID )  /* do nothing */
  17.188 +   #define PR_WL__record_interval_end_in_probe( probeID )  /* do nothing */
  17.189 +   #define PR_WL__print_stats_of_probe( probeID ) ; /* do nothing */
  17.190 +   #define PR_WL__print_stats_of_all_probes() ;/* do nothing */
  17.191 +
  17.192 +#endif   /* defined PROBES__TURN_ON_STATS_PROBES */
  17.193 +
  17.194 +#endif	/* _PROBES_H */
  17.195 +
    18.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    18.2 +++ b/Services_offered_by_PR/Memory_Handling/vmalloc__structs.h	Fri Jul 26 12:12:34 2013 -0700
    18.3 @@ -0,0 +1,89 @@
    18.4 +/*
    18.5 + *  Copyright 2009 OpenSourceCodeStewardshipFoundation.org
    18.6 + *  Licensed under GNU General Public License version 2
    18.7 + *
    18.8 + * Author: seanhalle@yahoo.com
    18.9 + *
   18.10 + * Created on November 14, 2009, 9:07 PM
   18.11 + */
   18.12 +
   18.13 +#ifndef _VMALLOC_structs_H
   18.14 +#define	_VMALLOC_structs_H
   18.15 +
   18.16 +#include <malloc.h>
   18.17 +#include <inttypes.h>
   18.18 +#include "PR__common_includes/PR__primitive_data_types.h"
   18.19 +
   18.20 +#define SMALL_CHUNK_SIZE 32
   18.21 +#define SMALL_CHUNK_COUNT 4
   18.22 +#define LOWER_BOUND     128  //Biggest chunk size that is created for the small chunks
   18.23 +#define BIG_LOWER_BOUND 160  //Smallest chunk size that is created for the big chunks
   18.24 +
   18.25 +#define LOG54 0.3219280948873623
   18.26 +#define LOG128 7
   18.27 +
   18.28 +typedef struct _MallocProlog MallocProlog;
   18.29 +
   18.30 +struct _MallocProlog
   18.31 + {
   18.32 +   MallocProlog *nextChunkInFreeList;
   18.33 +   MallocProlog *prevChunkInFreeList;
   18.34 +   MallocProlog *nextHigherInMem;
   18.35 +   MallocProlog *nextLowerInMem;
   18.36 + };
   18.37 +//MallocProlog
   18.38 + 
   18.39 + typedef struct MallocArrays MallocArrays;
   18.40 +
   18.41 + struct MallocArrays
   18.42 + {
   18.43 +     MallocProlog **smallChunks;
   18.44 +     MallocProlog **bigChunks;
   18.45 +     uint64       bigChunksSearchVector[2];
   18.46 +     void         *memSpace;
   18.47 +     uint32       containerCount;
   18.48 + };
   18.49 + //MallocArrays
   18.50 +
   18.51 +typedef struct
   18.52 + {
   18.53 +   MallocProlog *firstChunkInFreeList;
   18.54 +   int32         numInList; //TODO not used
   18.55 + }
   18.56 +FreeListHead;
   18.57 +
   18.58 +void *
   18.59 +PR_int__malloc( size_t sizeRequested );
   18.60 +
   18.61 +void *
   18.62 +PR_WL__malloc( int32  sizeRequested ); /*BUG: -- get master lock */
   18.63 +
   18.64 +void *
   18.65 +PR_int__malloc_aligned( size_t sizeRequested );
   18.66 +
   18.67 +void
   18.68 +PR_int__free( void *ptrToFree );
   18.69 +
   18.70 +void
   18.71 +PR_WL__free( void *ptrToFree );
   18.72 +
   18.73 +
   18.74 +
   18.75 +/*Allocates memory from the external system -- higher overhead
   18.76 + */
   18.77 +void *
   18.78 +PR_ext__malloc_in_ext( size_t sizeRequested );
   18.79 +
   18.80 +/*Frees memory that was allocated in the external system -- higher overhead
   18.81 + */
   18.82 +void
   18.83 +PR_ext__free_in_ext( void *ptrToFree );
   18.84 +
   18.85 +
   18.86 +MallocArrays *
   18.87 +PR_ext__create_free_list();
   18.88 +
   18.89 +void
   18.90 +PR_ext__free_free_list(MallocArrays *freeLists );
   18.91 +
   18.92 +#endif
   18.93 \ No newline at end of file
    19.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    19.2 +++ b/Services_offered_by_PR/Memory_Handling/vmalloc__wrapper_library.h	Fri Jul 26 12:12:34 2013 -0700
    19.3 @@ -0,0 +1,28 @@
    19.4 +/*
    19.5 + *  Copyright 2009 OpenSourceCodeStewardshipFoundation.org
    19.6 + *  Licensed under GNU General Public License version 2
    19.7 + *
    19.8 + * Author: seanhalle@yahoo.com
    19.9 + *
   19.10 + * Created on November 14, 2009, 9:07 PM
   19.11 + */
   19.12 +
   19.13 +#ifndef _VMALLOC_wrapper_library_H
   19.14 +#define	_VMALLOC_wrapper_library_H
   19.15 +
   19.16 +/*Can call PR__malloc and PR__free  from the main thread or from wrapper
   19.17 + * library code, or other library, after PR__start()  has been called
   19.18 + */
   19.19 +
   19.20 +
   19.21 +void *
   19.22 +PR_WL__malloc( int32  sizeRequested ); 
   19.23 +
   19.24 +void
   19.25 +PR_WL__free( void *ptrToFree );
   19.26 +
   19.27 +#define PR__malloc PR_WL__malloc
   19.28 +#define PR__free   PR_WL__free
   19.29 +
   19.30 +
   19.31 +#endif
   19.32 \ No newline at end of file