# HG changeset patch # User Sean Halle # Date 1374260974 25200 # Node ID e2db79e4814479c2b640159cef6c689c120c644a initial add -- into Dev_libs branch -- just junk copied -- will cut down diff -r 000000000000 -r e2db79e48144 Defines/MEAS__macros_to_be_moved_to_langs.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Defines/MEAS__macros_to_be_moved_to_langs.h Fri Jul 19 12:09:34 2013 -0700 @@ -0,0 +1,64 @@ +/* + * Copyright 2009 OpenSourceResearchInstitute.org + * Licensed under GNU General Public License version 2 + * + * Author: seanhalle@yahoo.com + * + */ + +#ifndef _PR_LANG_SPEC_DEFS_H +#define _PR_LANG_SPEC_DEFS_H + + + +//=================== Language-specific Measurement Stuff =================== +// +//TODO: move these into the language implementation directories +// + + +//=========================================================================== +//VCilk + +#ifdef VCILK + +/*These defines are used in the macros below*/ +#define spawnHistIdx 1 //note: starts at 1 +#define syncHistIdx 2 + +#define MEAS__Make_Meas_Hists_for_VCilk( slave, magicNum ) \ + do \ + { VCilkLangEnv * \ + langEnv = PR_PI__get_lang_env_from_slave( slave, magicNum ); \ + langEnv->measHistsInfo = \ + makePrivDynArrayOfSize( (void***)&(_PRTopEnv->measHists), 200); \ + histInfo = langEnv->measHistsInfo; + makeAMeasHist( histInfo, spawnHistIdx, "Spawn", 50, 0, 200 ) \ + makeAMeasHist( histInfo, syncHistIdx, "Sync", 50, 0, 200 ) \ + }while(FALSE); /* macro magic to protect local vars from name collision */ + +#define Meas_startSpawn fixme; /* changed names -- added __Cilk to end*/ + +#define Meas_startSpawn__Cilk \ + int32 startStamp, endStamp; \ + saveLowTimeStampCountInto( startStamp ); \ + +#define Meas_endSpawn__Cilk \ + saveLowTimeStampCountInto( endStamp ); \ + addIntervalToHist( startStamp, endStamp, \ + _PRTopEnv->measHists[ spawnHistIdx ] ); + +#define Meas_startSync__Cilk \ + int32 startStamp, endStamp; \ + saveLowTimeStampCountInto( startStamp ); \ + +#define Meas_endSync__Cilk \ + saveLowTimeStampCountInto( endStamp ); \ + addIntervalToHist( startStamp, endStamp, \ + _PRTopEnv->measHists[ syncHistIdx ] ); +#endif + +//=========================================================================== + +#endif /* _PR_DEFS_H */ + diff -r 000000000000 -r e2db79e48144 Defines/PR_defs.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Defines/PR_defs.h Fri Jul 19 12:09:34 2013 -0700 @@ -0,0 +1,43 @@ +/* + * Copyright 2009 OpenSourceResearchInstitute.org + * Licensed under GNU General Public License version 2 + * + * Author: seanhalle@yahoo.com + * + */ + +#ifndef _PR_DEFS_MAIN_H +#define _PR_DEFS_MAIN_H +#define _GNU_SOURCE + +//=========================== PR-wide defs =============================== + +#define SUCCESS 0 + + //only after macro-expansion are the defs of writePrivQ, aso looked up + // so these defs can be at the top, and writePrivQ defined later on.. +#define writePRQ writePrivQ +#define readPRQ readPrivQ +#define makePRQ makePrivQ +#define numInPRQ numInPrivQ +#define PRQueueStruc PrivQueueStruc + + +/*The language should re-define this, but need a default in case it doesn't*/ +#ifndef _LANG_NAME_ +#define _LANG_NAME_ "" +#endif + +//====================== Hardware Constants ============================ +#include "PR_defs__HW_constants.h" + +//====================== Macros ====================== + //for turning macros and other PR features on and off +#include "PR_defs__turn_on_and_off.h" + +#include "../Services_Offered_by_PR/Debugging/DEBUG__macros.h" +#include "../Services_Offered_by_PR/Measurement_and_Stats/MEAS__macros.h" + +//=========================================================================== +#endif /* */ + diff -r 000000000000 -r e2db79e48144 Defines/PR_defs__HW_constants.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Defines/PR_defs__HW_constants.h Fri Jul 19 12:09:34 2013 -0700 @@ -0,0 +1,67 @@ +/* + * Copyright 2012 OpenSourceResearchInstitute + * Licensed under BSD + * + * Author: seanhalle@yahoo.com + * + */ + +#ifndef _PR_HW_SPEC_DEFS_H +#define _PR_HW_SPEC_DEFS_H +#define _GNU_SOURCE + + +//========================= Hardware related Constants ===================== + //This value is the number of hardware threads in the shared memory + // machine +#define NUM_CORES 4 + //Now, check if sequential mode is on, and set num cores to 1, so that + // lang plugin code doesn't have to check for sequential mode +#ifdef DEBUG__TURN_ON_SEQUENTIAL_MODE + #undef NUM_CORES + #define NUM_CORES 1 +#endif + + + //tradeoff amortizing master fixed overhead vs imbalance potential + // when work-stealing, can make bigger, at risk of losing cache affinity +#define NUM_ANIM_SLOTS 1 + + //number of PRLangEnv structs created inside a process -- can't start more + // than this many langlets inside a single process +#define NUM_IN_COLLECTION 64 + + //These are for backoff inside core-loop, which reduces lock contention +#define NUM_REPS_W_NO_WORK_BEFORE_YIELD 10 +#define NUM_REPS_W_NO_WORK_BEFORE_BACKOFF 2 +#define MASTERLOCK_RETRIES_BEFORE_YIELD 100 +#define NUM_TRIES_BEFORE_DO_BACKOFF 10 +#define GET_LOCK_BACKOFF_WEIGHT 100 + + // stack size in virtual processors created +#define VIRT_PROCR_STACK_SIZE 0x8000 /* 32K */ + + // memory for PR_int__malloc +#define MALLOC_ADDITIONAL_MEM_FROM_OS_SIZE 0x8000000 /* 128M */ + + //Frequency of TS counts -- have to do tests to verify + //NOTE: turn off (in BIOS) TURBO-BOOST and SPEED-STEP else won't be const +#define TSCOUNT_FREQ 3180000000 +#define TSC_LOW_CYCLES 27 +#define TSC_LOWHI_CYCLES 45 + +#define CACHE_LINE_SZ 256 +#define PAGE_SIZE 4096 + +//To prevent false-sharing, aligns a variable to a cache-line boundary. +//No need to use for local vars because those are never shared between cores +#define __align_to_cacheline__ __attribute__ ((aligned(CACHE_LINE_SZ))) + +//aligns a pointer to cacheline. The memory area has to contain at least +//CACHE_LINE_SZ bytes more then needed +#define __align_address(ptr) ((void*)(((uintptr_t)(ptr))&((uintptr_t)(~0x0FF)))) + +//=========================================================================== + +#endif /* _PR_DEFS_H */ + diff -r 000000000000 -r e2db79e48144 PR.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PR.h Fri Jul 19 12:09:34 2013 -0700 @@ -0,0 +1,100 @@ +/* + * Copyright 2012 OpenSourceResearchInstitute.org + * Licensed under GNU General Public License version 2 + * + * Author: seanhalle@yahoo.com + * + */ + +#ifndef _PR_H +#define _PR_H +#define _GNU_SOURCE + +#include "DynArray/DynArray.h" +#include "Hash_impl/PrivateHash.h" +#include "Histogram/Histogram.h" +#include "Queue_impl/PrivateQueue.h" + +#include "PR_primitive_data_types.h" +#include "Services_Offered_by_PR/Memory_Handling/vmalloc.h" + +#include +#include + +//================= Defines: included from separate files ================= +// +// Note: ALL defines are in other files, none are in here +// +#include "Defines/PR_defs.h" + + +//================================ Typedefs ================================= +// +#include "PR__structs.h" + +//============================ HW Dependent Fns ================================ + +#include "HW_Dependent_Primitives/PR__HW_measurement.h" +#include "HW_Dependent_Primitives/PR__primitives.h" + + +//============================= Global Vars ================================ + +volatile TopEnv *_PRTopEnv __align_to_cacheline__; + + //these are global, but only used for startup and shutdown +pthread_t coreCtlrThdHandles[ NUM_CORES ]; //pthread's virt-procr state +ThdParams *coreCtlrThdParams [ NUM_CORES ]; + +pthread_mutex_t suspendLock; +pthread_cond_t suspendCond; + +//========================= Function Prototypes =========================== +/* MEANING OF WL PI SS int PROS + * These indicate which places the function is safe to use. They stand for: + * + * WL Wrapper Library -- wrapper lib code should only use these + * PI Plugin -- plugin code should only use these + * SS Startup and Shutdown -- designates these relate to startup & shutdown + * int32internal to PR -- should not be used in wrapper lib or plugin + * PROS means "OS functions for applications to use" + * + * PR_int__ functions touch internal PR data structs and are only safe + * to be used inside the master lock. However, occasionally, they appear + * in wrapper-lib or plugin code. In those cases, very careful analysis + * has been done to be sure no concurrency issues could arise. + * + * PR_WL__ functions are all safe for use outside the master lock. + * + * PR_OS are only safe for applications to use -- they're like a second + * language mixed in -- but they can't be used inside plugin code, and + * aren't meant for use in wrapper libraries, because they are themselves + * wrapper-library calls! + */ + +inline bool32 masterFunction( AnimSlot *slot ); + +//============== include internally used fn prototypes ================ + +//include fn prototypes used internally in the proto-runtime implementation +#include "PR__int.h" + +//include fn prototypes used by plugin +#include "PR__PI.h" + +//include fn prototype used by wrapper library +#include "PR__WL.h" + +//================================= +#define implement_me() printf("Unimpl Fn: \n%s \n%s : %d\n", __FILE__, __FUNCTION__, __LINE__) +//#define fix_me printf("Fix me at: \n%s \n%s : %s\n", __FILE__, __FUNCTION__, __LINE__) + + +//========================= Services ======================= +#include "Services_Offered_by_PR/Measurement_and_Stats/probes.h" +#include "Services_Offered_by_PR/Services_Language/PRServ.h" +//#include "Services_Offered_by_PR/Services_Language/libPRServ.h" + +//================================================ +#endif /* _PR_H */ + diff -r 000000000000 -r e2db79e48144 PR__PI.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PR__PI.h Fri Jul 19 12:09:34 2013 -0700 @@ -0,0 +1,195 @@ +/* + * Copyright 2009 OpenSourceResearchInstitute.org + * Licensed under GNU General Public License version 2 + * + * Author: seanhalle@yahoo.com + * + */ + +#ifndef _PR__PI_H +#define _PR__PI_H +#define _GNU_SOURCE + + +#include "PR_primitive_data_types.h" + +//========================= Function Prototypes =========================== +/* MEANING OF WL PI SS int PROS + * These indicate which places the function is safe to use. They stand for: + * + * WL Wrapper Library -- wrapper lib code should only use these + * PI Plugin -- plugin code should only use these + * SS Startup and Shutdown -- designates these relate to startup & shutdown + * int32internal to PR -- should not be used in wrapper lib or plugin + * PROS means "OS functions for applications to use" + * + * PR_int__ functions touch internal PR data structs and are only safe + * to be used inside the master lock. However, occasionally, they appear + * in wrapper-lib or plugin code. In those cases, very careful analysis + * has been done to be sure no concurrency issues could arise. + * + * PR_WL__ functions are all safe for use outside the master lock. + * + * PROS are only safe for applications to use -- they're like a second + * language mixed in -- but they can't be used inside plugin code, and + * aren't meant for use in wrapper libraries, because they are themselves + * wrapper-library calls! + */ + +#define \ +PR_PI__create_slaveVP PR_int__create_slaveVP_helper + +//============== +//=== Lang Data +//= +#define \ +PR_PI__give_lang_data_from_slave PR_int__give_lang_data_from_slave +#define \ +PR_SS__give_lang_data_from_slave PR_int__give_lang_data_from_slave + + +//============ +//=== Lang Env +//= +#define \ +PR_PI__give_proto_lang_env_for_slave PR_int__give_proto_lang_env_for_slave +#define \ +PR_PI__give_lang_env_for_slave PR_int__give_lang_env_for_slave +#define \ +PR_PI__give_lang_env_from_process PR_int__give_lang_env_from_process + + +//========= +//=== Meta Task +//= +#define \ +PR_PI__give_lang_meta_task_from_slave PR_int__give_lang_meta_task_from_slave +#define \ +PR_PI__give_prolog_of_lang_meta_task PR_int__give_prolog_of_lang_meta_task + +SlaveVP * +PR_PI__give_slave_lang_meta_task_is_assigned_to( void *langMetaTask ); + +#define \ +PR_PI__free_lang_meta_task_and_remove_from_slave PR_int__free_lang_meta_task_and_remove_from_coll + +#define \ +PR_PI__free_lang_meta_task PR_int__free_lang_meta_task + +void +PR_PI__set_no_del_flag_in_lang_meta_task( void *langMetaTask ); +void +PR_PI__clear_no_del_flag_in_lang_meta_task( void *langMetaTask ); + +//========== +//=== +//= +#define \ +PR_PI__give_ID_from_lang_meta_task PR__give_ID_from_lang_meta_task +#define \ +PR_PI__give_ID_from_slave PR__give_ID_from_slave + +//============= +//=== +//= +#define \ +PR_PI__put_slave_into_slot PR_int__put_slave_into_slot +#define \ +PR_PI__put_task_into_slot PR_int__put_task_into_slot + +PRReqst * +PR_PI__take_next_request_out_of( SlaveVP *slaveWithReq ); + +#define \ +PR_PI__take_lang_reqst_from( req ) req->langReq + +void +PR_PI__resume_slave_in_PRServ( SlaveVP *slave ); + +#define \ +PR_PI__malloc PR_int__malloc +#define \ +PR_PI__malloc_aligned PR_int__malloc_aligned +#define \ +PR_PI__free PR_int__free + + +#define \ +PR_PI__throw_exception PR_int__throw_exception + +//=============== Startup and Shutdown ================ +//=== +//= +void +PR_SS__create_topEnv(); + +AnimSlot ** +PR_SS__create_anim_slots( int32 coreSlotsAreOn ); + +void +PR_SS__create_the_coreCtlr_OS_threads(); + +//=================== +void * +PR_SS__create_lang_env( int32 size, SlaveVP *slave, int32 magicNum ); + +void +PR_SS__register_assigner( SlaveAssigner assigner, SlaveVP *seedVP, int32 magicNum ); +void +PR_SS__register_lang_shutdown_handler( LangShutdownHdlr shutdownHdlr, SlaveVP *seedVP, + int32 magicNum ); +void +PR_SS__register_lang_data_creator( LangDataCreator langDataCreator, + SlaveVP *seedVP, int32 magicNum ); +void +PR_SS__register_lang_meta_task_creator( LangDataCreator langMetaTaskCreator, + SlaveVP *seedVP, int32 magicNum ); +void +PR_SS__register_make_slave_ready_fn( MakeSlaveReadyFn fn, SlaveVP *seedVP, + int32 magicNum ); +void +PR_SS__register_make_task_ready_fn( MakeTaskReadyFn fn, SlaveVP *seedVP, + int32 magicNum ); +//=================== + +void +PR_SS__end_process_normally( PRProcess *process ); + +void +PR_SS__shutdown_OS_threads(); + +SlaveVP* +PR_SS__create_shutdown_slave(); + +void +PR_SS__cleanup_at_end_of_shutdown(); + +void +PR_SS__print_out_measurements(); + +void +PR_SS__wait_for_PR_to_shutdown(); + + +//============================= +//=== +//= + +#define \ +PR_SS__give_proto_lang_env_for_slave PR_int__give_proto_lang_env_for_slave + +#define \ +PR_SS__give_lang_meta_task_from_slave PR_int__give_lang_meta_task_from_slave +#define \ +PR_SS__give_lang_env_for_slave PR_int__give_lang_env_for_slave +#define \ +PR_SS__give_lang_env_from_process PR_int__give_lang_env_from_process + +#define \ +PR_SS__malloc PR_WL__malloc /*SS happens outside the Master*/ +#define \ +PR_SS__free PR_WL__free + +//================================================ +#endif /* _PR__PI_H */ + diff -r 000000000000 -r e2db79e48144 PR__WL.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PR__WL.h Fri Jul 19 12:09:34 2013 -0700 @@ -0,0 +1,148 @@ +/* + * Copyright 2009 OpenSourceResearchInstitute.org + * Licensed under GNU General Public License version 2 + * + * Author: seanhalle@yahoo.com + * + */ + +#ifndef _PR__WL_H +#define _PR__WL_H +#define _GNU_SOURCE + +#include "PR_primitive_data_types.h" +#include "PR__structs.h" +//========================= Function Prototypes =========================== +/* MEANING OF WL PI SS int PROS + * These indicate which places the function is safe to use. They stand for: + * + * WL Wrapper Library -- wrapper lib code should only use these + * PI Plugin -- plugin code should only use these + * SS Startup and Shutdown -- designates these relate to startup & shutdown + * int32internal to PR -- should not be used in wrapper lib or plugin + * PROS means "OS functions for applications to use" + * + * PR_int__ functions touch internal PR data structs and are only safe + * to be used inside the master lock. However, occasionally, they appear + * in wrapper-lib or plugin code. In those cases, very careful analysis + * has been done to be sure no concurrency issues could arise. + * + * PR_WL__ functions are all safe for use outside the master lock. + * + * PROS are only safe for applications to use -- they're like a second + * language mixed in -- but they can't be used inside plugin code, and + * aren't meant for use in wrapper libraries, because they are themselves + * wrapper-library calls! + */ + +//============== Top level Fns called from main =============== +void +PR__start(); + +PRProcess * +PR__create_process( BirthFnPtr seed_Fn, void *seedData ); + +void +PR__end_seedVP( SlaveVP *seedSlv ); + +void +PR__end_process_from_inside( SlaveVP *seedSlv ); + +void * +PR__give_results_from_process_when_ready( PRProcess *process ); + +void +PR__wait_for_process_to_end( PRProcess *process ); + +void +PR__wait_for_all_activity_to_end(); + +void +PR__shutdown(); + +#define \ +PR__create_taskID_of_size PR_WL__create_taskID_of_size + +inline +int32 * +PR__give_ID_from_slave( SlaveVP *animSlv, int32 magicNumber ); + +inline +int32 * +PR__give_ID_from_lang_meta_task( void *_task ); + +#define \ +PR__malloc PR_WL__malloc + +#define \ +PR__free PR_WL__free + + + +//============== include internally used fn prototypes ================ +#include "PR__int.h" + + +#define \ +PR_WL__create_slaveVP PR_int__create_slaveVP_helper + +#define \ +PR_WL__give_lang_meta_task_from_slave PR_int__give_lang_meta_task_from_slave + +#define \ +PR_WL__give_prolog_of_lang_meta_task PR_int__give_prolog_of_lang_meta_task + +//============== Request Related =============== + +void +PR_WL__suspend_slaveVP_and_send_req( SlaveVP *callingSlv ); + +inline void +PR_WL__add_lang_request_in_mallocd_PRReqst( void *langReqData, + SlaveVP *callingSlv ); + +inline void +PR_WL__send_lang_request( void *langReq, RequestHandler handler, + SlaveVP *callingSlv, int32 magicNum ); + +void +PR_WL__send_create_slaveVP_req( void *langReq, int32 *ID, CreateHandler handler, + SlaveVP *reqstingSlv, int32 magicNum ); + +void inline +PR_WL__send_end_slave_req( void *langReq, RequestHandler handler, + SlaveVP *slvToDissipate, int32 magicNum ); + +inline void +PR_WL__send_service_request( void *langReqData, SlaveVP *callingSlv ); + +inline void +PR_WL__send_lang_shutdown_request( SlaveVP *callingSlv, int32 magicNum ); + +inline +int32 * +PR_WL__create_taskID_of_size( int32 numInts ); + +//======================== MEASUREMENT ====================== +uint64 +PR_WL__give_num_plugin_cycles(); +uint32 +PR_WL__give_num_plugin_animations(); + + +//========================= Utilities ======================= +void +PR_WL__throw_exception( char *msgStr, SlaveVP *reqstSlv, PRExcp *excpData ); +#define PR_App__throw_exception PR_WL__throw_exception + + +//======================================================================= + +//========================= Services ======================= +//#include "Services_Offered_by_PR/Measurement_and_Stats/probes.h" +//#include "Services_Offered_by_PR/Services_Language/PRServ.h" +//#include "Services_Offered_by_PR/Services_Language/libPRServ.h" + +//================================================ +#endif /* _PR_H */ + diff -r 000000000000 -r e2db79e48144 PR__common.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PR__common.h Fri Jul 19 12:09:34 2013 -0700 @@ -0,0 +1,100 @@ +/* + * Copyright 2012 OpenSourceResearchInstitute.org + * Licensed under GNU General Public License version 2 + * + * Author: seanhalle@yahoo.com + * + */ + +#ifndef _PR_H +#define _PR_H +#define _GNU_SOURCE + +#include "DynArray/DynArray.h" +#include "Hash_impl/PrivateHash.h" +#include "Histogram/Histogram.h" +#include "Queue_impl/PrivateQueue.h" + +#include "PR_primitive_data_types.h" +#include "Services_Offered_by_PR/Memory_Handling/vmalloc.h" + +#include +#include + +//================= Defines: included from separate files ================= +// +// Note: ALL defines are in other files, none are in here +// +#include "Defines/PR_defs.h" + + +//================================ Typedefs ================================= +// +#include "PR__structs.h" + +//============================ HW Dependent Fns ================================ + +#include "HW_Dependent_Primitives/PR__HW_measurement.h" +#include "HW_Dependent_Primitives/PR__primitives.h" + + +//============================= Global Vars ================================ + +volatile TopEnv *_PRTopEnv __align_to_cacheline__; + + //these are global, but only used for startup and shutdown +pthread_t coreCtlrThdHandles[ NUM_CORES ]; //pthread's virt-procr state +ThdParams *coreCtlrThdParams [ NUM_CORES ]; + +pthread_mutex_t suspendLock; +pthread_cond_t suspendCond; + +//========================= Function Prototypes =========================== +/* MEANING OF WL PI SS int PROS + * These indicate which places the function is safe to use. They stand for: + * + * WL Wrapper Library -- wrapper lib code should only use these + * PI Plugin -- plugin code should only use these + * SS Startup and Shutdown -- designates these relate to startup & shutdown + * int32internal to PR -- should not be used in wrapper lib or plugin + * PROS means "OS functions for applications to use" + * + * PR_int__ functions touch internal PR data structs and are only safe + * to be used inside the master lock. However, occasionally, they appear + * in wrapper-lib or plugin code. In those cases, very careful analysis + * has been done to be sure no concurrency issues could arise. + * + * PR_WL__ functions are all safe for use outside the master lock. + * + * PR_OS are only safe for applications to use -- they're like a second + * language mixed in -- but they can't be used inside plugin code, and + * aren't meant for use in wrapper libraries, because they are themselves + * wrapper-library calls! + */ + +inline bool32 masterFunction( AnimSlot *slot ); + +//============== include internally used fn prototypes ================ + +//include fn prototypes used internally in the proto-runtime implementation +#include "PR__int.h" + +//include fn prototypes used by plugin +#include "PR__PI.h" + +//include fn prototype used by wrapper library +#include "PR__WL.h" + +//================================= +#define implement_me() printf("Unimpl Fn: \n%s \n%s : %d\n", __FILE__, __FUNCTION__, __LINE__) +//#define fix_me printf("Fix me at: \n%s \n%s : %s\n", __FILE__, __FUNCTION__, __LINE__) + + +//========================= Services ======================= +#include "Services_Offered_by_PR/Measurement_and_Stats/probes.h" +#include "Services_Offered_by_PR/Services_Language/PRServ.h" +//#include "Services_Offered_by_PR/Services_Language/libPRServ.h" + +//================================================ +#endif /* _PR_H */ + diff -r 000000000000 -r e2db79e48144 PR__common_structs.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PR__common_structs.h Fri Jul 19 12:09:34 2013 -0700 @@ -0,0 +1,432 @@ +/* + * Copyright 2009 OpenSourceResearchInstitute.org + * Licensed under GNU General Public License version 2 + * + * Author: seanhalle@yahoo.com + * + */ + +#ifndef _PR__structs_H +#define _PR__structs_H +#define _GNU_SOURCE + +#include "PR_primitive_data_types.h" + +#include +#include + + +//================================ Typedefs ================================= +//=== +//= +#define ZERO 0 + +typedef unsigned long long TSCount; + +typedef struct _AnimSlot AnimSlot; +typedef struct _PRReqst PRReqst; +typedef struct _SlaveVP SlaveVP; +typedef struct _MasterVP MasterVP; +typedef struct _IntervalProbe IntervalProbe; +typedef struct _PRLangEnv PRLangEnv; //a prolog +typedef struct _PRMetaTask PRMetaTask; //a prolog +typedef struct _PRLangData PRLangData; //a prolog +typedef struct _PRCollElem PRCollElem; //generic form of the prologs + +typedef bool32 (*SlaveAssigner) ( void *, AnimSlot* ); //langEnv, slot for HW info +typedef void (*RequestHandler) ( void *, SlaveVP *, void * ); //req, slv, langEnv +typedef void *(*CreateHandler) ( void *, SlaveVP *, void * ); //req, slv, langEnv +typedef void (*LangShutdownHdlr) ( void * ); //langEnv +typedef void *(*LangDataCreator) ( SlaveVP * ); +typedef void (*LangDataFreer) ( void * ); //lang data to free +typedef void *(*LangMetaTaskCreator)( SlaveVP * ); //when slave has no meta task for magic num +typedef void (*LangMetaTaskFreer) ( void * ); //lang meta task to free +typedef void (*MakeSlaveReadyFn) ( SlaveVP *, void * ); //slave and langEnv +typedef void (*MakeTaskReadyFn) ( void *, void * ); //langTask and langEnv +typedef void (*BirthFnPtr) ( void *, SlaveVP * ); //initData, animSlv +typedef void BirthFn ( void *, SlaveVP * ); //initData, animSlv +typedef void (*ResumeSlvFnPtr) ( SlaveVP *, void * ); + //=========== MEASUREMENT STUFF ========== + MEAS__Insert_Counter_Handler + //======================================== + +//============================ HW Dependent Fns ================================ + +#include "HW_Dependent_Primitives/PR__HW_measurement.h" +#include "HW_Dependent_Primitives/PR__primitives.h" + + +typedef struct + { //These are set by the plugin during startup and the application + char *assignerInfo; + char *appInfo; + char *inputInfo; + } +PRSysMetaInfo; + +//===================== Process Data Struct ====================== + +/*This structure holds all the information PR needs to manage a program. PR + * stores information about what percent of CPU time the program is getting, + * + */ +typedef struct + { + int32 numEnvsWithWork; + void *resultToReturn; + + PRLangEnv **langEnvs; //used as a hash table + PRLangEnv **protoLangEnvsList; //for fast linear scan of envs + int32 numLangEnvs; //for fast linear scan of envs + + SlaveVP *seedSlv; + + int32 numLiveGenericSlvs; + int32 numLiveTasks; + + SlaveAssigner overrideAssigner; + + + + //These are used to coord with an OS thread waiting for process to end + bool32 hasWaitingToEnd; + bool32 executionIsComplete; + pthread_mutex_t doneLock; + pthread_cond_t doneCond; + pthread_mutex_t doneAckLock; //waiter gets, then releases when done waiting + + //=========== MEASUREMENT STUFF ============= + IntervalProbe **intervalProbes; + PrivDynArrayInfo *dynIntervalProbesInfo; + HashTable *probeNameHashTbl; + int32 masterCreateProbeID; + float64 createPtInSecs; //real-clock time PR initialized + Histogram **measHists; + PrivDynArrayInfo *measHistsInfo; + MEAS__Insert_Susp_Meas_Fields_into_MasterEnv; + MEAS__Insert_Master_Meas_Fields_into_MasterEnv; + MEAS__Insert_Master_Lock_Meas_Fields_into_MasterEnv; + MEAS__Insert_Malloc_Meas_Fields_into_MasterEnv; + MEAS__Insert_Plugin_Meas_Fields_into_MasterEnv; + MEAS__Insert_System_Meas_Fields_into_MasterEnv; + MEAS__Insert_Counter_Meas_Fields_into_MasterEnv; + //========================================== + } +PRProcess; + + +//============= Request Related =========== +// + +enum PRReqstType //avoid starting enums at 0, for debug reasons + { + TaskCreate = 1, + TaskEnd, + SlvCreate, + SlvDissipate, + Language, + Service, //To invoke a PR provided equivalent of a language request (ex: probe) + Hardware, + IO, + OSCall, + LangShutdown, + ProcessEnd, + PRShutdown + }; + + +struct _PRReqst + { + enum PRReqstType reqType;//used for special forms that have PR behavior + void *langReq; + PRProcess *processReqIsIn; + int32 langMagicNumber; + SlaveVP *requestingSlave; + + BirthFnPtr topLevelFn; + void *initData; + int32 *ID; + + //The request handling structure is a bit messy.. for special forms, + // such as create and dissipate, the language inserts pointer to handler + // fn directly into the request.. might change to this for all requests + RequestHandler handler; //pointer to handler fn + CreateHandler createHdlr; //special because returns something + int32 createSuspendedGroup; //must be non-zero + + PRReqst *nextReqst; + }; +//PRReqst + +enum PRServiceReqType //These are equivalent to lang requests, but for + { // PR's services available directly to app, like OS + make_probe = 1, // and probe services -- like a PR-wide built-in lang + throw_excp, + openFile, + otherIO + }; + +typedef struct + { enum PRServiceReqType reqType; + SlaveVP *requestingSlv; + char *nameStr; //for create probe + char *msgStr; //for exception + void *exceptionData; + } +PRServiceReq; + + +//==================== Core data structures =================== + +typedef struct + { + //for future expansion + } +SlotPerfInfo; + +struct _AnimSlot + { + int32 workIsDone; + int32 needsWorkAssigned; + SlaveVP *slaveAssignedToSlot; + + int32 slotIdx; //needed by Holistic Model's data gathering + int32 coreSlotIsOn; + SlotPerfInfo *perfInfo; //used by assigner to pick best slave for core + }; +//AnimSlot + +enum VPtype + { SlotTaskSlv = 1,//Slave tied to an anim slot, only animates tasks + FreeTaskSlv, //When a suspended task ends, the slave becomes this + GenericSlv, //the VP is explicitly seen in the app code, or task suspends + SeedSlv, + Master_VP, + ShutdownVP, + IdleVP + }; + +/*This structure embodies the state of a slaveVP. It is reused for masterVP + * and shutdownVPs. + */ +struct _SlaveVP + { //The offsets of these fields are hard-coded into assembly + void *stackPtr; //save the core's stack ptr when suspend + void *framePtr; //save core's frame ptr when suspend + void *resumeInstrPtr; //save core's program-counter when suspend + void *coreCtlrFramePtr; //restore before jmp back to core controller + void *coreCtlrStackPtr; //restore before jmp back to core controller + + //============ below this, no fields are used in asm ============= + + void *startOfStack; //used to free, and to point slave to Fn + PRProcess *processSlaveIsIn; + enum VPtype typeOfVP; //Slave vs Master vs Shutdown.. + int32 slaveNum; //each slave given it's seq in creation + int32 *ID; //App defines meaning of each int in array + int32 coreAnimatedBy; + int32 numTimesAssignedToASlot; //Each assign is for one work-unit, so is an ID + //note, a scheduling decision is uniquely identified by the triple: + // -- used in record & replay + + //for comm -- between master and coreCtlr & btwn wrapper lib and plugin + AnimSlot *animSlotAssignedTo; + PRReqst *request; //wrapper lib puts in requests, plugin takes out + void *dataRetFromReq;//Return vals from plugin to Wrapper Lib + + //For language specific data that needs to be in the slave + //These are accessed directly for single-lang, but multi-lang places + // a holder here instead, then uses magic num to get lang's version + PRLangData **langDatas; //Lang saves lang-specific things in slave here + PRMetaTask **metaTasks; + + //=========== MEASUREMENT STUFF ========== + MEAS__Insert_Meas_Fields_into_Slave; + float64 createPtInSecs; //time VP created, in seconds + //======================================== + +// int8 cacheLinePad[512 - sizeof(contents)]; //for false sharing + }; +//SlaveVP + + +enum PRMode + { SingleLang = 1, + StandaloneWTasks, + MultiLang + }; + +/* The one and only global variable, holds many odds and ends + */ +typedef struct + { //The offsets of these fields are hard-coded into assembly + void *coreCtlrReturnPt; //offset to this field used in asm + int8 falseSharePad1[256 - sizeof(void*)]; + int32 masterLock; //offset to this field used in asm + int8 falseSharePad2[256 - sizeof(int32)]; + int32 wrapperLock; //offset to this field used in asm + int8 falseSharePad3[256 - sizeof(int32)]; + int32 mallocLock; //offset to this field used in asm + int8 falseSharePad4[256 - sizeof(int32)]; + //============ below this, no fields are used in asm ============= + + //Basic PR infrastructure +// enum PRMode mode; + SlaveVP **masterVPs; + AnimSlot ***allAnimSlots; + PrivQueueStruc *slaveRecycleQ; + SlaveVP *slotTaskSlvs[NUM_CORES][NUM_ANIM_SLOTS]; + SlaveVP *idleSlv[NUM_CORES][NUM_ANIM_SLOTS]; + + //Memory management related + MallocArrays *freeLists; + int32 amtOfOutstandingMem;//total currently allocated + + //Random number seeds -- random nums used in various places + uint32_t seed1; + uint32_t seed2; + + PRSysMetaInfo *metaInfo; //info about this PR system -- vers, build, etc + + //============== This only used by multi-lang mode ============ + PRProcess **processes; + int32 numProcesses; + int32 currProcessIdx; //used to choose which process gets slot + int32 firstProcessReady; //use while starting up coreCtlr + + //initialize flags for waiting for activity within PR to complete + bool32 allActivityIsDone; + pthread_mutex_t activityDoneLock; + pthread_cond_t activityDoneCond; + + SlaveAssigner overrideAssigner; + + //============== Below this is only used by single-lang mode ============== + void *protoLangEnv; + //Slave creation -- global count of slaves existing, across langs and processes + int32 numSlavesCreated; //used to give unique ID to processor + int32 numTasksCreated; //to give unique ID to a task + int32 numSlavesAlive; + + bool32 *coreIsDone; + int32 numCoresDone; + int32 shutdownInitiated; + + + //=========== MEASUREMENT STUFF ============= + IntervalProbe **intervalProbes; + PrivDynArrayInfo *dynIntervalProbesInfo; + HashTable *probeNameHashTbl; + int32 masterCreateProbeID; + float64 createPtInSecs; //real-clock time PR initialized + Histogram **measHists; + PrivDynArrayInfo *measHistsInfo; + MEAS__Insert_Susp_Meas_Fields_into_MasterEnv; + MEAS__Insert_Master_Meas_Fields_into_MasterEnv; + MEAS__Insert_Master_Lock_Meas_Fields_into_MasterEnv; + MEAS__Insert_Malloc_Meas_Fields_into_MasterEnv; + MEAS__Insert_Plugin_Meas_Fields_into_MasterEnv; + MEAS__Insert_System_Meas_Fields_into_MasterEnv; + MEAS__Insert_Counter_Meas_Fields_into_MasterEnv; + //========================================== + } +TopEnv; + + +//===================== These are prologs ==================== +//===A prolog is data immediately before pointer returned by a create function. +//= +struct _PRLangEnv + { //============== First two must match PRCollElem ============== + int32 langMagicNumber; //indexes into hash array of langEnvs in PRProcess + PRLangEnv *chainedLangEnv; //chains to langEnvs with same hash + //============================================================= + + SlaveAssigner workAssigner; + LangShutdownHdlr shutdownHdlr; //called when lang ended or process shutdown + LangDataCreator langDataCreator; + LangMetaTaskCreator langMetaTaskCreator; + MakeSlaveReadyFn makeSlaveReadyFn; + MakeTaskReadyFn makeTaskReadyFn; + + //when multi-lang, master polls lang env's to find one with work in it.. + // in single-lang case, flag ignored, master always asks lang for work + int32 hasWork; + PRProcess *processEnvIsIn; + + int32 idxInProcess; //index into array of langEnvs in the process + + int32 numReadyWork; + + int32 numLiveWork; + PrivQueueStruc *waitingForWorkToEndQ; + }; +//PRLangEnv -- this is the prolog of every lang's lang env + +enum PRTaskType + { GenericSlave = 1, + SlotTask, + FreeTask + }; + +struct _PRMetaTask + { //============== First two must match PRCollElem ============== + int32 langMagicNumber; + PRMetaTask *chainedMetaTask; + //============================================================= + enum PRTaskType taskType; + int32 *ID; //is standard PR ID + PRProcess *processTaskIsIn; + SlaveVP *slaveAssignedTo; //not valid until task animated + BirthFnPtr topLevelFn; //This is the Fn executes as the task + void *initData; //The data taken by the function + LangMetaTaskFreer freer; + bool32 goAheadAndFree; + + //NOTE: info needed for "wait" functionality is inside lang's metaTask + }; +//PRMetaTask -- prolog of every lang's meta task + +struct _PRLangData + { //============== First two must match PRCollElem ============== + int32 langMagicNumber; + PRLangData *chainedLangData; + //============================================================= + LangDataFreer freer; + bool32 goAheadAndFree; + SlaveVP *slaveAssignedTo; + }; +//PRLangData -- this is the prolog of each lang's lang data + +struct _PRCollElem + { + int32 hash; + PRCollElem *chained; + }; +//PRCollElem -- this is generic form of all the prologs + + + +//========================= Extra Stuff Data Strucs ======================= +typedef struct + { + + } +PRExcp; //exception + +//======================= OS Thread related =============================== + +void * coreController( void *paramsIn ); //standard PThreads fn prototype +void * coreCtlr_Seq( void *paramsIn ); //standard PThreads fn prototype +void animationMaster( void *initData, SlaveVP *masterVP ); + + +typedef struct + { + void *endThdPt; + unsigned int coreNum; + } +ThdParams; + +#endif /* _PR__structs_H */ + diff -r 000000000000 -r e2db79e48144 PR__int.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PR__int.h Fri Jul 19 12:09:34 2013 -0700 @@ -0,0 +1,244 @@ +/* + * Copyright 2009 OpenSourceResearchInstitute.org + * Licensed under GNU General Public License version 2 + * + * Author: seanhalle@yahoo.com + * + */ + +#ifndef _PR_INT_H +#define _PR_INT_H +#define _GNU_SOURCE + + +/* MEANING OF WL PI SS int + * These indicate which places the function is safe to use. They stand for: + * WL: Wrapper Library + * PI: Plugin + * SS: Startup and Shutdown + * int: internal to the PR implementation + */ + +inline +void +PR_int__reset_slaveVP_to_BirthFn( SlaveVP *slaveVP, BirthFnPtr fnPtr, + void *dataParam); + +inline +void +PR_int__point_slaveVP_to_OneParamFn( SlaveVP *slaveVP, void *fnPtr, + void *param); + +inline +void +PR_int__point_slaveVP_to_TwoParamFn( SlaveVP *slaveVP, void *fnPtr, + void *param1, void *param2); + +//=========================================================================== +// +//=========================================================================== +inline +SlaveVP * +PR_int__create_slaveVP_helper( BirthFnPtr fnPtr, void *dataParam ); + +inline +SlaveVP * +PR_int__create_slaveVP( BirthFnPtr fnPtr, void *dataParam, PRProcess *process ); + +SlaveVP * +PR_int__get_recycled_slot_slave( ); + +SlaveVP * +PR_int__create_slot_slave( ); + +inline +void +PR_int__replace_with_new_slot_slv( SlaveVP *slave ); + +void +idle_fn(void* data, SlaveVP *animatingSlv); + +inline +void +PR_int__put_task_into_slot( void *task, AnimSlot *slot ); + +inline +void +PR_int__put_slave_into_slot( SlaveVP *slave, AnimSlot *slot ); + +void inline +PRHandle__ServiceReq( SlaveVP *requestingSlv ); + +void +PR_int__free_slaveVP( SlaveVP *slave ); + +void +PR_int__recycle_slaveVP( SlaveVP *slave ); + +void +freeLangDataAsElem( void *elem ); + +void +freeMetaTaskAsElem( void *elem ); + + +//============================= +//=== Lange Env +//= +inline +void * +PR_int__give_lang_env( PRLangEnv *protoLangEnv ); + +inline +PRLangEnv * +PR_int__give_proto_lang_env( void *langEnv ); + +//inline +void * +PR_int__create_lang_env_in_process( int32 size, PRProcess *process, int32 magicNum ); + +inline +void * +PR_int__remove_lang_env_from_process_and_free( void *langEnv ); + +inline +void * +PR_int__give_lang_env_of_req( PRReqst *req, SlaveVP *requestingSlv ); + +inline +void * +PR_int__give_lang_env_for_slave( SlaveVP *slave, int32 magicNum ); +//No WL version -- not safe! if use env in WL, be sure data rd & wr is stable + +inline +PRLangEnv * +PR_int__give_proto_lang_env_for_slave( SlaveVP *slave, int32 magicNumber ); +//No WL version -- not safe! if use env in WL, be sure data rd & wr is stable + +inline +void * +PR_int__give_lang_env_from_process( PRProcess *process, int32 magicNum ); +//No WL version -- not safe! if use env in WL, be sure data rd & wr is stable + +inline +PRLangEnv * +PR_int__give_proto_lang_env_from_process( PRProcess *process, int32 magicNum ); + +//======================= +//=== Meta Task +//= +inline +PRMetaTask * +PR_int__give_prolog_of_lang_meta_task( void *task ); + +inline +void * +PR_int__give_lang_meta_task_of_prolog( PRMetaTask *metaTask); + +inline +void * +PR_int__create_lang_meta_task( int32 size, LangMetaTaskFreer freer, int32 magicNum ); + +inline +void * +PR_int__create_lang_meta_task_in_slave( int32 size, LangMetaTaskFreer freer, + SlaveVP *slave, int32 magicNum ); + +inline +PRMetaTask * +PR_int__create_generic_slave_meta_task( void *initData ); + +void +PR_int__free_lang_meta_task_and_remove_from_coll( void *langMetaTask ); + +inline +void +PR_int__insert_meta_task_into_slave( PRMetaTask *task, SlaveVP *slave ); + +inline +void +PR_int__insert_lang_meta_task_into_slave__ML( void *langMetaTask, SlaveVP *slave ); + +inline +void * +PR_int__give_lang_meta_task_from_slave( SlaveVP *slave, int32 magicNumer ); + +inline +SlaveVP * +PR_PI__give_slave_lang_meta_task_is_assigned_to( void *langMetaTask ); + +//============== +//=== Lang Data +//= +inline +void * +PR_PI__create_lang_data_in_slave( int32 size, LangDataFreer freer, + SlaveVP *slave, int32 magicNum ); + +inline +void * +PR_int__give_lang_data_from_slave( SlaveVP *slave, int32 magicNumer ); +#define PR_WL__give_lang_data PR_int__give_lang_data_from_slave + +inline +void * +PR_int__give_lang_data_of_prolog( PRLangData *langData); + +//================================================== +//=== Collection +//= +PRCollElem ** //return an array of pointers +PR_int__make_collection_of_size( int32 numInColl ); + +inline +void +PR_int__insert_elem_into_collection( PRCollElem *elem, PRCollElem **coll, int32 hash ); + +inline +void * +PR_int__lookup_elem_in_collection( int32 hash, PRCollElem **coll ); + +inline +void +PR_int__remove_elem_from_collection( int32 hash, PRCollElem **coll ); + +inline +void +PR_int__set_collection_to_empty( PRCollElem **coll ); + +inline +void +PR_int__apply_Fn_to_all_in_collection( void (*Fn)(void *), PRCollElem **coll ); + +//=========== +//=== +//= +void +PR_int__error( char *msgStr ); + +void +PR_int__throw_exception( char *msgStr, SlaveVP *reqstSlv, PRExcp *excpData ); + +char * +PR_int__strDup( char *str ); + +inline void +PR_int__get_wrapper_lock(); + +inline void +PR_int__get_malloc_lock(); + +#define PR_int__release_master_lock() _PRTopEnv->masterLock = UNLOCKED + +#define PR_int__release_wrapper_lock() _PRTopEnv->wrapperLock = UNLOCKED + +#define PR_int__release_malloc_lock() _PRTopEnv->mallocLock = UNLOCKED + +inline uint32_t +PR_int__randomNumber(); + +inline void +PR_int__backoff_for_TooLongToGetLock( int32 numTriesToGetLock ); + +#endif /* _PR_INT_H */ + diff -r 000000000000 -r e2db79e48144 PR__primitive_data_types.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PR__primitive_data_types.h Fri Jul 19 12:09:34 2013 -0700 @@ -0,0 +1,42 @@ +/* + * Copyright 2009 OpenSourceResearchInstitute.org + * Licensed under GNU General Public License version 2 + * + * Author: seanhalle@yahoo.com + * + + */ + +#ifndef _PRIMITIVE_DATA_TYPES_H +#define _PRIMITIVE_DATA_TYPES_H + + +/*For portability, need primitive data types that have a well defined + * size, and well-defined layout into bytes + *To do this, provide standard aliases for all primitive data types + *These aliases must be used in all functions instead of the ANSI types + * + *When PR is used together with BLIS, these definitions will be replaced + * inside each specialization module according to the compiler used in + * that module and the hardware being specialized to. + */ +typedef char bool8; +typedef char int8; +typedef char uint8; +typedef short int16; +typedef unsigned short uint16; +typedef int int32; +typedef unsigned int uint32; +typedef unsigned int bool32; +typedef long long int64; +typedef unsigned long long uint64; +typedef float float32; +typedef double float64; +//typedef double double float128; //GCC doesn't like this +#define float128 double double + +#define TRUE 1 +#define FALSE 0 + +#endif /* _PRIMITIVE_DATA_TYPES_H */ + diff -r 000000000000 -r e2db79e48144 PR__primitives.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PR__primitives.h Fri Jul 19 12:09:34 2013 -0700 @@ -0,0 +1,57 @@ +/* + * Copyright 2009 OpenSourceResearchInstitute.org + * Licensed under GNU General Public License version 2 + * + * Author: seanhalle@yahoo.com + * + */ + +#ifndef _PR__PRIMITIVES_H +#define _PR__PRIMITIVES_H +#define _GNU_SOURCE + +void +recordCoreCtlrReturnLabelAddr(void **returnAddress); + +void +switchToSlv(SlaveVP *nextSlave); + +void +switchToCoreCtlr(SlaveVP *nextSlave); + +void +masterSwitchToCoreCtlr(SlaveVP *nextSlave); + +void +startUpBirthFn(); + +void +jmpToOneParamFn(); + +void +jmpToTwoParamFn(); + +void +asmTerminateCoreCtlr(SlaveVP *currSlv); +void +asmTerminateCoreCtlrSeq(SlaveVP *animatingSlv); + +#define flushRegisters() \ + asm volatile ("":::"%rbx", "%r12", "%r13","%r14","%r15") + +void +PR_int__save_return_into_ptd_to_loc_then_do_ret(void *ptdToLoc); + +void +PR_int__return_to_addr_in_ptd_to_loc(void *ptdToLoc); + +inline void +PR_int__point_slaveVP_to_OneParamFn( SlaveVP *slaveVP, void *fnPtr, + void *param); + +inline void +PR_int__point_slaveVP_to_TwoParamFn( SlaveVP *slaveVP, void *fnPtr, + void *param1, void *param2); + +#endif /* _PR__HW_DEPENDENT_H */ + diff -r 000000000000 -r e2db79e48144 PR__structs.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PR__structs.h Fri Jul 19 12:09:34 2013 -0700 @@ -0,0 +1,432 @@ +/* + * Copyright 2009 OpenSourceResearchInstitute.org + * Licensed under GNU General Public License version 2 + * + * Author: seanhalle@yahoo.com + * + */ + +#ifndef _PR__structs_H +#define _PR__structs_H +#define _GNU_SOURCE + +#include "PR_primitive_data_types.h" + +#include +#include + + +//================================ Typedefs ================================= +//=== +//= +#define ZERO 0 + +typedef unsigned long long TSCount; + +typedef struct _AnimSlot AnimSlot; +typedef struct _PRReqst PRReqst; +typedef struct _SlaveVP SlaveVP; +typedef struct _MasterVP MasterVP; +typedef struct _IntervalProbe IntervalProbe; +typedef struct _PRLangEnv PRLangEnv; //a prolog +typedef struct _PRMetaTask PRMetaTask; //a prolog +typedef struct _PRLangData PRLangData; //a prolog +typedef struct _PRCollElem PRCollElem; //generic form of the prologs + +typedef bool32 (*SlaveAssigner) ( void *, AnimSlot* ); //langEnv, slot for HW info +typedef void (*RequestHandler) ( void *, SlaveVP *, void * ); //req, slv, langEnv +typedef void *(*CreateHandler) ( void *, SlaveVP *, void * ); //req, slv, langEnv +typedef void (*LangShutdownHdlr) ( void * ); //langEnv +typedef void *(*LangDataCreator) ( SlaveVP * ); +typedef void (*LangDataFreer) ( void * ); //lang data to free +typedef void *(*LangMetaTaskCreator)( SlaveVP * ); //when slave has no meta task for magic num +typedef void (*LangMetaTaskFreer) ( void * ); //lang meta task to free +typedef void (*MakeSlaveReadyFn) ( SlaveVP *, void * ); //slave and langEnv +typedef void (*MakeTaskReadyFn) ( void *, void * ); //langTask and langEnv +typedef void (*BirthFnPtr) ( void *, SlaveVP * ); //initData, animSlv +typedef void BirthFn ( void *, SlaveVP * ); //initData, animSlv +typedef void (*ResumeSlvFnPtr) ( SlaveVP *, void * ); + //=========== MEASUREMENT STUFF ========== + MEAS__Insert_Counter_Handler + //======================================== + +//============================ HW Dependent Fns ================================ + +#include "HW_Dependent_Primitives/PR__HW_measurement.h" +#include "HW_Dependent_Primitives/PR__primitives.h" + + +typedef struct + { //These are set by the plugin during startup and the application + char *assignerInfo; + char *appInfo; + char *inputInfo; + } +PRSysMetaInfo; + +//===================== Process Data Struct ====================== + +/*This structure holds all the information PR needs to manage a program. PR + * stores information about what percent of CPU time the program is getting, + * + */ +typedef struct + { + int32 numEnvsWithWork; + void *resultToReturn; + + PRLangEnv **langEnvs; //used as a hash table + PRLangEnv **protoLangEnvsList; //for fast linear scan of envs + int32 numLangEnvs; //for fast linear scan of envs + + SlaveVP *seedSlv; + + int32 numLiveGenericSlvs; + int32 numLiveTasks; + + SlaveAssigner overrideAssigner; + + + + //These are used to coord with an OS thread waiting for process to end + bool32 hasWaitingToEnd; + bool32 executionIsComplete; + pthread_mutex_t doneLock; + pthread_cond_t doneCond; + pthread_mutex_t doneAckLock; //waiter gets, then releases when done waiting + + //=========== MEASUREMENT STUFF ============= + IntervalProbe **intervalProbes; + PrivDynArrayInfo *dynIntervalProbesInfo; + HashTable *probeNameHashTbl; + int32 masterCreateProbeID; + float64 createPtInSecs; //real-clock time PR initialized + Histogram **measHists; + PrivDynArrayInfo *measHistsInfo; + MEAS__Insert_Susp_Meas_Fields_into_MasterEnv; + MEAS__Insert_Master_Meas_Fields_into_MasterEnv; + MEAS__Insert_Master_Lock_Meas_Fields_into_MasterEnv; + MEAS__Insert_Malloc_Meas_Fields_into_MasterEnv; + MEAS__Insert_Plugin_Meas_Fields_into_MasterEnv; + MEAS__Insert_System_Meas_Fields_into_MasterEnv; + MEAS__Insert_Counter_Meas_Fields_into_MasterEnv; + //========================================== + } +PRProcess; + + +//============= Request Related =========== +// + +enum PRReqstType //avoid starting enums at 0, for debug reasons + { + TaskCreate = 1, + TaskEnd, + SlvCreate, + SlvDissipate, + Language, + Service, //To invoke a PR provided equivalent of a language request (ex: probe) + Hardware, + IO, + OSCall, + LangShutdown, + ProcessEnd, + PRShutdown + }; + + +struct _PRReqst + { + enum PRReqstType reqType;//used for special forms that have PR behavior + void *langReq; + PRProcess *processReqIsIn; + int32 langMagicNumber; + SlaveVP *requestingSlave; + + BirthFnPtr topLevelFn; + void *initData; + int32 *ID; + + //The request handling structure is a bit messy.. for special forms, + // such as create and dissipate, the language inserts pointer to handler + // fn directly into the request.. might change to this for all requests + RequestHandler handler; //pointer to handler fn + CreateHandler createHdlr; //special because returns something + int32 createSuspendedGroup; //must be non-zero + + PRReqst *nextReqst; + }; +//PRReqst + +enum PRServiceReqType //These are equivalent to lang requests, but for + { // PR's services available directly to app, like OS + make_probe = 1, // and probe services -- like a PR-wide built-in lang + throw_excp, + openFile, + otherIO + }; + +typedef struct + { enum PRServiceReqType reqType; + SlaveVP *requestingSlv; + char *nameStr; //for create probe + char *msgStr; //for exception + void *exceptionData; + } +PRServiceReq; + + +//==================== Core data structures =================== + +typedef struct + { + //for future expansion + } +SlotPerfInfo; + +struct _AnimSlot + { + int32 workIsDone; + int32 needsWorkAssigned; + SlaveVP *slaveAssignedToSlot; + + int32 slotIdx; //needed by Holistic Model's data gathering + int32 coreSlotIsOn; + SlotPerfInfo *perfInfo; //used by assigner to pick best slave for core + }; +//AnimSlot + +enum VPtype + { SlotTaskSlv = 1,//Slave tied to an anim slot, only animates tasks + FreeTaskSlv, //When a suspended task ends, the slave becomes this + GenericSlv, //the VP is explicitly seen in the app code, or task suspends + SeedSlv, + Master_VP, + ShutdownVP, + IdleVP + }; + +/*This structure embodies the state of a slaveVP. It is reused for masterVP + * and shutdownVPs. + */ +struct _SlaveVP + { //The offsets of these fields are hard-coded into assembly + void *stackPtr; //save the core's stack ptr when suspend + void *framePtr; //save core's frame ptr when suspend + void *resumeInstrPtr; //save core's program-counter when suspend + void *coreCtlrFramePtr; //restore before jmp back to core controller + void *coreCtlrStackPtr; //restore before jmp back to core controller + + //============ below this, no fields are used in asm ============= + + void *startOfStack; //used to free, and to point slave to Fn + PRProcess *processSlaveIsIn; + enum VPtype typeOfVP; //Slave vs Master vs Shutdown.. + int32 slaveNum; //each slave given it's seq in creation + int32 *ID; //App defines meaning of each int in array + int32 coreAnimatedBy; + int32 numTimesAssignedToASlot; //Each assign is for one work-unit, so is an ID + //note, a scheduling decision is uniquely identified by the triple: + // -- used in record & replay + + //for comm -- between master and coreCtlr & btwn wrapper lib and plugin + AnimSlot *animSlotAssignedTo; + PRReqst *request; //wrapper lib puts in requests, plugin takes out + void *dataRetFromReq;//Return vals from plugin to Wrapper Lib + + //For language specific data that needs to be in the slave + //These are accessed directly for single-lang, but multi-lang places + // a holder here instead, then uses magic num to get lang's version + PRLangData **langDatas; //Lang saves lang-specific things in slave here + PRMetaTask **metaTasks; + + //=========== MEASUREMENT STUFF ========== + MEAS__Insert_Meas_Fields_into_Slave; + float64 createPtInSecs; //time VP created, in seconds + //======================================== + +// int8 cacheLinePad[512 - sizeof(contents)]; //for false sharing + }; +//SlaveVP + + +enum PRMode + { SingleLang = 1, + StandaloneWTasks, + MultiLang + }; + +/* The one and only global variable, holds many odds and ends + */ +typedef struct + { //The offsets of these fields are hard-coded into assembly + void *coreCtlrReturnPt; //offset to this field used in asm + int8 falseSharePad1[256 - sizeof(void*)]; + int32 masterLock; //offset to this field used in asm + int8 falseSharePad2[256 - sizeof(int32)]; + int32 wrapperLock; //offset to this field used in asm + int8 falseSharePad3[256 - sizeof(int32)]; + int32 mallocLock; //offset to this field used in asm + int8 falseSharePad4[256 - sizeof(int32)]; + //============ below this, no fields are used in asm ============= + + //Basic PR infrastructure +// enum PRMode mode; + SlaveVP **masterVPs; + AnimSlot ***allAnimSlots; + PrivQueueStruc *slaveRecycleQ; + SlaveVP *slotTaskSlvs[NUM_CORES][NUM_ANIM_SLOTS]; + SlaveVP *idleSlv[NUM_CORES][NUM_ANIM_SLOTS]; + + //Memory management related + MallocArrays *freeLists; + int32 amtOfOutstandingMem;//total currently allocated + + //Random number seeds -- random nums used in various places + uint32_t seed1; + uint32_t seed2; + + PRSysMetaInfo *metaInfo; //info about this PR system -- vers, build, etc + + //============== This only used by multi-lang mode ============ + PRProcess **processes; + int32 numProcesses; + int32 currProcessIdx; //used to choose which process gets slot + int32 firstProcessReady; //use while starting up coreCtlr + + //initialize flags for waiting for activity within PR to complete + bool32 allActivityIsDone; + pthread_mutex_t activityDoneLock; + pthread_cond_t activityDoneCond; + + SlaveAssigner overrideAssigner; + + //============== Below this is only used by single-lang mode ============== + void *protoLangEnv; + //Slave creation -- global count of slaves existing, across langs and processes + int32 numSlavesCreated; //used to give unique ID to processor + int32 numTasksCreated; //to give unique ID to a task + int32 numSlavesAlive; + + bool32 *coreIsDone; + int32 numCoresDone; + int32 shutdownInitiated; + + + //=========== MEASUREMENT STUFF ============= + IntervalProbe **intervalProbes; + PrivDynArrayInfo *dynIntervalProbesInfo; + HashTable *probeNameHashTbl; + int32 masterCreateProbeID; + float64 createPtInSecs; //real-clock time PR initialized + Histogram **measHists; + PrivDynArrayInfo *measHistsInfo; + MEAS__Insert_Susp_Meas_Fields_into_MasterEnv; + MEAS__Insert_Master_Meas_Fields_into_MasterEnv; + MEAS__Insert_Master_Lock_Meas_Fields_into_MasterEnv; + MEAS__Insert_Malloc_Meas_Fields_into_MasterEnv; + MEAS__Insert_Plugin_Meas_Fields_into_MasterEnv; + MEAS__Insert_System_Meas_Fields_into_MasterEnv; + MEAS__Insert_Counter_Meas_Fields_into_MasterEnv; + //========================================== + } +TopEnv; + + +//===================== These are prologs ==================== +//===A prolog is data immediately before pointer returned by a create function. +//= +struct _PRLangEnv + { //============== First two must match PRCollElem ============== + int32 langMagicNumber; //indexes into hash array of langEnvs in PRProcess + PRLangEnv *chainedLangEnv; //chains to langEnvs with same hash + //============================================================= + + SlaveAssigner workAssigner; + LangShutdownHdlr shutdownHdlr; //called when lang ended or process shutdown + LangDataCreator langDataCreator; + LangMetaTaskCreator langMetaTaskCreator; + MakeSlaveReadyFn makeSlaveReadyFn; + MakeTaskReadyFn makeTaskReadyFn; + + //when multi-lang, master polls lang env's to find one with work in it.. + // in single-lang case, flag ignored, master always asks lang for work + int32 hasWork; + PRProcess *processEnvIsIn; + + int32 idxInProcess; //index into array of langEnvs in the process + + int32 numReadyWork; + + int32 numLiveWork; + PrivQueueStruc *waitingForWorkToEndQ; + }; +//PRLangEnv -- this is the prolog of every lang's lang env + +enum PRTaskType + { GenericSlave = 1, + SlotTask, + FreeTask + }; + +struct _PRMetaTask + { //============== First two must match PRCollElem ============== + int32 langMagicNumber; + PRMetaTask *chainedMetaTask; + //============================================================= + enum PRTaskType taskType; + int32 *ID; //is standard PR ID + PRProcess *processTaskIsIn; + SlaveVP *slaveAssignedTo; //not valid until task animated + BirthFnPtr topLevelFn; //This is the Fn executes as the task + void *initData; //The data taken by the function + LangMetaTaskFreer freer; + bool32 goAheadAndFree; + + //NOTE: info needed for "wait" functionality is inside lang's metaTask + }; +//PRMetaTask -- prolog of every lang's meta task + +struct _PRLangData + { //============== First two must match PRCollElem ============== + int32 langMagicNumber; + PRLangData *chainedLangData; + //============================================================= + LangDataFreer freer; + bool32 goAheadAndFree; + SlaveVP *slaveAssignedTo; + }; +//PRLangData -- this is the prolog of each lang's lang data + +struct _PRCollElem + { + int32 hash; + PRCollElem *chained; + }; +//PRCollElem -- this is generic form of all the prologs + + + +//========================= Extra Stuff Data Strucs ======================= +typedef struct + { + + } +PRExcp; //exception + +//======================= OS Thread related =============================== + +void * coreController( void *paramsIn ); //standard PThreads fn prototype +void * coreCtlr_Seq( void *paramsIn ); //standard PThreads fn prototype +void animationMaster( void *initData, SlaveVP *masterVP ); + + +typedef struct + { + void *endThdPt; + unsigned int coreNum; + } +ThdParams; + +#endif /* _PR__structs_H */ + diff -r 000000000000 -r e2db79e48144 __README_repo_purpose__.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/__README_repo_purpose__.txt Fri Jul 19 12:09:34 2013 -0700 @@ -0,0 +1,16 @@ + +This repository contains the common definitions that are used by all the other sub-directories.. + +That is, the wrapper libraries, as well as the core implementations of both PR and the language, all include the files from this directory. + +Any includes that are needed by multiple other repositories are held in this repository. + +Hence, this repo will be included with the application, along with the language's wrapper lib and PR's wrapper lib. + +This repo will also be included in the place where a given leaf-level proto-runtime library is developed, and where each upper level proto-runtime library is developed. + +And, it will be included where the language's plugin dynamic library is developed. + +So, any defines or function prototypes, or data structs that are needed in two or more of those places are included in here. + +Note that because this repo is included in the application development environment, anything in it will be visible to application code.. hence, the less it has the better. \ No newline at end of file diff -r 000000000000 -r e2db79e48144 __brch__Dev_libs__ --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/__brch__Dev_libs__ Fri Jul 19 12:09:34 2013 -0700 @@ -0,0 +1,1 @@ +This branch is for splitting up PRT and the Reo implementation into dynamic libraries