# HG changeset patch # User Philipe Louchtch # Date 1399627193 -7200 # Node ID f3cb11baf7917cf85f524bbb3c8022c71e8ff424 # Parent 45f7cf8a80eb244d03faf38800c7c726ed51525c Fully working longjmp, get_sched based. Also OS Portability work included. Related library_proto-runtime commit: 45dc6d5afb2d diff -r 45f7cf8a80eb -r f3cb11baf791 PR__PI.h --- a/PR__PI.h Tue Mar 04 12:45:08 2014 -0800 +++ b/PR__PI.h Fri May 09 11:19:53 2014 +0200 @@ -37,10 +37,16 @@ //#define PR_PI__get_fresh_slaveVP PR_int__create_slaveVP_helper -inline +__inline SlaveVP* PR_PI__get_fresh_slaveVP( BirthFnPtr fnPtr, void *dataParam, SlaveVP* requestingSlv ); +void +PR_PI__make_slave_ready( SlaveVP *slave, void *_langEnv ); + +void +PR_PI__make_task_ready(void *_task, void *_langEnv); + //============== //=== Lang Data //= @@ -111,6 +117,9 @@ void PR_PI__resume_slave_in_PRServ( SlaveVP *slave ); +void +PR_PI__set_task_properties(int32 *ID, BirthFnPtr birthFn, void *initData, void *task, SlaveVP *slave, int32 magicNum); + #define \ PR_PI__malloc PR_int__malloc #define \ diff -r 45f7cf8a80eb -r f3cb11baf791 PR__SS.h --- a/PR__SS.h Tue Mar 04 12:45:08 2014 -0800 +++ b/PR__SS.h Fri May 09 11:19:53 2014 +0200 @@ -1,128 +1,128 @@ -/* - * Copyright 2009 OpenSourceResearchInstitute.org - * Licensed under GNU General Public License version 2 - * - * Author: seanhalle@yahoo.com - * - */ - -#ifndef _PR__SS_H -#define _PR__SS_H -#define _GNU_SOURCE - -#include - -//========================= 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! - */ - -//=============== Startup and Shutdown ================ -//=== -//= Some of these are for PR internal use only, others for langlet use - - -#define \ -PR_SS__malloc PR_WL__malloc /*SS happens outside the Master*/ -#define \ -PR_SS__free PR_WL__free - -//=================== -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 ); - - -//================================ -//=== -//= PR internal use only -void -PR_SS__create_topEnv(); - -AnimSlot * -PR_SS__create_anim_slot( int32 coreSlotsAreOn ); - -void -PR_SS__create_the_coreCtlr_OS_threads(); - -int -PR_SS__give_num_cores(); - -//=================== - -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_lang_data_from_slave PR_int__give_lang_data_from_slave -#define \ -PR_SS__give_lang_meta_task_from_slave PR_int__give_lang_meta_task_from_slave -#define \ -PR_SS__give_proto_lang_env_for_slave PR_int__give_proto_lang_env_for_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 /* */ - +/* + * Copyright 2009 OpenSourceResearchInstitute.org + * Licensed under GNU General Public License version 2 + * + * Author: seanhalle@yahoo.com + * + */ + +#ifndef _PR__SS_H +#define _PR__SS_H +#define _GNU_SOURCE + +#include + +//========================= 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! + */ + +//=============== Startup and Shutdown ================ +//=== +//= Some of these are for PR internal use only, others for langlet use + + +#define \ +PR_SS__malloc PR_WL__malloc /*SS happens outside the Master*/ +#define \ +PR_SS__free PR_WL__free + +//=================== +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 ); + + +//================================ +//=== +//= PR internal use only +void +PR_SS__create_topEnv(); + +AnimSlot * +PR_SS__create_anim_slot( int32 coreSlotsAreOn ); + +void +PR_SS__create_the_coreCtlr_OS_threads(); + +int +PR_SS__give_num_cores(); + +//=================== + +void +PR_SS__end_process_normally( PRProcess *process ); + +void +PR_SS__shutdown_OS_threads(); + +SlaveVP* +PR_SS__create_shutdown_slave(int32 coreNum); + +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_lang_data_from_slave PR_int__give_lang_data_from_slave +#define \ +PR_SS__give_lang_meta_task_from_slave PR_int__give_lang_meta_task_from_slave +#define \ +PR_SS__give_proto_lang_env_for_slave PR_int__give_proto_lang_env_for_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 /* */ + diff -r 45f7cf8a80eb -r f3cb11baf791 PR__WL.h --- a/PR__WL.h Tue Mar 04 12:45:08 2014 -0800 +++ b/PR__WL.h Fri May 09 11:19:53 2014 +0200 @@ -63,11 +63,11 @@ #define \ PR__create_taskID_of_size PR_WL__create_taskID_of_size -inline +__inline int32 * PR__give_ID_from_slave( SlaveVP *animSlv, int32 magicNumber ); -inline +__inline int32 * PR__give_ID_from_lang_meta_task( void *_task ); @@ -91,11 +91,11 @@ void PR_WL__suspend_slaveVP_and_send_req( SlaveVP *callingSlv ); -inline void +__inline void PR_WL__add_lang_request_in_mallocd_PRReqst( void *langReqData, SlaveVP *callingSlv ); -inline void +__inline void PR_WL__send_lang_request( void *langReq, RequestHandler handler, SlaveVP *callingSlv, int32 magicNum ); @@ -103,17 +103,17 @@ PR_WL__send_create_slaveVP_req( void *langReq, int32 *ID, CreateHandler handler, SlaveVP *reqstingSlv, int32 magicNum ); -void inline +void __inline PR_WL__send_end_slave_req( void *langReq, RequestHandler handler, SlaveVP *slvToDissipate, int32 magicNum ); -inline void +__inline void PR_WL__send_service_request( void *langReqData, SlaveVP *callingSlv ); -inline void +__inline void PR_WL__send_lang_shutdown_request( SlaveVP *callingSlv, int32 magicNum ); -inline +__inline int32 * PR_WL__create_taskID_of_size( int32 numInts ); diff -r 45f7cf8a80eb -r f3cb11baf791 PR__int.h --- a/PR__int.h Tue Mar 04 12:45:08 2014 -0800 +++ b/PR__int.h Fri May 09 11:19:53 2014 +0200 @@ -22,17 +22,17 @@ * int: internal to the PR implementation */ -inline +__inline void PR_int__reset_slaveVP_to_BirthFn( SlaveVP *slaveVP, BirthFnPtr fnPtr, void *dataParam); -inline +__inline void PR_int__point_slaveVP_to_OneParamFn( SlaveVP *slaveVP, void *fnPtr, void *param); -inline +__inline void PR_int__point_slaveVP_to_TwoParamFn( SlaveVP *slaveVP, void *fnPtr, void *param1, void *param2); @@ -40,13 +40,17 @@ //=========================================================================== // //=========================================================================== -inline +__inline SlaveVP * PR_int__create_slaveVP_struct( BirthFnPtr fnPtr, void *dataParam ); -inline +__inline +void +PR_int__create_slaveVP_finalize( SlaveVP* newSlv ); + +__inline SlaveVP * -PR_int__create_slaveVP( BirthFnPtr fnPtr, void *dataParam, int32 coreNum ); +PR_int__create_slaveVP( BirthFnPtr fnPtr, void *dataParam ); SlaveVP * PR_int__get_recycled_slot_slave( int32 coreNum ); @@ -54,22 +58,22 @@ SlaveVP * PR_int__create_slot_slave( int32 coreNum ); -inline +__inline void PR_int__replace_with_new_slot_slv( SlaveVP *slave ); void idle_fn(void* data, SlaveVP *animatingSlv); -inline +__inline void PR_int__put_task_into_slot( void *task, AnimSlot *slot ); -inline +__inline void PR_int__put_slave_into_slot( SlaveVP *slave, AnimSlot *slot ); -void inline +__inline void PRHandle__ServiceReq( SlaveVP *requestingSlv ); void @@ -89,11 +93,11 @@ //============================= //=== Lange Env //= -inline +__inline void * PR_int__give_lang_env( PRLangEnv *protoLangEnv ); -inline +__inline PRLangEnv * PR_int__give_proto_lang_env( void *langEnv ); @@ -101,89 +105,89 @@ void * PR_int__create_lang_env_in_process( int32 size, PRProcess *process, int32 magicNum ); -inline +__inline void * PR_int__remove_lang_env_from_process_and_free( void *langEnv ); -inline +__inline void * PR_int__give_lang_env_of_req( PRReqst *req, SlaveVP *requestingSlv ); -inline +__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 +__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 +__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 +__inline PRLangEnv * PR_int__give_proto_lang_env_from_process( PRProcess *process, int32 magicNum ); //======================= //=== Meta Task //= -inline +__inline PRMetaTask * PR_int__give_prolog_of_lang_meta_task( void *task ); -inline +__inline void * PR_int__give_lang_meta_task_of_prolog( PRMetaTask *metaTask); -inline +__inline void * PR_int__create_lang_meta_task( int32 size, LangMetaTaskFreer freer, int32 magicNum ); -inline +__inline void * PR_int__create_lang_meta_task_in_slave( int32 size, LangMetaTaskFreer freer, SlaveVP *slave, int32 magicNum ); -inline +__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 +__inline void PR_int__insert_meta_task_into_slave( PRMetaTask *task, SlaveVP *slave ); -inline +__inline void PR_int__insert_lang_meta_task_into_slave__ML( void *langMetaTask, SlaveVP *slave ); -inline +__inline void * PR_int__give_lang_meta_task_from_slave( SlaveVP *slave, int32 magicNumer ); -inline +__inline SlaveVP * PR_PI__give_slave_lang_meta_task_is_assigned_to( void *langMetaTask ); //============== //=== Lang Data //= -inline +__inline void * PR_PI__create_lang_data_in_slave( int32 size, LangDataFreer freer, SlaveVP *slave, int32 magicNum ); -inline +__inline void * PR_int__give_lang_data_from_slave( SlaveVP *slave, int32 magicNumer ); -inline +__inline void * PR_int__give_lang_data_of_prolog( PRLangData *langData); @@ -193,29 +197,29 @@ PRCollElem ** //return an array of pointers PR_int__make_collection_of_size( int32 numInColl ); -inline +__inline void PR_int__insert_elem_into_collection( PRCollElem *elem, PRCollElem **coll, int32 hash ); -inline +__inline void PR_int__replace_or_insert_elem_into_collection( PRCollElem *elem, PRCollElem **coll, int32 hash ); -inline +__inline void * PR_int__lookup_elem_in_collection( int32 hash, PRCollElem **coll ); -inline +__inline void PR_int__remove_elem_from_collection( int32 hash, PRCollElem **coll ); -inline +__inline void PR_int__set_collection_to_empty( PRCollElem **coll ); -inline +__inline void PR_int__apply_Fn_to_all_in_collection( void (*Fn)(void *), PRCollElem **coll ); @@ -245,28 +249,32 @@ char * PR_int__strDup( char *str ); -inline void +__inline void PR_int__get_wrapper_lock(); -inline void +__inline void PR_int__get_master_lock(); -inline void +__inline void PR_int__get_malloc_lock(); -inline void +__inline void PR_int__pthread_wait_for_condition(int32* condVar); +__inline void +PR_int__aquire_masterLock(); + #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 +__inline +uint32_t PR_int__randomNumber(); -inline void +__inline void PR_int__backoff_for_TooLongToGetLock( int32 numTriesToGetLock ); #endif /* _PR_INT_H */ diff -r 45f7cf8a80eb -r f3cb11baf791 PR__primitive_data_types.h --- a/PR__primitive_data_types.h Tue Mar 04 12:45:08 2014 -0800 +++ b/PR__primitive_data_types.h Fri May 09 11:19:53 2014 +0200 @@ -1,42 +1,61 @@ -/* - * 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 */ - +/* + * 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. + */ +#ifdef _WIN32 + +#define bool8 char +#define int8 char +#define uint8 char +#define int16 short +#define uint16 unsigned short +#define int32 int +#define uint32 unsigned int +#define bool32 unsigned int +#define uint64 unsigned long long +#define float32 float +#define float64 double + +#else + +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; + +#endif + +//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 45f7cf8a80eb -r f3cb11baf791 PR__structs__common.h --- a/PR__structs__common.h Tue Mar 04 12:45:08 2014 -0800 +++ b/PR__structs__common.h Fri May 09 11:19:53 2014 +0200 @@ -11,7 +11,13 @@ #define _GNU_SOURCE #include +#ifdef _WIN32 + #define WIN32__LEAN_AND_MEAN + #include +#else +#endif #include + #include //#include "PR_defs__turn_on_and_off.h" @@ -108,13 +114,13 @@ 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; + MEAS__Insert_Susp_Meas_Fields_into_MasterEnv + MEAS__Insert_Master_Meas_Fields_into_MasterEnv + MEAS__Insert_Master_Lock_Meas_Fields_into_MasterEnv + MEAS__Insert_System_Meas_Fields_into_MasterEnv + MEAS__Insert_Malloc_Meas_Fields_into_MasterEnv + MEAS__Insert_Plugin_Meas_Fields_into_MasterEnv + MEAS__Insert_Counter_Meas_Fields_into_MasterEnv //========================================== } PRProcess; @@ -186,6 +192,7 @@ typedef struct { //for future expansion + void* undefined; } SlotPerfInfo; @@ -253,7 +260,7 @@ // PRGhostInfo *ghostInfo; //=========== MEASUREMENT STUFF ========== - MEAS__Insert_Meas_Fields_into_Slave; + MEAS__Insert_Meas_Fields_into_Slave float64 createPtInSecs; //time VP created, in seconds //======================================== @@ -346,10 +353,9 @@ //========================= Extra Stuff Data Strucs ======================= typedef struct { - + void* undefined; } PRExcp; //exception - #endif /* _PR__structs_H */ diff -r 45f7cf8a80eb -r f3cb11baf791 Services_offered_by_PR/DEBUG__macros.h --- a/Services_offered_by_PR/DEBUG__macros.h Tue Mar 04 12:45:08 2014 -0800 +++ b/Services_offered_by_PR/DEBUG__macros.h Fri May 09 11:19:53 2014 +0200 @@ -1,65 +1,65 @@ -/* - * Copyright 2009 OpenSourceResearchInstitute.org - * Licensed under GNU General Public License version 2 - * - * Author: seanhalle@yahoo.com - * - */ - -#ifndef _DEBUG__macros_H -#define _DEBUG__macros_H -#define _GNU_SOURCE - -/* - */ -#ifdef DEBUG__TURN_ON_DEBUG_PRINT - #define DEBUG__printf( bool, ...) \ - do{\ - if(bool)\ - { printf(__VA_ARGS__);\ - printf(" | function: %s\n", __FUNCTION__);\ - fflush(stdin);\ - }\ - }while(0);/*macro magic to isolate var-names*/ - - #define DEBUG__printf1( bool, msg, param) \ - do{\ - if(bool)\ - { printf(msg, param);\ - printf(" | function: %s\n", __FUNCTION__);\ - fflush(stdin);\ - }\ - }while(0);/*macro magic to isolate var-names*/ - - #define DEBUG__printf2( bool, msg, p1, p2) \ - do{\ - if(bool)\ - { printf(msg, p1, p2); \ - printf(" | function: %s\n", __FUNCTION__);\ - fflush(stdin);\ - }\ - }while(0);/*macro magic to isolate var-names*/ - - #define DEBUG__printf3( bool, msg, p1, p2, p3) \ - do{\ - if(bool)\ - { printf(msg, p1, p2, p3); \ - printf(" | function: %s\n", __FUNCTION__);\ - fflush(stdin);\ - }\ - }while(0);/*macro magic to isolate var-names*/ - -#else - #define DEBUG__printf( bool, ...) - #define DEBUG__printf1( bool, msg, param) - #define DEBUG__printf2( bool, msg, p1, p2) -#endif - -//============================= ERROR MSGs ============================ -#define ERROR(msg) printf(msg); -#define ERROR1(msg, param) printf(msg, param); -#define ERROR2(msg, p1, p2) printf(msg, p1, p2); - -//=========================================================================== -#endif /* _PR_DEFS_H */ - +/* + * Copyright 2009 OpenSourceResearchInstitute.org + * Licensed under GNU General Public License version 2 + * + * Author: seanhalle@yahoo.com + * + */ + +#ifndef _DEBUG__macros_H +#define _DEBUG__macros_H +#define _GNU_SOURCE + +/* + */ +#ifdef DEBUG__TURN_ON_DEBUG_PRINT + #define DEBUG__printf( bool, ...) \ + do{\ + if(bool)\ + { printf(__VA_ARGS__);\ + printf(" | function: %s:%d\n", __FUNCTION__, __LINE__);\ + fflush(stdin);\ + }\ + }while(0);/*macro magic to isolate var-names*/ + + #define DEBUG__printf1( bool, msg, param) \ + do{\ + if(bool)\ + { printf(msg, param);\ + printf(" | function: %s\n", __FUNCTION__);\ + fflush(stdin);\ + }\ + }while(0);/*macro magic to isolate var-names*/ + + #define DEBUG__printf2( bool, msg, p1, p2) \ + do{\ + if(bool)\ + { printf(msg, p1, p2); \ + printf(" | function: %s\n", __FUNCTION__);\ + fflush(stdin);\ + }\ + }while(0);/*macro magic to isolate var-names*/ + + #define DEBUG__printf3( bool, msg, p1, p2, p3) \ + do{\ + if(bool)\ + { printf(msg, p1, p2, p3); \ + printf(" | function: %s\n", __FUNCTION__);\ + fflush(stdin);\ + }\ + }while(0);/*macro magic to isolate var-names*/ + +#else + #define DEBUG__printf( bool, ...) + #define DEBUG__printf1( bool, msg, param) + #define DEBUG__printf2( bool, msg, p1, p2) +#endif + +//============================= ERROR MSGs ============================ +#define ERROR(msg) printf(msg); +#define ERROR1(msg, param) printf(msg, param); +#define ERROR2(msg, p1, p2) printf(msg, p1, p2); + +//=========================================================================== +#endif /* _PR_DEFS_H */ + diff -r 45f7cf8a80eb -r f3cb11baf791 Services_offered_by_PR/MEAS__Counter_Recording.h --- a/Services_offered_by_PR/MEAS__Counter_Recording.h Tue Mar 04 12:45:08 2014 -0800 +++ b/Services_offered_by_PR/MEAS__Counter_Recording.h Fri May 09 11:19:53 2014 +0200 @@ -1,37 +1,37 @@ -/* - * File: MEAS__Counter_Recording.h - * Author: nengel - * - * Created on January 11, 2012, 3:03 PM - */ - -#ifndef MEAS__COUNTER_RECORDING_H -#define MEAS__COUNTER_RECORDING_H - - -#include - -typedef struct - { - int event_type; - int coreID; - AnimSlot* slot; - int vp; - int task; - uint64 cycles; - uint64 instrs; - } -CounterEvent; - -FILE* counterfile; //pass file handle via side effect because - // doAllInListOfArrays only takes Fns with a single input - -void MEAS__init_counter_data_structs_for_lang( SlaveVP *slv, int32 magicNum ); - -void MEAS__counter_handler(int evt_type, int vpid, int task, SlaveVP* pr, uint64 cycles, uint64 instrs); - -void MEAS__set_counter_file(FILE* f); - -void MEAS__print_counter_event_to_file( void* _e ); -#endif /* PRServ_COUNTER_RECORDING_H */ - +/* + * File: MEAS__Counter_Recording.h + * Author: nengel + * + * Created on January 11, 2012, 3:03 PM + */ + +#ifndef MEAS__COUNTER_RECORDING_H +#define MEAS__COUNTER_RECORDING_H + + +#include + +typedef struct + { + int event_type; + int coreID; + AnimSlot* slot; + int vp; + int task; + uint64 cycles; + uint64 instrs; + } +CounterEvent; + +FILE* counterfile; //pass file handle via side effect because + // doAllInListOfArrays only takes Fns with a single input + +void MEAS__init_counter_data_structs_for_lang( SlaveVP *slv, int32 magicNum ); + +void MEAS__counter_handler(int evt_type, int vpid, int task, SlaveVP* pr, uint64 cycles, uint64 instrs); + +void MEAS__set_counter_file(FILE* f); + +void MEAS__print_counter_event_to_file( void* _e ); +#endif /* PRServ_COUNTER_RECORDING_H */ + diff -r 45f7cf8a80eb -r f3cb11baf791 Services_offered_by_PR/MEAS__macros.h --- a/Services_offered_by_PR/MEAS__macros.h Tue Mar 04 12:45:08 2014 -0800 +++ b/Services_offered_by_PR/MEAS__macros.h Fri May 09 11:19:53 2014 +0200 @@ -1,514 +1,514 @@ -/* - * Copyright 2009 OpenSourceResearchInstitute.org - * Licensed under GNU General Public License version 2 - * - * Author: seanhalle@yahoo.com - * - */ - -#ifndef _MEAS_MACROS_H -#define _MEAS_MACROS_H -#define _GNU_SOURCE - -//================== Macros define types of meas want ===================== -// -/*Generic measurement macro -- has name-space collision potential, which - * compiler will catch.. so only use one pair inside a given set of - * curly braces. - */ -//TODO: finish generic capture interval in hist -enum histograms - { generic1 - }; - #define MEAS__Capture_Pre_Point \ - int32 startStamp, endStamp; \ - saveLowTimeStampCountInto( startStamp ); - - #define MEAS__Capture_Post_Point( histName ) \ - saveLowTimeStampCountInto( endStamp ); \ - addIntervalToHist( startStamp, endStamp, _PRTopEnv->histName ); - - - - -//================== Macros define types of meas want ===================== - -#ifdef MEAS__TURN_ON_SUSP_MEAS - #define MEAS__Insert_Susp_Meas_Fields_into_Slave \ - uint32 preSuspTSCLow; \ - uint32 postSuspTSCLow; - - #define MEAS__Insert_Susp_Meas_Fields_into_MasterEnv \ - Histogram *suspLowTimeHist; \ - Histogram *suspHighTimeHist; - - #define MEAS__Make_Meas_Hists_for_Susp_Meas \ - _PRTopEnv->suspLowTimeHist = makeFixedBinHistExt( 100, 0, 200,\ - "master_low_time_hist");\ - _PRTopEnv->suspHighTimeHist = makeFixedBinHistExt( 100, 0, 200,\ - "master_high_time_hist"); - - //record time stamp: compare to time-stamp recorded below - #define MEAS__Capture_Pre_Susp_Point \ - saveLowTimeStampCountInto( animatingSlv->preSuspTSCLow ); - - //NOTE: only take low part of count -- do sanity check when take diff - #define MEAS__Capture_Post_Susp_Point \ - saveLowTimeStampCountInto( animatingSlv->postSuspTSCLow );\ - addIntervalToHist( preSuspTSCLow, postSuspTSCLow,\ - _PRTopEnv->suspLowTimeHist ); \ - addIntervalToHist( preSuspTSCLow, postSuspTSCLow,\ - _PRTopEnv->suspHighTimeHist ); - - #define MEAS__Print_Hists_for_Susp_Meas \ - printHist( _PRTopEnv->pluginTimeHist ); - -#else - #define MEAS__Insert_Susp_Meas_Fields_into_Slave - #define MEAS__Insert_Susp_Meas_Fields_into_MasterEnv - #define MEAS__Make_Meas_Hists_for_Susp_Meas - #define MEAS__Capture_Pre_Susp_Point - #define MEAS__Capture_Post_Susp_Point - #define MEAS__Print_Hists_for_Susp_Meas -#endif - -#ifdef MEAS__TURN_ON_MASTER_MEAS - #define MEAS__Insert_Master_Meas_Fields_into_Slave \ - uint32 startMasterTSCLow; \ - uint32 endMasterTSCLow; - - #define MEAS__Insert_Master_Meas_Fields_into_MasterEnv \ - Histogram *masterLowTimeHist; \ - Histogram *masterHighTimeHist; - - #define MEAS__Make_Meas_Hists_for_Master_Meas \ - _PRTopEnv->masterLowTimeHist = makeFixedBinHistExt( 100, 0, 200,\ - "master_low_time_hist");\ - _PRTopEnv->masterHighTimeHist = makeFixedBinHistExt( 100, 0, 200,\ - "master_high_time_hist"); - - //Total Master time includes one coreloop time -- just assume the core - // loop time is same for Master as for AppSlvs, even though it may be - // smaller due to higher predictability of the fixed jmp. - #define MEAS__Capture_Pre_Master_Point\ - saveLowTimeStampCountInto( masterVP->startMasterTSCLow ); - - #define MEAS__Capture_Post_Master_Point \ - saveLowTimeStampCountInto( masterVP->endMasterTSCLow );\ - addIntervalToHist( startMasterTSCLow, endMasterTSCLow,\ - _PRTopEnv->masterLowTimeHist ); \ - addIntervalToHist( startMasterTSCLow, endMasterTSCLow,\ - _PRTopEnv->masterHighTimeHist ); - - #define MEAS__Print_Hists_for_Master_Meas \ - printHist( _PRTopEnv->pluginTimeHist ); - -#else - #define MEAS__Insert_Master_Meas_Fields_into_Slave - #define MEAS__Insert_Master_Meas_Fields_into_MasterEnv - #define MEAS__Make_Meas_Hists_for_Master_Meas - #define MEAS__Capture_Pre_Master_Point - #define MEAS__Capture_Post_Master_Point - #define MEAS__Print_Hists_for_Master_Meas -#endif - - -#ifdef MEAS__TURN_ON_MASTER_LOCK_MEAS - #define MEAS__Insert_Master_Lock_Meas_Fields_into_MasterEnv \ - Histogram *masterLockLowTimeHist; \ - Histogram *masterLockHighTimeHist; - - #define MEAS__Make_Meas_Hists_for_Master_Lock_Meas \ - _PRTopEnv->masterLockLowTimeHist = makeFixedBinHist( 50, 0, 2, \ - "master lock low time hist");\ - _PRTopEnv->masterLockHighTimeHist = makeFixedBinHist( 50, 0, 100,\ - "master lock high time hist"); - - #define MEAS__Capture_Pre_Master_Lock_Point \ - int32 startStamp, endStamp; \ - saveLowTimeStampCountInto( startStamp ); - - #define MEAS__Capture_Post_Master_Lock_Point \ - saveLowTimeStampCountInto( endStamp ); \ - addIntervalToHist( startStamp, endStamp,\ - _PRTopEnv->masterLockLowTimeHist ); \ - addIntervalToHist( startStamp, endStamp,\ - _PRTopEnv->masterLockHighTimeHist ); - - #define MEAS__Print_Hists_for_Master_Lock_Meas \ - printHist( _PRTopEnv->masterLockLowTimeHist ); \ - printHist( _PRTopEnv->masterLockHighTimeHist ); - -#else - #define MEAS__Insert_Master_Lock_Meas_Fields_into_MasterEnv - #define MEAS__Make_Meas_Hists_for_Master_Lock_Meas - #define MEAS__Capture_Pre_Master_Lock_Point - #define MEAS__Capture_Post_Master_Lock_Point - #define MEAS__Print_Hists_for_Master_Lock_Meas -#endif - - -#ifdef MEAS__TURN_ON_MALLOC_MEAS - #define MEAS__Insert_Malloc_Meas_Fields_into_MasterEnv\ - Histogram *mallocTimeHist; \ - Histogram *freeTimeHist; - - #define MEAS__Make_Meas_Hists_for_Malloc_Meas \ - _PRTopEnv->mallocTimeHist = makeFixedBinHistExt( 100, 0, 30,\ - "malloc_time_hist");\ - _PRTopEnv->freeTimeHist = makeFixedBinHistExt( 100, 0, 30,\ - "free_time_hist"); - - #define MEAS__Capture_Pre_Malloc_Point \ - int32 startStamp, endStamp; \ - saveLowTimeStampCountInto( startStamp ); - - #define MEAS__Capture_Post_Malloc_Point \ - saveLowTimeStampCountInto( endStamp ); \ - addIntervalToHist( startStamp, endStamp,\ - _PRTopEnv->mallocTimeHist ); - - #define MEAS__Capture_Pre_Free_Point \ - int32 startStamp, endStamp; \ - saveLowTimeStampCountInto( startStamp ); - - #define MEAS__Capture_Post_Free_Point \ - saveLowTimeStampCountInto( endStamp ); \ - addIntervalToHist( startStamp, endStamp,\ - _PRTopEnv->freeTimeHist ); - - #define MEAS__Print_Hists_for_Malloc_Meas \ - printHist( _PRTopEnv->mallocTimeHist ); \ - saveHistToFile( _PRTopEnv->mallocTimeHist ); \ - printHist( _PRTopEnv->freeTimeHist ); \ - saveHistToFile( _PRTopEnv->freeTimeHist ); \ - freeHistExt( _PRTopEnv->mallocTimeHist ); \ - freeHistExt( _PRTopEnv->freeTimeHist ); - -#else - #define MEAS__Insert_Malloc_Meas_Fields_into_MasterEnv - #define MEAS__Make_Meas_Hists_for_Malloc_Meas - #define MEAS__Capture_Pre_Malloc_Point - #define MEAS__Capture_Post_Malloc_Point - #define MEAS__Capture_Pre_Free_Point - #define MEAS__Capture_Post_Free_Point - #define MEAS__Print_Hists_for_Malloc_Meas -#endif - - - -#ifdef MEAS__TURN_ON_PLUGIN_MEAS - #define MEAS__Insert_Plugin_Meas_Fields_into_MasterEnv \ - Histogram *reqHdlrLowTimeHist; \ - Histogram *reqHdlrHighTimeHist; - - #define MEAS__Make_Meas_Hists_for_Plugin_Meas \ - _PRTopEnv->reqHdlrLowTimeHist = makeFixedBinHistExt( 100, 0, 200,\ - "plugin_low_time_hist");\ - _PRTopEnv->reqHdlrHighTimeHist = makeFixedBinHistExt( 100, 0, 200,\ - "plugin_high_time_hist"); - - #define MEAS__startReqHdlr \ - int32 startStamp1, endStamp1; \ - saveLowTimeStampCountInto( startStamp1 ); - - #define MEAS__endReqHdlr \ - saveLowTimeStampCountInto( endStamp1 ); \ - addIntervalToHist( startStamp1, endStamp1, \ - _PRTopEnv->reqHdlrLowTimeHist ); \ - addIntervalToHist( startStamp1, endStamp1, \ - _PRTopEnv->reqHdlrHighTimeHist ); - - #define MEAS__Print_Hists_for_Plugin_Meas \ - printHist( _PRTopEnv->reqHdlrLowTimeHist ); \ - saveHistToFile( _PRTopEnv->reqHdlrLowTimeHist ); \ - printHist( _PRTopEnv->reqHdlrHighTimeHist ); \ - saveHistToFile( _PRTopEnv->reqHdlrHighTimeHist ); \ - freeHistExt( _PRTopEnv->reqHdlrLowTimeHist ); \ - freeHistExt( _PRTopEnv->reqHdlrHighTimeHist ); -#else - #define MEAS__Insert_Plugin_Meas_Fields_into_MasterEnv - #define MEAS__Make_Meas_Hists_for_Plugin_Meas - #define MEAS__startReqHdlr - #define MEAS__endReqHdlr - #define MEAS__Print_Hists_for_Plugin_Meas - -#endif - - -#ifdef MEAS__TURN_ON_SYSTEM_MEAS - #define MEAS__Insert_System_Meas_Fields_into_Slave \ - TSCountLowHigh startSusp; \ - uint64 totalSuspCycles; \ - uint32 numGoodSusp; - - #define MEAS__Insert_System_Meas_Fields_into_MasterEnv \ - TSCountLowHigh startMaster; \ - uint64 totalMasterCycles; \ - uint32 numMasterAnimations; \ - TSCountLowHigh startReqHdlr; \ - uint64 totalPluginCycles; \ - uint32 numPluginAnimations; \ - uint64 cyclesTillStartAnimationMaster; \ - TSCountLowHigh endAnimationMaster; - - #define MEAS__startAnimationMaster_forSys \ - TSCountLowHigh startStamp1, endStamp1; \ - saveTSCLowHigh( endStamp1 ); \ - _PRTopEnv->cyclesTillStartAnimationMaster = \ - endStamp1.longVal - masterVP->startSusp.longVal; - - #define Meas_startReqHdlr_forSys \ - saveTSCLowHigh( startStamp1 ); \ - _PRTopEnv->startReqHdlr.longVal = startStamp1.longVal; - - #define MEAS__endAnimationMaster_forSys \ - saveTSCLowHigh( startStamp1 ); \ - _PRTopEnv->endAnimationMaster.longVal = startStamp1.longVal; - - /*A TSC is stored in VP first thing inside wrapper-lib - * Now, measures cycles from there to here - * Master and Plugin will add this value to other trace-seg measures - */ - #define MEAS__Capture_End_Susp_in_CoreCtlr_ForSys\ - saveTSCLowHigh(endSusp); \ - numCycles = endSusp.longVal - currVP->startSusp.longVal; \ - /*sanity check (400K is about 20K iters)*/ \ - if( numCycles < 400000 ) \ - { currVP->totalSuspCycles += numCycles; \ - currVP->numGoodSusp++; \ - } \ - /*recorded every time, but only read if currVP == MasterVP*/ \ - _PRTopEnv->startMaster.longVal = endSusp.longVal; - -#else - #define MEAS__Insert_System_Meas_Fields_into_Slave - #define MEAS__Insert_System_Meas_Fields_into_MasterEnv - #define MEAS__Make_Meas_Hists_for_System_Meas - #define MEAS__startAnimationMaster_forSys - #define MEAS__startReqHdlr_forSys - #define MEAS__endAnimationMaster_forSys - #define MEAS__Capture_End_Susp_in_CoreCtlr_ForSys - #define MEAS__Print_Hists_for_System_Meas -#endif - -#ifdef HOLISTIC__TURN_ON_PERF_COUNTERS - - #define MEAS__Insert_Counter_Handler \ - typedef void (*CounterHandler) (int,int,int,SlaveVP*,uint64,uint64,uint64); - - enum eventType { - DebugEvt = 0, - AppResponderInvocation_start, - AppResponder_start, - AppResponder_end, - AssignerInvocation_start, - NextAssigner_start, - Assigner_start, - Assigner_end, - Work_start, - Work_end, - HwResponderInvocation_start, - Timestamp_start, - Timestamp_end - }; - - #define saveCyclesAndInstrs(core,cycles,instrs,cachem) do{ \ - int cycles_fd = _PRTopEnv->cycles_counter_fd[core]; \ - int instrs_fd = _PRTopEnv->instrs_counter_fd[core]; \ - int cachem_fd = _PRTopEnv->cachem_counter_fd[core]; \ - int nread; \ - \ - nread = read(cycles_fd,&(cycles),sizeof(cycles)); \ - if(nread<0){ \ - perror("Error reading cycles counter"); \ - cycles = 0; \ - } \ - \ - nread = read(instrs_fd,&(instrs),sizeof(instrs)); \ - if(nread<0){ \ - perror("Error reading cycles counter"); \ - instrs = 0; \ - } \ - nread = read(cachem_fd,&(cachem),sizeof(cachem)); \ - if(nread<0){ \ - perror("Error reading last level cache miss counter"); \ - cachem = 0; \ - } \ - } while (0) - - #define MEAS__Insert_Counter_Meas_Fields_into_MasterEnv \ - int cycles_counter_fd[NUM_CORES]; \ - int instrs_counter_fd[NUM_CORES]; \ - int cachem_counter_fd[NUM_CORES]; \ - uint64 start_master_lock[NUM_CORES][3]; \ - CounterHandler counterHandler; - - #define HOLISTIC__Setup_Perf_Counters setup_perf_counters(); - - - #define HOLISTIC__CoreCtrl_Setup \ - CounterHandler counterHandler = _PRTopEnv->counterHandler; \ - SlaveVP *lastVPBeforeMaster = NULL; \ - /*if(thisCoresThdParams->coreNum == 0){ \ - uint64 initval = tsc_offset_send(thisCoresThdParams,0); \ - while(!coreCtlrThdParams[NUM_CORES - 2]->ret_tsc); \ - } \ - if(0 < (thisCoresThdParams->coreNum) && (thisCoresThdParams->coreNum) < (NUM_CORES - 1)){ \ - ThdParams* sendCoresThdParams = coreCtlrThdParams[thisCoresThdParams->coreNum - 1]; \ - int sndctr = tsc_offset_resp(sendCoresThdParams, 0); \ - uint64 initval = tsc_offset_send(thisCoresThdParams,0); \ - while(!coreCtlrThdParams[NUM_CORES - 2]->ret_tsc); \ - } \ - if(thisCoresThdParams->coreNum == (NUM_CORES - 1)){ \ - ThdParams* sendCoresThdParams = coreCtlrThdParams[thisCoresThdParams->coreNum - 1]; \ - int sndctr = tsc_offset_resp(sendCoresThdParams,0); \ - }*/ - - - #define HOLISTIC__Insert_Master_Global_Vars \ - int vpid,task; \ - CounterHandler counterHandler = _PRTopEnv->counterHandler; - - #define HOLISTIC__Record_last_work lastVPBeforeMaster = currVP; - - #define HOLISTIC__Record_AppResponderInvocation_start \ - uint64 cycles,instrs,cachem; \ - saveCyclesAndInstrs(thisCoresIdx,cycles, instrs,cachem); \ - if(lastVPBeforeMaster){ \ - (*counterHandler)(AppResponderInvocation_start,lastVPBeforeMaster->slaveNum,lastVPBeforeMaster->numTimesAssignedToASlot,lastVPBeforeMaster,cycles,instrs,cachem); \ - lastVPBeforeMaster = NULL; \ - } else { \ - _PRTopEnv->start_master_lock[thisCoresIdx][0] = cycles; \ - _PRTopEnv->start_master_lock[thisCoresIdx][1] = instrs; \ - _PRTopEnv->start_master_lock[thisCoresIdx][2] = cachem; \ - } - - /* Request Handler may call resume() on the VP, but we want to - * account the whole interval to the same task. Therefore, need - * to save task ID at the beginning. - * - * Using this value as "end of AppResponder Invocation Time" - * is possible if there is only one SchedSlot per core - - * invoking processor is last to be treated here! If more than - * one slot, MasterLoop processing time for all but the last VP - * would be erroneously counted as invocation time. - */ - #define HOLISTIC__Record_AppResponder_start \ - vpid = currSlot->slaveAssignedToSlot->slaveNum; \ - task = currSlot->slaveAssignedToSlot->numTimesAssignedToASlot; \ - uint64 cycles, instrs, cachem; \ - saveCyclesAndInstrs(thisCoresIdx,cycles, instrs,cachem); \ - (*counterHandler)(AppResponder_start,vpid,task,currSlot->slaveAssignedToSlot,cycles,instrs,cachem); - - #define HOLISTIC__Record_AppResponder_end \ - uint64 cycles2,instrs2,cachem2; \ - saveCyclesAndInstrs(thisCoresIdx,cycles2, instrs2,cachem2); \ - (*counterHandler)(AppResponder_end,vpid,task,currSlot->slaveAssignedToSlot,cycles2,instrs2,cachem2); \ - (*counterHandler)(Timestamp_end,vpid,task,currSlot->slaveAssignedToSlot,rdtsc(),0,0); - - - /* Don't know who to account time to yet - goes to assigned VP - * after the call. - */ - #define HOLISTIC__Record_Assigner_start \ - int empty = FALSE; \ - if(currSlot->slaveAssignedToSlot == NULL){ \ - empty= TRUE; \ - } \ - uint64 tmp_cycles, tmp_instrs, tmp_cachem; \ - saveCyclesAndInstrs(thisCoresIdx,tmp_cycles,tmp_instrs,tmp_cachem); \ - uint64 tsc = rdtsc(); \ - if(vpid > 0) { \ - (*counterHandler)(NextAssigner_start,vpid,task,currSlot->slaveAssignedToSlot,tmp_cycles,tmp_instrs,tmp_cachem); \ - vpid = 0; \ - task = 0; \ - } - - #define HOLISTIC__Record_Assigner_end \ - uint64 cycles,instrs,cachem; \ - saveCyclesAndInstrs(thisCoresIdx,cycles,instrs,cachem); \ - if(empty){ \ - (*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]); \ - } \ - (*counterHandler)(Timestamp_start,assignedSlaveVP->slaveNum,assignedSlaveVP->numTimesAssignedToASlot,assignedSlaveVP,tsc,0,0); \ - (*counterHandler)(Assigner_start,assignedSlaveVP->slaveNum,assignedSlaveVP->numTimesAssignedToASlot,assignedSlaveVP,tmp_cycles,tmp_instrs,tmp_cachem); \ - (*counterHandler)(Assigner_end,assignedSlaveVP->slaveNum,assignedSlaveVP->numTimesAssignedToASlot,assignedSlaveVP,cycles,instrs,tmp_cachem); - - #define HOLISTIC__Record_Work_start \ - if(currVP){ \ - uint64 cycles,instrs,cachem; \ - saveCyclesAndInstrs(thisCoresIdx,cycles, instrs,cachem); \ - (*counterHandler)(Work_start,currVP->slaveNum,currVP->numTimesAssignedToASlot,currVP,cycles,instrs,cachem); \ - } - - #define HOLISTIC__Record_Work_end \ - if(currVP){ \ - uint64 cycles,instrs,cachem; \ - saveCyclesAndInstrs(thisCoresIdx,cycles, instrs,cachem); \ - (*counterHandler)(Work_end,currVP->slaveNum,currVP->numTimesAssignedToASlot,currVP,cycles,instrs,cachem); \ - } - - #define HOLISTIC__Record_HwResponderInvocation_start \ - uint64 cycles,instrs,cachem; \ - saveCyclesAndInstrs(animatingSlv->coreAnimatedBy,cycles, instrs,cachem); \ - (*(_PRTopEnv->counterHandler))(HwResponderInvocation_start,animatingSlv->slaveNum,animatingSlv->numTimesAssignedToASlot,animatingSlv,cycles,instrs,cachem); - - - #define getReturnAddressBeforeLibraryCall(vp_ptr, res_ptr) do{ \ -void* frame_ptr0 = vp_ptr->framePtr; \ -void* frame_ptr1 = *((void**)frame_ptr0); \ -void* frame_ptr2 = *((void**)frame_ptr1); \ -void* frame_ptr3 = *((void**)frame_ptr2); \ -void* ret_addr = *((void**)frame_ptr3 + 1); \ -*res_ptr = ret_addr; \ -} while (0) - -#else - #define MEAS__Insert_Counter_Handler - #define MEAS__Insert_Counter_Meas_Fields_into_MasterEnv - #define HOLISTIC__Setup_Perf_Counters - #define HOLISTIC__CoreCtrl_Setup - #define HOLISTIC__Insert_Master_Global_Vars - #define HOLISTIC__Record_last_work - #define HOLISTIC__Record_AppResponderInvocation_start - #define HOLISTIC__Record_AppResponder_start - #define HOLISTIC__Record_AppResponder_end - #define HOLISTIC__Record_Assigner_start - #define HOLISTIC__Record_Assigner_end - #define HOLISTIC__Record_Work_start - #define HOLISTIC__Record_Work_end - #define HOLISTIC__Record_HwResponderInvocation_start - #define getReturnAddressBeforeLibraryCall(vp_ptr, res_ptr) -#endif - -//Experiment in two-step macros -- if doesn't work, insert each separately -#define MEAS__Insert_Meas_Fields_into_Slave \ - MEAS__Insert_Susp_Meas_Fields_into_Slave \ - MEAS__Insert_Master_Meas_Fields_into_Slave \ - MEAS__Insert_System_Meas_Fields_into_Slave - - -//====================== Histogram Macros -- Create ======================== -// -// - -//The language implementation should include a definition of this macro, -// which creates all the histograms the language uses to collect measurements -// of plugin operation -- so, if the language didn't define it, must -// define it here (as empty), to avoid compile error -#ifndef MEAS__Make_Meas_Hists_for_Language -#define MEAS__Make_Meas_Hists_for_Language -#endif - -#define makeAMeasHist( histInfo, idx, name, numBins, startVal, binWidth ) \ - makeHighestDynArrayIndexBeAtLeast( _PRTopEnv->measHistsInfo, idx ); \ - _PRTopEnv->measHists[idx] = \ - makeFixedBinHist( numBins, startVal, binWidth, name ); - -//============================== Probes =================================== - - -//=========================================================================== -#endif /* _PR_DEFS_MEAS_H */ - +/* + * Copyright 2009 OpenSourceResearchInstitute.org + * Licensed under GNU General Public License version 2 + * + * Author: seanhalle@yahoo.com + * + */ + +#ifndef _MEAS_MACROS_H +#define _MEAS_MACROS_H +#define _GNU_SOURCE + +//================== Macros define types of meas want ===================== +// +/*Generic measurement macro -- has name-space collision potential, which + * compiler will catch.. so only use one pair inside a given set of + * curly braces. + */ +//TODO: finish generic capture interval in hist +enum histograms + { generic1 + }; + #define MEAS__Capture_Pre_Point \ + int32 startStamp, endStamp; \ + saveLowTimeStampCountInto( startStamp ); + + #define MEAS__Capture_Post_Point( histName ) \ + saveLowTimeStampCountInto( endStamp ); \ + addIntervalToHist( startStamp, endStamp, _PRTopEnv->histName ); + + + + +//================== Macros define types of meas want ===================== + +#ifdef MEAS__TURN_ON_SUSP_MEAS + #define MEAS__Insert_Susp_Meas_Fields_into_Slave \ + uint32 preSuspTSCLow; \ + uint32 postSuspTSCLow; + + #define MEAS__Insert_Susp_Meas_Fields_into_MasterEnv \ + Histogram *suspLowTimeHist; \ + Histogram *suspHighTimeHist; + + #define MEAS__Make_Meas_Hists_for_Susp_Meas \ + _PRTopEnv->suspLowTimeHist = makeFixedBinHistExt( 100, 0, 200,\ + "master_low_time_hist");\ + _PRTopEnv->suspHighTimeHist = makeFixedBinHistExt( 100, 0, 200,\ + "master_high_time_hist"); + + //record time stamp: compare to time-stamp recorded below + #define MEAS__Capture_Pre_Susp_Point \ + saveLowTimeStampCountInto( animatingSlv->preSuspTSCLow ); + + //NOTE: only take low part of count -- do sanity check when take diff + #define MEAS__Capture_Post_Susp_Point \ + saveLowTimeStampCountInto( animatingSlv->postSuspTSCLow );\ + addIntervalToHist( preSuspTSCLow, postSuspTSCLow,\ + _PRTopEnv->suspLowTimeHist ); \ + addIntervalToHist( preSuspTSCLow, postSuspTSCLow,\ + _PRTopEnv->suspHighTimeHist ); + + #define MEAS__Print_Hists_for_Susp_Meas \ + printHist( _PRTopEnv->pluginTimeHist ); + +#else + #define MEAS__Insert_Susp_Meas_Fields_into_Slave + #define MEAS__Insert_Susp_Meas_Fields_into_MasterEnv + #define MEAS__Make_Meas_Hists_for_Susp_Meas + #define MEAS__Capture_Pre_Susp_Point + #define MEAS__Capture_Post_Susp_Point + #define MEAS__Print_Hists_for_Susp_Meas +#endif + +#ifdef MEAS__TURN_ON_MASTER_MEAS + #define MEAS__Insert_Master_Meas_Fields_into_Slave \ + uint32 startMasterTSCLow; \ + uint32 endMasterTSCLow; + + #define MEAS__Insert_Master_Meas_Fields_into_MasterEnv \ + Histogram *masterLowTimeHist; \ + Histogram *masterHighTimeHist; + + #define MEAS__Make_Meas_Hists_for_Master_Meas \ + _PRTopEnv->masterLowTimeHist = makeFixedBinHistExt( 100, 0, 200,\ + "master_low_time_hist");\ + _PRTopEnv->masterHighTimeHist = makeFixedBinHistExt( 100, 0, 200,\ + "master_high_time_hist"); + + //Total Master time includes one coreloop time -- just assume the core + // loop time is same for Master as for AppSlvs, even though it may be + // smaller due to higher predictability of the fixed jmp. + #define MEAS__Capture_Pre_Master_Point\ + saveLowTimeStampCountInto( masterVP->startMasterTSCLow ); + + #define MEAS__Capture_Post_Master_Point \ + saveLowTimeStampCountInto( masterVP->endMasterTSCLow );\ + addIntervalToHist( startMasterTSCLow, endMasterTSCLow,\ + _PRTopEnv->masterLowTimeHist ); \ + addIntervalToHist( startMasterTSCLow, endMasterTSCLow,\ + _PRTopEnv->masterHighTimeHist ); + + #define MEAS__Print_Hists_for_Master_Meas \ + printHist( _PRTopEnv->pluginTimeHist ); + +#else + #define MEAS__Insert_Master_Meas_Fields_into_Slave + #define MEAS__Insert_Master_Meas_Fields_into_MasterEnv + #define MEAS__Make_Meas_Hists_for_Master_Meas + #define MEAS__Capture_Pre_Master_Point + #define MEAS__Capture_Post_Master_Point + #define MEAS__Print_Hists_for_Master_Meas +#endif + + +#ifdef MEAS__TURN_ON_MASTER_LOCK_MEAS + #define MEAS__Insert_Master_Lock_Meas_Fields_into_MasterEnv \ + Histogram *masterLockLowTimeHist; \ + Histogram *masterLockHighTimeHist; + + #define MEAS__Make_Meas_Hists_for_Master_Lock_Meas \ + _PRTopEnv->masterLockLowTimeHist = makeFixedBinHist( 50, 0, 2, \ + "master lock low time hist");\ + _PRTopEnv->masterLockHighTimeHist = makeFixedBinHist( 50, 0, 100,\ + "master lock high time hist"); + + #define MEAS__Capture_Pre_Master_Lock_Point \ + int32 startStamp, endStamp; \ + saveLowTimeStampCountInto( startStamp ); + + #define MEAS__Capture_Post_Master_Lock_Point \ + saveLowTimeStampCountInto( endStamp ); \ + addIntervalToHist( startStamp, endStamp,\ + _PRTopEnv->masterLockLowTimeHist ); \ + addIntervalToHist( startStamp, endStamp,\ + _PRTopEnv->masterLockHighTimeHist ); + + #define MEAS__Print_Hists_for_Master_Lock_Meas \ + printHist( _PRTopEnv->masterLockLowTimeHist ); \ + printHist( _PRTopEnv->masterLockHighTimeHist ); + +#else + #define MEAS__Insert_Master_Lock_Meas_Fields_into_MasterEnv + #define MEAS__Make_Meas_Hists_for_Master_Lock_Meas + #define MEAS__Capture_Pre_Master_Lock_Point + #define MEAS__Capture_Post_Master_Lock_Point + #define MEAS__Print_Hists_for_Master_Lock_Meas +#endif + + +#ifdef MEAS__TURN_ON_MALLOC_MEAS + #define MEAS__Insert_Malloc_Meas_Fields_into_MasterEnv\ + Histogram *mallocTimeHist; \ + Histogram *freeTimeHist; + + #define MEAS__Make_Meas_Hists_for_Malloc_Meas \ + _PRTopEnv->mallocTimeHist = makeFixedBinHistExt( 100, 0, 30,\ + "malloc_time_hist");\ + _PRTopEnv->freeTimeHist = makeFixedBinHistExt( 100, 0, 30,\ + "free_time_hist"); + + #define MEAS__Capture_Pre_Malloc_Point \ + int32 startStamp, endStamp; \ + saveLowTimeStampCountInto( startStamp ); + + #define MEAS__Capture_Post_Malloc_Point \ + saveLowTimeStampCountInto( endStamp ); \ + addIntervalToHist( startStamp, endStamp,\ + _PRTopEnv->mallocTimeHist ); + + #define MEAS__Capture_Pre_Free_Point \ + int32 startStamp, endStamp; \ + saveLowTimeStampCountInto( startStamp ); + + #define MEAS__Capture_Post_Free_Point \ + saveLowTimeStampCountInto( endStamp ); \ + addIntervalToHist( startStamp, endStamp,\ + _PRTopEnv->freeTimeHist ); + + #define MEAS__Print_Hists_for_Malloc_Meas \ + printHist( _PRTopEnv->mallocTimeHist ); \ + saveHistToFile( _PRTopEnv->mallocTimeHist ); \ + printHist( _PRTopEnv->freeTimeHist ); \ + saveHistToFile( _PRTopEnv->freeTimeHist ); \ + freeHistExt( _PRTopEnv->mallocTimeHist ); \ + freeHistExt( _PRTopEnv->freeTimeHist ); + +#else + #define MEAS__Insert_Malloc_Meas_Fields_into_MasterEnv + #define MEAS__Make_Meas_Hists_for_Malloc_Meas + #define MEAS__Capture_Pre_Malloc_Point + #define MEAS__Capture_Post_Malloc_Point + #define MEAS__Capture_Pre_Free_Point + #define MEAS__Capture_Post_Free_Point + #define MEAS__Print_Hists_for_Malloc_Meas +#endif + + + +#ifdef MEAS__TURN_ON_PLUGIN_MEAS + #define MEAS__Insert_Plugin_Meas_Fields_into_MasterEnv \ + Histogram *reqHdlrLowTimeHist; \ + Histogram *reqHdlrHighTimeHist; + + #define MEAS__Make_Meas_Hists_for_Plugin_Meas \ + _PRTopEnv->reqHdlrLowTimeHist = makeFixedBinHistExt( 100, 0, 200,\ + "plugin_low_time_hist");\ + _PRTopEnv->reqHdlrHighTimeHist = makeFixedBinHistExt( 100, 0, 200,\ + "plugin_high_time_hist"); + + #define MEAS__startReqHdlr \ + int32 startStamp1, endStamp1; \ + saveLowTimeStampCountInto( startStamp1 ); + + #define MEAS__endReqHdlr \ + saveLowTimeStampCountInto( endStamp1 ); \ + addIntervalToHist( startStamp1, endStamp1, \ + _PRTopEnv->reqHdlrLowTimeHist ); \ + addIntervalToHist( startStamp1, endStamp1, \ + _PRTopEnv->reqHdlrHighTimeHist ); + + #define MEAS__Print_Hists_for_Plugin_Meas \ + printHist( _PRTopEnv->reqHdlrLowTimeHist ); \ + saveHistToFile( _PRTopEnv->reqHdlrLowTimeHist ); \ + printHist( _PRTopEnv->reqHdlrHighTimeHist ); \ + saveHistToFile( _PRTopEnv->reqHdlrHighTimeHist ); \ + freeHistExt( _PRTopEnv->reqHdlrLowTimeHist ); \ + freeHistExt( _PRTopEnv->reqHdlrHighTimeHist ); +#else + #define MEAS__Insert_Plugin_Meas_Fields_into_MasterEnv + #define MEAS__Make_Meas_Hists_for_Plugin_Meas + #define MEAS__startReqHdlr + #define MEAS__endReqHdlr + #define MEAS__Print_Hists_for_Plugin_Meas + +#endif + + +#ifdef MEAS__TURN_ON_SYSTEM_MEAS + #define MEAS__Insert_System_Meas_Fields_into_Slave \ + TSCountLowHigh startSusp; \ + uint64 totalSuspCycles; \ + uint32 numGoodSusp; + + #define MEAS__Insert_System_Meas_Fields_into_MasterEnv \ + TSCountLowHigh startMaster; \ + uint64 totalMasterCycles; \ + uint32 numMasterAnimations; \ + TSCountLowHigh startReqHdlr; \ + uint64 totalPluginCycles; \ + uint32 numPluginAnimations; \ + uint64 cyclesTillStartAnimationMaster; \ + TSCountLowHigh endAnimationMaster; + + #define MEAS__startAnimationMaster_forSys \ + TSCountLowHigh startStamp1, endStamp1; \ + saveTSCLowHigh( endStamp1 ); \ + _PRTopEnv->cyclesTillStartAnimationMaster = \ + endStamp1.longVal - masterVP->startSusp.longVal; + + #define Meas_startReqHdlr_forSys \ + saveTSCLowHigh( startStamp1 ); \ + _PRTopEnv->startReqHdlr.longVal = startStamp1.longVal; + + #define MEAS__endAnimationMaster_forSys \ + saveTSCLowHigh( startStamp1 ); \ + _PRTopEnv->endAnimationMaster.longVal = startStamp1.longVal; + + /*A TSC is stored in VP first thing inside wrapper-lib + * Now, measures cycles from there to here + * Master and Plugin will add this value to other trace-seg measures + */ + #define MEAS__Capture_End_Susp_in_CoreCtlr_ForSys\ + saveTSCLowHigh(endSusp); \ + numCycles = endSusp.longVal - currVP->startSusp.longVal; \ + /*sanity check (400K is about 20K iters)*/ \ + if( numCycles < 400000 ) \ + { currVP->totalSuspCycles += numCycles; \ + currVP->numGoodSusp++; \ + } \ + /*recorded every time, but only read if currVP == MasterVP*/ \ + _PRTopEnv->startMaster.longVal = endSusp.longVal; + +#else + #define MEAS__Insert_System_Meas_Fields_into_Slave + #define MEAS__Insert_System_Meas_Fields_into_MasterEnv + #define MEAS__Make_Meas_Hists_for_System_Meas + #define MEAS__startAnimationMaster_forSys + #define MEAS__startReqHdlr_forSys + #define MEAS__endAnimationMaster_forSys + #define MEAS__Capture_End_Susp_in_CoreCtlr_ForSys + #define MEAS__Print_Hists_for_System_Meas +#endif + +#ifdef HOLISTIC__TURN_ON_PERF_COUNTERS + + #define MEAS__Insert_Counter_Handler \ + typedef void (*CounterHandler) (int,int,int,SlaveVP*,uint64,uint64,uint64); + + enum eventType { + DebugEvt = 0, + AppResponderInvocation_start, + AppResponder_start, + AppResponder_end, + AssignerInvocation_start, + NextAssigner_start, + Assigner_start, + Assigner_end, + Work_start, + Work_end, + HwResponderInvocation_start, + Timestamp_start, + Timestamp_end + }; + + #define saveCyclesAndInstrs(core,cycles,instrs,cachem) do{ \ + int cycles_fd = _PRTopEnv->cycles_counter_fd[core]; \ + int instrs_fd = _PRTopEnv->instrs_counter_fd[core]; \ + int cachem_fd = _PRTopEnv->cachem_counter_fd[core]; \ + int nread; \ + \ + nread = read(cycles_fd,&(cycles),sizeof(cycles)); \ + if(nread<0){ \ + perror("Error reading cycles counter"); \ + cycles = 0; \ + } \ + \ + nread = read(instrs_fd,&(instrs),sizeof(instrs)); \ + if(nread<0){ \ + perror("Error reading cycles counter"); \ + instrs = 0; \ + } \ + nread = read(cachem_fd,&(cachem),sizeof(cachem)); \ + if(nread<0){ \ + perror("Error reading last level cache miss counter"); \ + cachem = 0; \ + } \ + } while (0) + + #define MEAS__Insert_Counter_Meas_Fields_into_MasterEnv \ + int cycles_counter_fd[NUM_CORES]; \ + int instrs_counter_fd[NUM_CORES]; \ + int cachem_counter_fd[NUM_CORES]; \ + uint64 start_master_lock[NUM_CORES][3]; \ + CounterHandler counterHandler; + + #define HOLISTIC__Setup_Perf_Counters setup_perf_counters(); + + + #define HOLISTIC__CoreCtrl_Setup \ + CounterHandler counterHandler = _PRTopEnv->counterHandler; \ + SlaveVP *lastVPBeforeMaster = NULL; \ + /*if(thisCoresThdParams->coreNum == 0){ \ + uint64 initval = tsc_offset_send(thisCoresThdParams,0); \ + while(!coreCtlrThdParams[NUM_CORES - 2]->ret_tsc); \ + } \ + if(0 < (thisCoresThdParams->coreNum) && (thisCoresThdParams->coreNum) < (NUM_CORES - 1)){ \ + ThdParams* sendCoresThdParams = coreCtlrThdParams[thisCoresThdParams->coreNum - 1]; \ + int sndctr = tsc_offset_resp(sendCoresThdParams, 0); \ + uint64 initval = tsc_offset_send(thisCoresThdParams,0); \ + while(!coreCtlrThdParams[NUM_CORES - 2]->ret_tsc); \ + } \ + if(thisCoresThdParams->coreNum == (NUM_CORES - 1)){ \ + ThdParams* sendCoresThdParams = coreCtlrThdParams[thisCoresThdParams->coreNum - 1]; \ + int sndctr = tsc_offset_resp(sendCoresThdParams,0); \ + }*/ + + + #define HOLISTIC__Insert_Master_Global_Vars \ + int vpid,task; \ + CounterHandler counterHandler = _PRTopEnv->counterHandler; + + #define HOLISTIC__Record_last_work lastVPBeforeMaster = currVP; + + #define HOLISTIC__Record_AppResponderInvocation_start \ + uint64 cycles,instrs,cachem; \ + saveCyclesAndInstrs(thisCoresIdx,cycles, instrs,cachem); \ + if(lastVPBeforeMaster){ \ + (*counterHandler)(AppResponderInvocation_start,lastVPBeforeMaster->slaveNum,lastVPBeforeMaster->numTimesAssignedToASlot,lastVPBeforeMaster,cycles,instrs,cachem); \ + lastVPBeforeMaster = NULL; \ + } else { \ + _PRTopEnv->start_master_lock[thisCoresIdx][0] = cycles; \ + _PRTopEnv->start_master_lock[thisCoresIdx][1] = instrs; \ + _PRTopEnv->start_master_lock[thisCoresIdx][2] = cachem; \ + } + + /* Request Handler may call resume() on the VP, but we want to + * account the whole interval to the same task. Therefore, need + * to save task ID at the beginning. + * + * Using this value as "end of AppResponder Invocation Time" + * is possible if there is only one SchedSlot per core - + * invoking processor is last to be treated here! If more than + * one slot, MasterLoop processing time for all but the last VP + * would be erroneously counted as invocation time. + */ + #define HOLISTIC__Record_AppResponder_start \ + vpid = currSlot->slaveAssignedToSlot->slaveNum; \ + task = currSlot->slaveAssignedToSlot->numTimesAssignedToASlot; \ + uint64 cycles, instrs, cachem; \ + saveCyclesAndInstrs(thisCoresIdx,cycles, instrs,cachem); \ + (*counterHandler)(AppResponder_start,vpid,task,currSlot->slaveAssignedToSlot,cycles,instrs,cachem); + + #define HOLISTIC__Record_AppResponder_end \ + uint64 cycles2,instrs2,cachem2; \ + saveCyclesAndInstrs(thisCoresIdx,cycles2, instrs2,cachem2); \ + (*counterHandler)(AppResponder_end,vpid,task,currSlot->slaveAssignedToSlot,cycles2,instrs2,cachem2); \ + (*counterHandler)(Timestamp_end,vpid,task,currSlot->slaveAssignedToSlot,rdtsc(),0,0); + + + /* Don't know who to account time to yet - goes to assigned VP + * after the call. + */ + #define HOLISTIC__Record_Assigner_start \ + int empty = FALSE; \ + if(currSlot->slaveAssignedToSlot == NULL){ \ + empty= TRUE; \ + } \ + uint64 tmp_cycles, tmp_instrs, tmp_cachem; \ + saveCyclesAndInstrs(thisCoresIdx,tmp_cycles,tmp_instrs,tmp_cachem); \ + uint64 tsc = rdtsc(); \ + if(vpid > 0) { \ + (*counterHandler)(NextAssigner_start,vpid,task,currSlot->slaveAssignedToSlot,tmp_cycles,tmp_instrs,tmp_cachem); \ + vpid = 0; \ + task = 0; \ + } + + #define HOLISTIC__Record_Assigner_end \ + uint64 cycles,instrs,cachem; \ + saveCyclesAndInstrs(thisCoresIdx,cycles,instrs,cachem); \ + if(empty){ \ + (*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]); \ + } \ + (*counterHandler)(Timestamp_start,assignedSlaveVP->slaveNum,assignedSlaveVP->numTimesAssignedToASlot,assignedSlaveVP,tsc,0,0); \ + (*counterHandler)(Assigner_start,assignedSlaveVP->slaveNum,assignedSlaveVP->numTimesAssignedToASlot,assignedSlaveVP,tmp_cycles,tmp_instrs,tmp_cachem); \ + (*counterHandler)(Assigner_end,assignedSlaveVP->slaveNum,assignedSlaveVP->numTimesAssignedToASlot,assignedSlaveVP,cycles,instrs,tmp_cachem); + + #define HOLISTIC__Record_Work_start \ + if(currVP){ \ + uint64 cycles,instrs,cachem; \ + saveCyclesAndInstrs(thisCoresIdx,cycles, instrs,cachem); \ + (*counterHandler)(Work_start,currVP->slaveNum,currVP->numTimesAssignedToASlot,currVP,cycles,instrs,cachem); \ + } + + #define HOLISTIC__Record_Work_end \ + if(currVP){ \ + uint64 cycles,instrs,cachem; \ + saveCyclesAndInstrs(thisCoresIdx,cycles, instrs,cachem); \ + (*counterHandler)(Work_end,currVP->slaveNum,currVP->numTimesAssignedToASlot,currVP,cycles,instrs,cachem); \ + } + + #define HOLISTIC__Record_HwResponderInvocation_start \ + uint64 cycles,instrs,cachem; \ + saveCyclesAndInstrs(animatingSlv->coreAnimatedBy,cycles, instrs,cachem); \ + (*(_PRTopEnv->counterHandler))(HwResponderInvocation_start,animatingSlv->slaveNum,animatingSlv->numTimesAssignedToASlot,animatingSlv,cycles,instrs,cachem); + + + #define getReturnAddressBeforeLibraryCall(vp_ptr, res_ptr) do{ \ +void* frame_ptr0 = vp_ptr->framePtr; \ +void* frame_ptr1 = *((void**)frame_ptr0); \ +void* frame_ptr2 = *((void**)frame_ptr1); \ +void* frame_ptr3 = *((void**)frame_ptr2); \ +void* ret_addr = *((void**)frame_ptr3 + 1); \ +*res_ptr = ret_addr; \ +} while (0) + +#else + #define MEAS__Insert_Counter_Handler + #define MEAS__Insert_Counter_Meas_Fields_into_MasterEnv + #define HOLISTIC__Setup_Perf_Counters + #define HOLISTIC__CoreCtrl_Setup + #define HOLISTIC__Insert_Master_Global_Vars + #define HOLISTIC__Record_last_work + #define HOLISTIC__Record_AppResponderInvocation_start + #define HOLISTIC__Record_AppResponder_start + #define HOLISTIC__Record_AppResponder_end + #define HOLISTIC__Record_Assigner_start + #define HOLISTIC__Record_Assigner_end + #define HOLISTIC__Record_Work_start + #define HOLISTIC__Record_Work_end + #define HOLISTIC__Record_HwResponderInvocation_start + #define getReturnAddressBeforeLibraryCall(vp_ptr, res_ptr) +#endif + +//Experiment in two-step macros -- if doesn't work, insert each separately +#define MEAS__Insert_Meas_Fields_into_Slave \ + MEAS__Insert_Susp_Meas_Fields_into_Slave \ + MEAS__Insert_Master_Meas_Fields_into_Slave \ + MEAS__Insert_System_Meas_Fields_into_Slave + + +//====================== Histogram Macros -- Create ======================== +// +// + +//The language implementation should include a definition of this macro, +// which creates all the histograms the language uses to collect measurements +// of plugin operation -- so, if the language didn't define it, must +// define it here (as empty), to avoid compile error +#ifndef MEAS__Make_Meas_Hists_for_Language +#define MEAS__Make_Meas_Hists_for_Language +#endif + +#define makeAMeasHist( histInfo, idx, name, numBins, startVal, binWidth ) \ + makeHighestDynArrayIndexBeAtLeast( _PRTopEnv->measHistsInfo, idx ); \ + _PRTopEnv->measHists[idx] = \ + makeFixedBinHist( numBins, startVal, binWidth, name ); + +//============================== Probes =================================== + + +//=========================================================================== +#endif /* _PR_DEFS_MEAS_H */ + diff -r 45f7cf8a80eb -r f3cb11baf791 Services_offered_by_PR/prdependency.h --- a/Services_offered_by_PR/prdependency.h Tue Mar 04 12:45:08 2014 -0800 +++ b/Services_offered_by_PR/prdependency.h Fri May 09 11:19:53 2014 +0200 @@ -1,57 +1,57 @@ -/* - * Copyright 2011 OpenSourceResearchInstitute.org - * Licensed under GNU General Public License version 2 - * - * Author: Nina Engelhardt - * - */ - -#ifndef _PRDEPENDENCY_H -#define _PRDEPENDENCY_H - - -#include -#include - -typedef struct { - int vp; - int task; -} Unit; - -typedef struct { - int from_vp; - int from_task; - int to_vp; - int to_task; -} Dependency; - -typedef struct { - int32 id; - ListOfArrays* senders; - ListOfArrays* receivers; -} NtoN; - -FILE* dependency_file; - -Dependency* new_dependency(int from_vp, int from_task, int to_vp, int to_task); - -NtoN* new_NtoN(int id); - -int set_dependency_file(FILE* file); - -void print_ctl_dependency_to_file(void* _dep); - -void print_comm_dependency_to_file(void* _dep); - -void print_dyn_dependency_to_file(void* _dep); - -void print_hw_dependency_to_file(void* _dep); - -void print_dependency_to_file(void* dep); - -void print_unit_to_file(void* unit); - -void print_nton_to_file(void* _nton); - -#endif /* DEPENDENCY_H */ - +/* + * Copyright 2011 OpenSourceResearchInstitute.org + * Licensed under GNU General Public License version 2 + * + * Author: Nina Engelhardt + * + */ + +#ifndef _PRDEPENDENCY_H +#define _PRDEPENDENCY_H + + +#include +#include + +typedef struct { + int vp; + int task; +} Unit; + +typedef struct { + int from_vp; + int from_task; + int to_vp; + int to_task; +} Dependency; + +typedef struct { + int32 id; + ListOfArrays* senders; + ListOfArrays* receivers; +} NtoN; + +FILE* dependency_file; + +Dependency* new_dependency(int from_vp, int from_task, int to_vp, int to_task); + +NtoN* new_NtoN(int id); + +int set_dependency_file(FILE* file); + +void print_ctl_dependency_to_file(void* _dep); + +void print_comm_dependency_to_file(void* _dep); + +void print_dyn_dependency_to_file(void* _dep); + +void print_hw_dependency_to_file(void* _dep); + +void print_dependency_to_file(void* dep); + +void print_unit_to_file(void* unit); + +void print_nton_to_file(void* _nton); + +#endif /* DEPENDENCY_H */ + diff -r 45f7cf8a80eb -r f3cb11baf791 Services_offered_by_PR/probes__wrapper_library.h --- a/Services_offered_by_PR/probes__wrapper_library.h Tue Mar 04 12:45:08 2014 -0800 +++ b/Services_offered_by_PR/probes__wrapper_library.h Fri May 09 11:19:53 2014 +0200 @@ -1,44 +1,44 @@ -/* - * Copyright 2009 OpenSourceStewardshipFoundation.org - * Licensed under GNU General Public License version 2 - * - * Author: seanhalle@yahoo.com - * - */ - -/*NOTE: this file should only be included AFTER some other - * file has defined which kind of probe to use, and whether - * probes are turned on or off.. - * - *In other words, this is a static library that uses macros, - * and there are multiple versions of the same macro.. which - * version gets used depends on #define statements in a - * DIFFERENT file.. (traditionally PR_defs__turn_on_and_off.h) - * - *So, this file relies on #defines that appear in other files, - * which must come first in the sequence of #includes that - * include this one.. - */ - -#ifndef _PROBES_wrapper_library_H -#define _PROBES_wrapper_library_H -#define _GNU_SOURCE - -//========================================================= -// Use only these aliases within application code -//========================================================= - - -#define PR_App__record_time_point_into_new_probe PR_WL__record_time_point_into_new_probe -#define PR_App__create_single_interval_probe PR_WL__create_single_interval_probe -#define PR_App__create_histogram_probe PR_WL__create_histogram_probe -#define PR_App__index_probe_by_its_name PR_WL__index_probe_by_its_name -#define PR_App__get_probe_by_name PR_WL__get_probe_by_name -#define PR_App__record_sched_choice_into_probe PR_WL__record_sched_choice_into_probe -#define PR_App__record_interval_start_in_probe PR_WL__record_interval_start_in_probe -#define PR_App__record_interval_end_in_probe PR_WL__record_interval_end_in_probe -#define PR_App__print_stats_of_probe PR_WL__print_stats_of_probe -#define PR_App__print_stats_of_all_probes PR_WL__print_stats_of_all_probes - -#endif /* top ifndef */ - +/* + * Copyright 2009 OpenSourceStewardshipFoundation.org + * Licensed under GNU General Public License version 2 + * + * Author: seanhalle@yahoo.com + * + */ + +/*NOTE: this file should only be included AFTER some other + * file has defined which kind of probe to use, and whether + * probes are turned on or off.. + * + *In other words, this is a static library that uses macros, + * and there are multiple versions of the same macro.. which + * version gets used depends on #define statements in a + * DIFFERENT file.. (traditionally PR_defs__turn_on_and_off.h) + * + *So, this file relies on #defines that appear in other files, + * which must come first in the sequence of #includes that + * include this one.. + */ + +#ifndef _PROBES_wrapper_library_H +#define _PROBES_wrapper_library_H +#define _GNU_SOURCE + +//========================================================= +// Use only these aliases within application code +//========================================================= + + +#define PR_App__record_time_point_into_new_probe PR_WL__record_time_point_into_new_probe +#define PR_App__create_single_interval_probe PR_WL__create_single_interval_probe +#define PR_App__create_histogram_probe PR_WL__create_histogram_probe +#define PR_App__index_probe_by_its_name PR_WL__index_probe_by_its_name +#define PR_App__get_probe_by_name PR_WL__get_probe_by_name +#define PR_App__record_sched_choice_into_probe PR_WL__record_sched_choice_into_probe +#define PR_App__record_interval_start_in_probe PR_WL__record_interval_start_in_probe +#define PR_App__record_interval_end_in_probe PR_WL__record_interval_end_in_probe +#define PR_App__print_stats_of_probe PR_WL__print_stats_of_probe +#define PR_App__print_stats_of_all_probes PR_WL__print_stats_of_all_probes + +#endif /* top ifndef */ + diff -r 45f7cf8a80eb -r f3cb11baf791 __README__about_dir.txt --- a/__README__about_dir.txt Tue Mar 04 12:45:08 2014 -0800 +++ b/__README__about_dir.txt Fri May 09 11:19:53 2014 +0200 @@ -1,7 +1,7 @@ - -This directory is a copy of /usr/include/PR__include - -It holds the header files that are public, for all the independent libraries created, related to proto-runtime (as of now, just the universal version). - -In particular, the individual repositories do NOT contain these header files! If any of them change these, then the /usr/include/PR__include directory has to be copied to the windows shadow copy, then committed to the repository. - + +This directory is a copy of /usr/include/PR__include + +It holds the header files that are public, for all the independent libraries created, related to proto-runtime (as of now, just the universal version). + +In particular, the individual repositories do NOT contain these header files! If any of them change these, then the /usr/include/PR__include directory has to be copied to the windows shadow copy, then committed to the repository. + diff -r 45f7cf8a80eb -r f3cb11baf791 langlets/PRServ__wrapper_library.h --- a/langlets/PRServ__wrapper_library.h Tue Mar 04 12:45:08 2014 -0800 +++ b/langlets/PRServ__wrapper_library.h Fri May 09 11:19:53 2014 +0200 @@ -1,173 +1,173 @@ -/* - * Copyright 2009-2013 OpenSourceResearchInstitute.org - * Licensed under GNU General Public License version 2 - * - * Author: seanhalle@yahoo.com - * - */ - -#ifndef _PRServ_wrapper_library_H -#define _PRServ_wrapper_library_H - -#include - - -//=========================================================================== -typedef void (*PtrToAtomicFn ) ( void * ); //executed atomically in master - -typedef struct _DKUPiece DKUPiece; -typedef struct _DKUInstance DKUInstance; - -typedef void (*DKUKernel ) ( void *, SlaveVP * ); //used as task birth Fn -typedef void (*DKUSerialKernel ) ( void *, SlaveVP * ); //used as task birth Fn -typedef void (*DKUDivider ) ( DKUPiece * ); -typedef void (*DKUUndivider ) ( DKUPiece * ); - -typedef DKUPiece * (*DKURootPieceMaker) ( void *, DKUInstance * ); - -struct _DKUInstance - { - DKURootPieceMaker rootPieceMaker; - DKUKernel kernel; - DKUSerialKernel serialKernel; - DKUDivider divider; - DKUUndivider undivider; - }; - -struct _DKUPiece - { - void *payload; - int32 dataFootprint; //Kbytes of cache space used by piece -- set by root piece maker and then by divider - DKUPiece *parent; - DKUPiece **children; - int32 childFootprint; //set as suggestion by PR, reset by divider - int32 numChildren; //set as suggestion by PR, reset by divider - int32 numUnfinishedChildren; - DKUInstance *dkuInstance; //to get kernel and undivider - void *undividerInfo; //divider communicates to undivider - SlaveVP *waitingVP; - bool32 wasRecursivelyDivided; - }; - - - - - - - - -/*WARNING: assembly hard-codes position of endInstrAddr as first field - */ -typedef struct - { - void *endInstrAddr; - int32 hasBeenStarted; - int32 hasFinished; - PrivQueueStruc *waitQ; - } -PRServSingleton; - - -//=========================================================================== - -int32 -PRServ__giveMinWorkUnitCycles( float32 percentOverhead ); - -void -PRServ__begin_primitive(); - -int32 -PRServ__end_primitive_and_give_cycles(); - -int32 -PRServ__giveIdealNumWorkUnits(); - -int32 -PRServ__give_number_of_cores_to_schedule_onto(); - -char * -PRServ___give_environment_string(); - -//======================= - -void -PRServ__end_seedVP( SlaveVP *seedSlv ); -//======================= - -inline int32 * -PRServ__create_taskID_of_size( int32 numInts, SlaveVP *animSlv ); - -//========================= -void -PRServ__taskwait(SlaveVP *animSlv); - -inline int32 * -PRServ__give_self_taskID( SlaveVP *animSlv ); - -//======================= Concurrency Stuff ====================== -void -PRServ__start_fn_singleton( int32 singletonID, SlaveVP *animSlv ); - -void -PRServ__end_fn_singleton( int32 singletonID, SlaveVP *animSlv ); - -void -PRServ__start_data_singleton( PRServSingleton **singeltonAddr, SlaveVP *animSlv ); - -void -PRServ__end_data_singleton( PRServSingleton **singletonAddr, SlaveVP *animSlv ); - -void -PRServ__animate_short_fn_in_isolation( PtrToAtomicFn ptrToFnToExecInMaster, - void *data, SlaveVP *animSlv ); - -void -PRServ__start_transaction( int32 transactionID, SlaveVP *animSlv ); - -void -PRServ__end_transaction( int32 transactionID, SlaveVP *animSlv ); - -//============================== DKU ============================= -DKUInstance * -PRServ__DKU_make_empty_DKU_instance( SlaveVP *animSlv ); - -DKUPiece * -PRServ__DKU_make_empty_DKU_piece(); - -DKUPiece * -PRServ__DKU_make_child_piece_from( DKUPiece *pieceToDivide ); - -void -PRServ__DKU_set_root_piece_maker( DKUInstance *dkuInstance, - DKURootPieceMaker rootPieceMakerFn, - SlaveVP *animSlv ); -void -PRServ__DKU_set_kernel( DKUInstance *dkuInstance, - DKUKernel kernelFn, - SlaveVP *animSlv ); -void -PRServ__DKU_set_serial_kernel( DKUInstance *dkuInstance, - DKUSerialKernel serialKernelFn, - SlaveVP *animSlv ); -void -PRServ__DKU_set_divider( DKUInstance *dkuInstance, - DKUDivider dividerFn, - SlaveVP *animSlv ); -void -PRServ__DKU_set_undivider( DKUInstance *dkuInstance, - DKUUndivider undividerFn, - SlaveVP *animSlv ); -DKUPiece * -PRServ__DKU_make_root_piece( DKUInstance *dkuInstance, - void *data, - SlaveVP *animSlv ); -void -PRServ__DKU_perform_work_on( DKUPiece *rootPiece, - SlaveVP *animSlv ); -void -PRServ__DKU_wait_for_result_to_be_complete( DKUPiece *rootPiece, - SlaveVP *animSlv ); - -//=========================================================================== -#endif /* _PRServ_H */ - +/* + * Copyright 2009-2013 OpenSourceResearchInstitute.org + * Licensed under GNU General Public License version 2 + * + * Author: seanhalle@yahoo.com + * + */ + +#ifndef _PRServ_wrapper_library_H +#define _PRServ_wrapper_library_H + +#include + + +//=========================================================================== +typedef void (*PtrToAtomicFn ) ( void * ); //executed atomically in master + +typedef struct _DKUPiece DKUPiece; +typedef struct _DKUInstance DKUInstance; + +typedef void (*DKUKernel ) ( void *, SlaveVP * ); //used as task birth Fn +typedef void (*DKUSerialKernel ) ( void *, SlaveVP * ); //used as task birth Fn +typedef void (*DKUDivider ) ( DKUPiece * ); +typedef void (*DKUUndivider ) ( DKUPiece * ); + +typedef DKUPiece * (*DKURootPieceMaker) ( void *, DKUInstance * ); + +struct _DKUInstance + { + DKURootPieceMaker rootPieceMaker; + DKUKernel kernel; + DKUSerialKernel serialKernel; + DKUDivider divider; + DKUUndivider undivider; + }; + +struct _DKUPiece + { + void *payload; + int32 dataFootprint; //Kbytes of cache space used by piece -- set by root piece maker and then by divider + DKUPiece *parent; + DKUPiece **children; + int32 childFootprint; //set as suggestion by PR, reset by divider + int32 numChildren; //set as suggestion by PR, reset by divider + int32 numUnfinishedChildren; + DKUInstance *dkuInstance; //to get kernel and undivider + void *undividerInfo; //divider communicates to undivider + SlaveVP *waitingVP; + bool32 wasRecursivelyDivided; + }; + + + + + + + + +/*WARNING: assembly hard-codes position of endInstrAddr as first field + */ +typedef struct + { + void *endInstrAddr; + int32 hasBeenStarted; + int32 hasFinished; + PrivQueueStruc *waitQ; + } +PRServSingleton; + + +//=========================================================================== + +int32 +PRServ__giveMinWorkUnitCycles( float32 percentOverhead ); + +void +PRServ__begin_primitive(); + +int32 +PRServ__end_primitive_and_give_cycles(); + +int32 +PRServ__giveIdealNumWorkUnits(); + +int32 +PRServ__give_number_of_cores_to_schedule_onto(); + +char * +PRServ___give_environment_string(); + +//======================= + +void +PRServ__end_seedVP( SlaveVP *seedSlv ); +//======================= + +__inline int32 * +PRServ__create_taskID_of_size( int32 numInts, SlaveVP *animSlv ); + +//========================= +void +PRServ__taskwait(SlaveVP *animSlv); + +__inline int32 * +PRServ__give_self_taskID( SlaveVP *animSlv ); + +//======================= Concurrency Stuff ====================== +void +PRServ__start_fn_singleton( int32 singletonID, SlaveVP *animSlv ); + +void +PRServ__end_fn_singleton( int32 singletonID, SlaveVP *animSlv ); + +void +PRServ__start_data_singleton( PRServSingleton **singeltonAddr, SlaveVP *animSlv ); + +void +PRServ__end_data_singleton( PRServSingleton **singletonAddr, SlaveVP *animSlv ); + +void +PRServ__animate_short_fn_in_isolation( PtrToAtomicFn ptrToFnToExecInMaster, + void *data, SlaveVP *animSlv ); + +void +PRServ__start_transaction( int32 transactionID, SlaveVP *animSlv ); + +void +PRServ__end_transaction( int32 transactionID, SlaveVP *animSlv ); + +//============================== DKU ============================= +DKUInstance * +PRServ__DKU_make_empty_DKU_instance( SlaveVP *animSlv ); + +DKUPiece * +PRServ__DKU_make_empty_DKU_piece(); + +DKUPiece * +PRServ__DKU_make_child_piece_from( DKUPiece *pieceToDivide ); + +void +PRServ__DKU_set_root_piece_maker( DKUInstance *dkuInstance, + DKURootPieceMaker rootPieceMakerFn, + SlaveVP *animSlv ); +void +PRServ__DKU_set_kernel( DKUInstance *dkuInstance, + DKUKernel kernelFn, + SlaveVP *animSlv ); +void +PRServ__DKU_set_serial_kernel( DKUInstance *dkuInstance, + DKUSerialKernel serialKernelFn, + SlaveVP *animSlv ); +void +PRServ__DKU_set_divider( DKUInstance *dkuInstance, + DKUDivider dividerFn, + SlaveVP *animSlv ); +void +PRServ__DKU_set_undivider( DKUInstance *dkuInstance, + DKUUndivider undividerFn, + SlaveVP *animSlv ); +DKUPiece * +PRServ__DKU_make_root_piece( DKUInstance *dkuInstance, + void *data, + SlaveVP *animSlv ); +void +PRServ__DKU_perform_work_on( DKUPiece *rootPiece, + SlaveVP *animSlv ); +void +PRServ__DKU_wait_for_result_to_be_complete( DKUPiece *rootPiece, + SlaveVP *animSlv ); + +//=========================================================================== +#endif /* _PRServ_H */ + diff -r 45f7cf8a80eb -r f3cb11baf791 langlets/prdsl_wrapper_library.h --- a/langlets/prdsl_wrapper_library.h Tue Mar 04 12:45:08 2014 -0800 +++ b/langlets/prdsl_wrapper_library.h Fri May 09 11:19:53 2014 +0200 @@ -1,93 +1,93 @@ -/* - * Copyright 2009 OpenSourceResearchInstitute.org - * Licensed under GNU General Public License version 2 - * - * Author: seanhalle@yahoo.com - * - */ - -#ifndef _PRDSL_WRAPPER_H -#define _PRDSL_WRAPPER_H - -#include - -//=========================================================================== - //uniquely identifies PRDSL -- should be a jenkins char-hash of "PRDSL" to int32 -#define PRDSL_MAGIC_NUMBER 0000000004 - -typedef struct _PRDSLTaskStub PRDSLTaskStub; - -//=========================================================================== - -/*This is PRDSL's "lang meta task" - *See the proto-runtime wiki entry to learn about "lang meta task" - *In essence, this holds all the meta information that PRDSL needs about a task - */ -struct _PRDSLTaskStub - { - void **args; //given to the birth Fn - int32 numBlockingProp; - PrivQueueStruc *dependentTasksQ; - bool32 isActive; //active after done adding propendents - bool32 canBeAProp; - - PRDSLTaskStub *parentTaskStub; //for liveness, for the wait construct - int32 numLiveChildTasks; - int32 numLiveChildVPs; - bool32 isWaitingForChildTasksToEnd; - bool32 isWaitingForChildThreadsToEnd; - bool32 isEnded; - -// int32 *taskID; //is in PRMetaTask, in prolog - }; - - -//======================= - -void -PRDSL__start( SlaveVP *seedSlv ); - -void -PRDSL__shutdown( SlaveVP *seedSlv ); - -void -PRDSL__wait_for_all_PRDSL_created_work_to_end( SlaveVP *seedSlv ); - -//======================= - -SlaveVP * -PRDSL__create_thread( BirthFnPtr fnPtr, void *initData, - SlaveVP *creatingThd ); - -void -PRDSL__end_thread( SlaveVP *thdToEnd ); - -//======================= - -#define PRDSL__malloc( numBytes, callingSlave ) PR_App__malloc( numBytes, callingSlave) - -#define PRDSL__free(ptrToFree, callingSlave ) PR_App__free( ptrToFree, callingSlave ) - - -//======================= -PRDSLTaskStub * -PRDSL__create_task_ready_to_run( BirthFnPtr birthFn, void *args, SlaveVP *animSlv); - -//inline int32 * -//PRDSL__create_taskID_of_size( int32 numInts, SlaveVP *animSlv ); - - -void -PRDSL__end_task( SlaveVP *animSlv ); - -//========================= -void -PRDSL__taskwait(SlaveVP *animSlv); - - -inline int32 * -PRDSL__give_self_taskID( SlaveVP *animSlv ); - -//=========================================================================== -#endif - +/* + * Copyright 2009 OpenSourceResearchInstitute.org + * Licensed under GNU General Public License version 2 + * + * Author: seanhalle@yahoo.com + * + */ + +#ifndef _PRDSL_WRAPPER_H +#define _PRDSL_WRAPPER_H + +#include + +//=========================================================================== + //uniquely identifies PRDSL -- should be a jenkins char-hash of "PRDSL" to int32 +#define PRDSL_MAGIC_NUMBER 0000000004 + +typedef struct _PRDSLTaskStub PRDSLTaskStub; + +//=========================================================================== + +/*This is PRDSL's "lang meta task" + *See the proto-runtime wiki entry to learn about "lang meta task" + *In essence, this holds all the meta information that PRDSL needs about a task + */ +struct _PRDSLTaskStub + { + void **args; //given to the birth Fn + int32 numBlockingProp; + PrivQueueStruc *dependentTasksQ; + bool32 isActive; //active after done adding propendents + bool32 canBeAProp; + + PRDSLTaskStub *parentTaskStub; //for liveness, for the wait construct + int32 numLiveChildTasks; + int32 numLiveChildVPs; + bool32 isWaitingForChildTasksToEnd; + bool32 isWaitingForChildThreadsToEnd; + bool32 isEnded; + +// int32 *taskID; //is in PRMetaTask, in prolog + }; + + +//======================= + +void +PRDSL__start( SlaveVP *seedSlv ); + +void +PRDSL__shutdown( SlaveVP *seedSlv ); + +void +PRDSL__wait_for_all_PRDSL_created_work_to_end( SlaveVP *seedSlv ); + +//======================= + +SlaveVP * +PRDSL__create_thread( BirthFnPtr fnPtr, void *initData, + SlaveVP *creatingThd ); + +void +PRDSL__end_thread( SlaveVP *thdToEnd ); + +//======================= + +#define PRDSL__malloc( numBytes, callingSlave ) PR_App__malloc( numBytes, callingSlave) + +#define PRDSL__free(ptrToFree, callingSlave ) PR_App__free( ptrToFree, callingSlave ) + + +//======================= +PRDSLTaskStub * +PRDSL__create_task_ready_to_run( BirthFnPtr birthFn, void *args, SlaveVP *animSlv); + +//inline int32 * +//PRDSL__create_taskID_of_size( int32 numInts, SlaveVP *animSlv ); + + +void +PRDSL__end_task( SlaveVP *animSlv ); + +//========================= +void +PRDSL__taskwait(SlaveVP *animSlv); + + +inline int32 * +PRDSL__give_self_taskID( SlaveVP *animSlv ); + +//=========================================================================== +#endif + diff -r 45f7cf8a80eb -r f3cb11baf791 langlets/vreo_wrapper_library.h --- a/langlets/vreo_wrapper_library.h Tue Mar 04 12:45:08 2014 -0800 +++ b/langlets/vreo_wrapper_library.h Fri May 09 11:19:53 2014 +0200 @@ -10,41 +10,63 @@ #define _VREO_WRAPPER_H #include - +#include //uniquely identifies VSs -- should be a jenkins char-hash of "VSs" to int32 #define VReo_MAGIC_NUMBER 0000000003 //=========================================================================== typedef struct _VReoIsland VReoIsland; +typedef struct _VReoO1island VReoO1island; +typedef struct _VReoBridge VReoBridge; +typedef struct _VReoPartnerQStruct VReoPartnerQStruct; typedef bool32 (*VReoCheckerFn ) ( VReoIsland * ); typedef void (*VReoDoerFn ) ( VReoIsland * ); +typedef void (*VReoO1islandDoerFn) (VReoO1island *, VReoBridge*, VReoBridge*); //chg to list of bridges //=========================================================================== +typedef enum + { None = 0, + Island, + O1island, + VP + } +VReoRWType; -typedef struct +struct _VReoBridge { void *buffer; - bool32 portIsFull; + bool32 bridgeIsFull; SlaveVP *waitingReaderVP; //doubles as flag SlaveVP *waitingWriterVP; - void *reader; //either island or VP - void *writer; //either island or VP - + void *reader; //island, o1island, or VP + VReoRWType readerType; + void *writer; //island, o1island, or VP + VReoRWType writerType; + + //============ For Islands ============= int32 numReaderCheckerFns; - VReoCheckerFn *readerCheckerFns; //checkers triggered when port state changes + VReoCheckerFn *readerCheckerFns; //checkers triggered when bridge state changes VReoDoerFn *readerDoerFns; //corresponding doer functions int32 numWriterCheckerFns; - VReoCheckerFn *writerCheckerFns; //checkers triggered when port state changes - VReoDoerFn *writerDoerFns; //corresponding doer functions - } -VReoPort; - + VReoCheckerFn *writerCheckerFns; //checkers triggered when bridge state changes + VReoDoerFn *writerDoerFns; //corresponding doer functions + + //============ For O1islands ============= + VReoPartnerQStruct *readerPartnerQStruct; + VReoPartnerQStruct *writerPartnerQStruct; + //these queues are pointed to by partnerQStructs in other bridges + //the bridge is placed into these queues when no partner is found + PrivQueueStruc *readerOfferQ; + PrivQueueStruc *writerOfferQ; + }; +//VReoBridge + struct _VReoIsland { - int32 numPorts; - VReoPort **ports; //array of pointers to port structs + int32 numBridges; + VReoBridge **bridges; //array of pointers to bridge structs int32 numCheckerFns; VReoCheckerFn *checkerFns; //checkers triggered when state changes @@ -54,6 +76,33 @@ }; //VReoIsland + +struct _VReoO1island + { + int32 numBridges; + VReoBridge **bridges; //array of pointers to bridge structs + +// VReoO1islandCheckerFn checkerFn; //checker triggered when state changes +// VReoO1islandDoerFn *doerFns; //corresponding doer functions + + //During search, have to save last Q checked inside each node of + // Qstruct.. + }; +//VReoO1island + +/*This is expected to change in future.. just quick and simple to get + * first version of optimization working. In particular, the way the + * doer functions are handled should change. Not clear how to handle them + * at this point. + */ +struct _VReoPartnerQStruct + { + int32 numQs; + PrivQueueStruc **partnerQs; //array of partner Qs, hold bridge ptrs + VReoO1islandDoerFn *doerFns; //array of ptrs to doer Fns + }; +//VReoPartnerQStruct + typedef struct _VReoListElem VReoListElem; struct _VReoListElem @@ -65,13 +114,16 @@ typedef struct { - int32 numPorts; // - VReoPort *ports; //array of port structs - VReoPort **boundaryPorts; + int32 numBridges; // + VReoBridge *bridges; //array of bridge structs + VReoBridge **boundaryBridges; int32 numIslands; VReoIsland *islands; //array of island structs -- no pointers + int32 numO1islands; + VReoO1island *o1islands; //array of O1island structs -- no pointers + int32 numVPs; VReoListElem *VPs; @@ -106,10 +158,10 @@ //======================= void -VReo__put_into_port( void *itemToPut, VReoPort *port, SlaveVP *callingVP ); +VReo__put_into_bridge( void *itemToPut, VReoBridge *bridge, SlaveVP *callingVP ); void * -VReo__get_from_port( VReoPort *port, SlaveVP *callingVP ); +VReo__get_from_bridge( VReoBridge *bridge, SlaveVP *callingVP ); @@ -120,6 +172,12 @@ void VReo__end_VP( SlaveVP *VPToEnd ); +//================ For use by generated circuit code ================= +void +o1islandReadBridgeToWrittenBridgeDoer( VReoO1island *o1island, + VReoBridge *readBridge, VReoBridge *writtenBridge ); + + //=========================================================================== #endif /* _VReo_H */ diff -r 45f7cf8a80eb -r f3cb11baf791 osportability.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/osportability.h Fri May 09 11:19:53 2014 +0200 @@ -0,0 +1,39 @@ +#ifndef __OS_PORTABILITY_H__ +#define __OS_PORTABILITY_H__ + +#ifdef _WIN32 + +#define VC_EXTRALEAN +#define WIN32_LEAN_AND_MEAN + +#include +#include + +#include +#include + +#define cpu_set_t DWORD_PTR +#define PR_int__malloc malloc +#define PR_int__free free + +__inline int32 __sync_bool_compare_and_swap(volatile int32* destination, int32 newval, int32 oldval) +{ + /* + #ifdef _WIN32 + gotLock = (int)(UNLOCKED && InterlockedCompareExchange((volatile unsigned long long*) addrOfMasterLock, (long long)LOCKED, (long long)UNLOCKED)); + #else + */ + return (int32)(oldval == InterlockedCompareExchange((volatile unsigned long long*) destination, (long long)newval, (long long)oldval)); +} + +#define pthread_yield sched_yield + + + +#else // GNU + +#include +#include + +#endif // _WIN32 +#endif // __OS_PORTABILITY_H__ \ No newline at end of file diff -r 45f7cf8a80eb -r f3cb11baf791 prdynarray.h --- a/prdynarray.h Tue Mar 04 12:45:08 2014 -0800 +++ b/prdynarray.h Fri May 09 11:19:53 2014 +0200 @@ -1,91 +1,91 @@ -/* - * File: Vector.h - * Author: Me - * - * Created on May 14, 2010, 3:08 PM - */ - -#ifndef _DYNARRAY_H -#define _DYNARRAY_H - -#include - - - -/*WARNING: Passing a DynArray as a param is dangerous if add to the DynArray - * inside the function called! After adding or other operation that might - * change the size, must re-read the addr of the chunk of memory that is the - * array, via the DynArrayInfo. - *Here's why: An array variable is a location, either on the stack - * or in a field of a struct, whose contents is an addr. That addr is of the - * first location of a chunk of locations. The DynArray works by changing - * the chunk of locations, then modifying the contents of the original - * array variable. It overwrites the addr of the old chunk of locations - * with the addr of the new chunk. - *But when the array variable is passed as a parameter, such as - * in this: "foo( myDynArray )", then there are now two locations that hold - * the addr of the same chunk of locations. So when a call is made that - * adds to the DynArray, and inside the DynArray expands, it only updates - * the original location with the new addr. Hence, the function will begin - * overwriting memory past the end of the old chunk, because it still has - * the pointer to the old chunk of locations. - * - *A dynamic array is accessed same as any other array. However, must use - * dyn array calls, defined in here, in order to add or increase the size. - * Must re-read the original array variable after any size-changing calls. - *To pass a DynArray as a parameter to a function, can only pass the - * DynArrayInfo, then inside the function, to read the addr of the first - * location in the chunk of locations that is the array, do this: - * "localArrayCopy = *(myDynArrayInfo->addrOfPtrToArray). After that, can - * treat localArrayCopy as a normal array, as long as don't make any calls - * that add or otherwise could increase the size of the array. If do make - * such a call, then re-copy the array via the above. Can then use the - * copy up until another add to the array. - * - */ -typedef struct - { - void ***addrOfPtrToArray; //addr of var that is array of ptrs == triple * - int32 numInArray; //num entries added - int32 sizeOfArray; //num elems alloc'd - int32 sizeOfElem; //num bytes in one elem of array -- used in 2nd version - } -PrivDynArrayInfo; - -PrivDynArrayInfo * -makePrivDynArrayInfoFrom( void ***addrOfPtrToArray, int32 sizeOfArray ); - -PrivDynArrayInfo * -makePrivDynArrayOfSize( void ***addrOfPtrToArray, int32 sizeOfArray ); - -PrivDynArrayInfo * -makePrivDynArrayOfSize_Ext( void ***addrOfPtrToArray, int32 sizeOfArray ); - -int32 -addToDynArray( void *value, PrivDynArrayInfo *info ); - -void -makeHighestDynArrayIndexBe( PrivDynArrayInfo *info, int32 highestIndex ); - -void -makeHighestDynArrayIndexBeAtLeast(PrivDynArrayInfo *info,int32 highestIndex); - -void -increaseSizeOfDynArrayTo( PrivDynArrayInfo *info, int32 newSize ); - -typedef void (*FreeFnPtr) ( void * ); //fn has to cast void * to whatever - -void -freeDynArrayDeep( PrivDynArrayInfo *info, FreeFnPtr freeFnPtr ); - -void -freeDynArrayFlat( PrivDynArrayInfo *info ); - - -typedef void (*DynArrayFnPtr) ( void * ); //fn has to cast void * - -void -forAllInDynArrayDo( PrivDynArrayInfo *info, DynArrayFnPtr fnPtr ); - -#endif /* _DYNARRAY_H */ - +/* + * File: Vector.h + * Author: Me + * + * Created on May 14, 2010, 3:08 PM + */ + +#ifndef _DYNARRAY_H +#define _DYNARRAY_H + +#include + + + +/*WARNING: Passing a DynArray as a param is dangerous if add to the DynArray + * inside the function called! After adding or other operation that might + * change the size, must re-read the addr of the chunk of memory that is the + * array, via the DynArrayInfo. + *Here's why: An array variable is a location, either on the stack + * or in a field of a struct, whose contents is an addr. That addr is of the + * first location of a chunk of locations. The DynArray works by changing + * the chunk of locations, then modifying the contents of the original + * array variable. It overwrites the addr of the old chunk of locations + * with the addr of the new chunk. + *But when the array variable is passed as a parameter, such as + * in this: "foo( myDynArray )", then there are now two locations that hold + * the addr of the same chunk of locations. So when a call is made that + * adds to the DynArray, and inside the DynArray expands, it only updates + * the original location with the new addr. Hence, the function will begin + * overwriting memory past the end of the old chunk, because it still has + * the pointer to the old chunk of locations. + * + *A dynamic array is accessed same as any other array. However, must use + * dyn array calls, defined in here, in order to add or increase the size. + * Must re-read the original array variable after any size-changing calls. + *To pass a DynArray as a parameter to a function, can only pass the + * DynArrayInfo, then inside the function, to read the addr of the first + * location in the chunk of locations that is the array, do this: + * "localArrayCopy = *(myDynArrayInfo->addrOfPtrToArray). After that, can + * treat localArrayCopy as a normal array, as long as don't make any calls + * that add or otherwise could increase the size of the array. If do make + * such a call, then re-copy the array via the above. Can then use the + * copy up until another add to the array. + * + */ +typedef struct + { + void ***addrOfPtrToArray; //addr of var that is array of ptrs == triple * + int32 numInArray; //num entries added + int32 sizeOfArray; //num elems alloc'd + int32 sizeOfElem; //num bytes in one elem of array -- used in 2nd version + } +PrivDynArrayInfo; + +PrivDynArrayInfo * +makePrivDynArrayInfoFrom( void ***addrOfPtrToArray, int32 sizeOfArray ); + +PrivDynArrayInfo * +makePrivDynArrayOfSize( void ***addrOfPtrToArray, int32 sizeOfArray ); + +PrivDynArrayInfo * +makePrivDynArrayOfSize_Ext( void ***addrOfPtrToArray, int32 sizeOfArray ); + +int32 +addToDynArray( void *value, PrivDynArrayInfo *info ); + +void +makeHighestDynArrayIndexBe( PrivDynArrayInfo *info, int32 highestIndex ); + +void +makeHighestDynArrayIndexBeAtLeast(PrivDynArrayInfo *info,int32 highestIndex); + +void +increaseSizeOfDynArrayTo( PrivDynArrayInfo *info, int32 newSize ); + +typedef void (*FreeFnPtr) ( void * ); //fn has to cast void * to whatever + +void +freeDynArrayDeep( PrivDynArrayInfo *info, FreeFnPtr freeFnPtr ); + +void +freeDynArrayFlat( PrivDynArrayInfo *info ); + + +typedef void (*DynArrayFnPtr) ( void * ); //fn has to cast void * + +void +forAllInDynArrayDo( PrivDynArrayInfo *info, DynArrayFnPtr fnPtr ); + +#endif /* _DYNARRAY_H */ + diff -r 45f7cf8a80eb -r f3cb11baf791 prhash.h --- a/prhash.h Tue Mar 04 12:45:08 2014 -0800 +++ b/prhash.h Fri May 09 11:19:53 2014 +0200 @@ -1,96 +1,96 @@ -/* - * Copyright 2009 OpenSourceResearchInstitute.org - * Licensed under GNU General Public License version 2 - * - * Author: seanhalle@yahoo.com - */ - -#ifndef _PRHASH_H -#define _PRHASH_H - -#include -#include -#include -#include - -#include - -//===================== defines ===================== -#define TRUE 1 -#define FALSE 0 - -#define DEFAULT_HASH_TABLE_SIZE 1 << 10 -#define DEFAULT_POWER_OF_2_TABLE_SIZE 10 - - -//===================== structs ===================== -union hashkey_t{ - char hashable[8]; - int32 parts[2]; -}; - -typedef union hashkey_t hashkey_t; - -typedef struct _HashEntry HashEntry; - -struct _HashEntry - { - char *key; - void *content; - HashEntry *next; - }; - -typedef void (*FreeEntryContentFnPtr) ( void * ); - -typedef struct - { int32 tableSz; - int32 numEntries; - HashEntry* *entries; - int32 hashMask; - int32 prevHash; - FreeEntryContentFnPtr freeEntryContentFn; - } -HashTable; - - -//=========================================================================== -// Public functions -HashTable *makeHashTable( int numHashSlots, FreeEntryContentFnPtr freeFn ); - -int32 putEntryIntoTable( HashEntry *entry, HashTable *table); -int32 addValueIntoTable( char* key, void *value, HashTable *table); -HashEntry *getEntryFromTable( char *key, HashTable *table ); -void *getValueFromTable( char *key, HashTable *table ); - -bool8 deleteEntryFromTable( char *key, HashTable *table ); -bool8 deleteThisEntryFromTable( HashEntry *entry, HashTable *table ); -bool8 deleteEntrysValueInTable( char *key, HashTable *table ); -bool8 deleteEntryFromTableAndFreeValue( char *key, HashTable *table ); -void freeHashTable( HashTable *table ); -//char *paramBagToString( ParamBag * bag ) - -//================= Same Fns, but for 32b array key hash fn ================ -HashTable *makeHashTable32(int32 powerOf2OfSz, FreeEntryContentFnPtr freeFn); -HashTable *makeDefaultSizeHashTable32( FreeEntryContentFnPtr freeFn ); - -int32 putEntryIntoTable32( HashEntry *entry, HashTable *table); -HashEntry *addValueIntoTable32( uint32 key[], void *value, HashTable *table); -HashEntry *getEntryFromTable32( uint32 key[], HashTable *table ); -void *getValueFromTable32( uint32 key[], HashTable *table ); - -bool32 deleteEntryFromTable32( uint32 key[], HashTable *table ); - -//=========================================================================== -// Internal functions -void freeHashEntryUsing( HashEntry *entry, HashTable *table ); -unsigned int hashThisKey( char *s, int hashSz ); -void nullOutTablesArray( HashTable *table ); -void doubleTableSize( HashTable *table ); -void freeHashEntryButNotContent( HashEntry *entry ); - -uint32 -jenkHash32( const uint32 *key, /* array of uint32 values */ - int32 length); /* num uint32 in the key */ - -#endif /* _PRIVATE_HASH_H */ - +/* + * Copyright 2009 OpenSourceResearchInstitute.org + * Licensed under GNU General Public License version 2 + * + * Author: seanhalle@yahoo.com + */ + +#ifndef _PRHASH_H +#define _PRHASH_H + +#include +#include +#include +#include + +#include + +//===================== defines ===================== +#define TRUE 1 +#define FALSE 0 + +#define DEFAULT_HASH_TABLE_SIZE 1 << 10 +#define DEFAULT_POWER_OF_2_TABLE_SIZE 10 + + +//===================== structs ===================== +union hashkey_t{ + char hashable[8]; + int32 parts[2]; +}; + +typedef union hashkey_t hashkey_t; + +typedef struct _HashEntry HashEntry; + +struct _HashEntry + { + char *key; + void *content; + HashEntry *next; + }; + +typedef void (*FreeEntryContentFnPtr) ( void * ); + +typedef struct + { int32 tableSz; + int32 numEntries; + HashEntry* *entries; + int32 hashMask; + int32 prevHash; + FreeEntryContentFnPtr freeEntryContentFn; + } +HashTable; + + +//=========================================================================== +// Public functions +HashTable *makeHashTable( int numHashSlots, FreeEntryContentFnPtr freeFn ); + +int32 putEntryIntoTable( HashEntry *entry, HashTable *table); +int32 addValueIntoTable( char* key, void *value, HashTable *table); +HashEntry *getEntryFromTable( char *key, HashTable *table ); +void *getValueFromTable( char *key, HashTable *table ); + +bool8 deleteEntryFromTable( char *key, HashTable *table ); +bool8 deleteThisEntryFromTable( HashEntry *entry, HashTable *table ); +bool8 deleteEntrysValueInTable( char *key, HashTable *table ); +bool8 deleteEntryFromTableAndFreeValue( char *key, HashTable *table ); +void freeHashTable( HashTable *table ); +//char *paramBagToString( ParamBag * bag ) + +//================= Same Fns, but for 32b array key hash fn ================ +HashTable *makeHashTable32(int32 powerOf2OfSz, FreeEntryContentFnPtr freeFn); +HashTable *makeDefaultSizeHashTable32( FreeEntryContentFnPtr freeFn ); + +int32 putEntryIntoTable32( HashEntry *entry, HashTable *table); +HashEntry *addValueIntoTable32( uint32 key[], void *value, HashTable *table); +HashEntry *getEntryFromTable32( uint32 key[], HashTable *table ); +void *getValueFromTable32( uint32 key[], HashTable *table ); + +bool32 deleteEntryFromTable32( uint32 key[], HashTable *table ); + +//=========================================================================== +// Internal functions +void freeHashEntryUsing( HashEntry *entry, HashTable *table ); +unsigned int hashThisKey( char *s, int hashSz ); +void nullOutTablesArray( HashTable *table ); +void doubleTableSize( HashTable *table ); +void freeHashEntryButNotContent( HashEntry *entry ); + +uint32 +jenkHash32( const uint32 *key, /* array of uint32 values */ + int32 length); /* num uint32 in the key */ + +#endif /* _PRIVATE_HASH_H */ + diff -r 45f7cf8a80eb -r f3cb11baf791 prhistogram.h --- a/prhistogram.h Tue Mar 04 12:45:08 2014 -0800 +++ b/prhistogram.h Fri May 09 11:19:53 2014 +0200 @@ -1,102 +1,102 @@ -/* - * Copyright 2010 OpenSourceResearchInstitute.org - * Licensed under GNU General Public License version 2 - * - * Author: seanhalle@yahoo.com - * - */ - - -#ifndef _PRHISTOGRAM_H -#define _PRHISTOGRAM_H - -#include -#include - - -typedef struct - { - char *name; - int32 startOfRange; - int32 endOfRange; - int32 numBins; - int32 binWidth; - int32 *bins; - } -Histogram; - -typedef struct - { - float32 startOfRange; - float32 endOfRange; - int32 numBins; - float32 binWidth; - int32 *bins; - } -FloatHist; - -typedef struct - { - float64 startOfRange; - float64 endOfRange; - int32 numBins; - float64 binWidth; - int32 *bins; - } -DblHist; - -Histogram * -makeHistogram( int32 numBins, int32 startOfRange, int32 endOfRange ); - -Histogram * -makeFixedBinHist( int32 numBins, int32 startOfRange, int32 binWidth, - char *name ); - -Histogram * -makeFixedBinHistExt( int32 numBins, int32 startOfRange, int32 binWidth, - char *name ); - -void inline -addToHist( int32 value, Histogram *hist ); - -void inline -addIntervalToHist( uint32 startIntvl, uint32 endIntvl, Histogram *hist ); - -void inline -subIntervalFromHist( int32 startIntvl, int32 endIntvl, Histogram *hist ); - -void -saveHistToFile(Histogram *hist); - -void -printHist( Histogram *hist ); - -FloatHist * -makeFloatHistogram( int numBins, float32 startOfRange, float32 binWidth ); - -void -addToFloatHist( float32 value, FloatHist *hist ); - -void -printFloatHist( FloatHist *hist ); - -void -freeHistExt( Histogram *hist ); - -void -freeHist( Histogram *hist ); - -DblHist * -makeDblHistogram( int numBins, float64 startOfRange, float64 binWidth ); - -void -addToDblHist( float64 value, DblHist *hist ); - -void -printDblHist( DblHist *hist ); - -void -freeDblHist( DblHist *hist ); - -#endif /* _HISTOGRAM_H */ - +/* + * Copyright 2010 OpenSourceResearchInstitute.org + * Licensed under GNU General Public License version 2 + * + * Author: seanhalle@yahoo.com + * + */ + + +#ifndef _PRHISTOGRAM_H +#define _PRHISTOGRAM_H + +#include +#include + + +typedef struct + { + char *name; + int32 startOfRange; + int32 endOfRange; + int32 numBins; + int32 binWidth; + int32 *bins; + } +Histogram; + +typedef struct + { + float32 startOfRange; + float32 endOfRange; + int32 numBins; + float32 binWidth; + int32 *bins; + } +FloatHist; + +typedef struct + { + float64 startOfRange; + float64 endOfRange; + int32 numBins; + float64 binWidth; + int32 *bins; + } +DblHist; + +Histogram * +makeHistogram( int32 numBins, int32 startOfRange, int32 endOfRange ); + +Histogram * +makeFixedBinHist( int32 numBins, int32 startOfRange, int32 binWidth, + char *name ); + +Histogram * +makeFixedBinHistExt( int32 numBins, int32 startOfRange, int32 binWidth, + char *name ); + +__inline void +addToHist( int32 value, Histogram *hist ); + +__inline void +addIntervalToHist( uint32 startIntvl, uint32 endIntvl, Histogram *hist ); + +__inline void +subIntervalFromHist( int32 startIntvl, int32 endIntvl, Histogram *hist ); + +void +saveHistToFile(Histogram *hist); + +void +printHist( Histogram *hist ); + +FloatHist * +makeFloatHistogram( int numBins, float32 startOfRange, float32 binWidth ); + +void +addToFloatHist( float32 value, FloatHist *hist ); + +void +printFloatHist( FloatHist *hist ); + +void +freeHistExt( Histogram *hist ); + +void +freeHist( Histogram *hist ); + +DblHist * +makeDblHistogram( int numBins, float64 startOfRange, float64 binWidth ); + +void +addToDblHist( float64 value, DblHist *hist ); + +void +printDblHist( DblHist *hist ); + +void +freeDblHist( DblHist *hist ); + +#endif /* _HISTOGRAM_H */ + diff -r 45f7cf8a80eb -r f3cb11baf791 prlistofarrays.h --- a/prlistofarrays.h Tue Mar 04 12:45:08 2014 -0800 +++ b/prlistofarrays.h Fri May 09 11:19:53 2014 +0200 @@ -1,67 +1,67 @@ -/* - * File: ListOfArrays.h - * Author: Nina Engelhardt - * - * Created on December 16, 2011, 2:06 PM - */ - -#ifndef _LISTOFARRAYS_H -#define _LISTOFARRAYS_H - -#include -#include - -#include -#include - - -typedef struct { - void* next; - void* data; -} ArrayFragment; - -typedef struct { - void** dim1; - PrivDynArrayInfo* dim1info; - //ArrayFragment* last; - size_t entry_size; - int num_entries_per_fragment; - int next_free_index; -} ListOfArrays; - -ListOfArrays* makeListOfArrays(size_t entry_size, int num_entries_per_block); - -#define addToListOfArrays(type,value,list) do { \ - int offset_in_fragment = list->next_free_index % list->num_entries_per_fragment; \ - if(offset_in_fragment == 0){ \ - void* newBlock = PR__malloc(list->entry_size * list->num_entries_per_fragment); \ - addToDynArray(newBlock,list->dim1info); \ - } \ - type* typedFragment = (type*) ((list->dim1)[list->dim1info->numInArray -1]); \ - typedFragment[offset_in_fragment] = value; \ - list->next_free_index++; \ -} while (0) - -#define addToListOfArrays_ext(type,value,list) do { \ - int offset_in_fragment = list->next_free_index % list->num_entries_per_fragment; \ - if(offset_in_fragment == 0){ \ - void* newBlock = malloc(list->entry_size * list->num_entries_per_fragment); \ - addToDynArray(newBlock,list->dim1info); \ - } \ - type* typedFragment = (type*) ((list->dim1)[list->dim1info->numInArray -1]); \ - typedFragment[offset_in_fragment] = value; \ - list->next_free_index++; \ -} while (0) - -typedef void (*ListOfArraysFnPtr) ( void * ); //fn has to cast void * - -void forAllInListOfArraysDo(ListOfArrays* list, ListOfArraysFnPtr fnPtr); - -#define valueInListOfArrays(type,index,list) ((type*)((list->dim1)[index / list->num_entries_per_fragment]))[index % list->num_entries_per_fragment] - -#define setValueInListOfArrays(type,index,value,list) ((type*)((list->dim1)[index / list->num_entries_per_fragment]))[index % list->num_entries_per_fragment] = value - -void freeListOfArrays(ListOfArrays* list); - -#endif /* LISTOFARRAYS_H */ - +/* + * File: ListOfArrays.h + * Author: Nina Engelhardt + * + * Created on December 16, 2011, 2:06 PM + */ + +#ifndef _LISTOFARRAYS_H +#define _LISTOFARRAYS_H + +#include +#include + +#include +#include + + +typedef struct { + void* next; + void* data; +} ArrayFragment; + +typedef struct { + void** dim1; + PrivDynArrayInfo* dim1info; + //ArrayFragment* last; + size_t entry_size; + int num_entries_per_fragment; + int next_free_index; +} ListOfArrays; + +ListOfArrays* makeListOfArrays(size_t entry_size, int num_entries_per_block); + +#define addToListOfArrays(type,value,list) do { \ + int offset_in_fragment = list->next_free_index % list->num_entries_per_fragment; \ + if(offset_in_fragment == 0){ \ + void* newBlock = PR__malloc(list->entry_size * list->num_entries_per_fragment); \ + addToDynArray(newBlock,list->dim1info); \ + } \ + type* typedFragment = (type*) ((list->dim1)[list->dim1info->numInArray -1]); \ + typedFragment[offset_in_fragment] = value; \ + list->next_free_index++; \ +} while (0) + +#define addToListOfArrays_ext(type,value,list) do { \ + int offset_in_fragment = list->next_free_index % list->num_entries_per_fragment; \ + if(offset_in_fragment == 0){ \ + void* newBlock = malloc(list->entry_size * list->num_entries_per_fragment); \ + addToDynArray(newBlock,list->dim1info); \ + } \ + type* typedFragment = (type*) ((list->dim1)[list->dim1info->numInArray -1]); \ + typedFragment[offset_in_fragment] = value; \ + list->next_free_index++; \ +} while (0) + +typedef void (*ListOfArraysFnPtr) ( void * ); //fn has to cast void * + +void forAllInListOfArraysDo(ListOfArrays* list, ListOfArraysFnPtr fnPtr); + +#define valueInListOfArrays(type,index,list) ((type*)((list->dim1)[index / list->num_entries_per_fragment]))[index % list->num_entries_per_fragment] + +#define setValueInListOfArrays(type,index,value,list) ((type*)((list->dim1)[index / list->num_entries_per_fragment]))[index % list->num_entries_per_fragment] = value + +void freeListOfArrays(ListOfArrays* list); + +#endif /* LISTOFARRAYS_H */ + diff -r 45f7cf8a80eb -r f3cb11baf791 prmalloc.h --- a/prmalloc.h Tue Mar 04 12:45:08 2014 -0800 +++ b/prmalloc.h Fri May 09 11:19:53 2014 +0200 @@ -1,52 +1,52 @@ -/* - * Copyright 2009 OpenSourceCodeStewardshipFoundation.org - * Licensed under GNU General Public License version 2 - * - * Author: seanhalle@yahoo.com - * - * Created on November 14, 2009, 9:07 PM - */ - -#ifndef _PRMALLOC_H -#define _PRMALLOC_H - -#include -#include -#include -#include - -void * -PR_int__malloc( size_t sizeRequested ); - -void * -PR_int__malloc_aligned( size_t sizeRequested ); - -void -PR_int__free( void *ptrToFree ); - -//Use these in application code directly -#define \ -PR__malloc PR_WL__malloc - -#define \ -PR__free PR_WL__free - -//these are implemented in the PR leaf implementation -void * -PR_WL__malloc( int32 sizeRequested ); - -void -PR_WL__free( void *ptrToFree ); - - -/*Allocates memory from the external system -- higher overhead - */ -void * -PR_ext__malloc_in_ext( size_t sizeRequested ); - -/*Frees memory that was allocated in the external system -- higher overhead - */ -void -PR_ext__free_in_ext( void *ptrToFree ); - +/* + * Copyright 2009 OpenSourceCodeStewardshipFoundation.org + * Licensed under GNU General Public License version 2 + * + * Author: seanhalle@yahoo.com + * + * Created on November 14, 2009, 9:07 PM + */ + +#ifndef _PRMALLOC_H +#define _PRMALLOC_H + +#include +#include +#include +#include + +void * +PR_int__malloc( size_t sizeRequested ); + +void * +PR_int__malloc_aligned( size_t sizeRequested ); + +void +PR_int__free( void *ptrToFree ); + +//Use these in application code directly +#define \ +PR__malloc PR_WL__malloc + +#define \ +PR__free PR_WL__free + +//these are implemented in the PR leaf implementation +void * +PR_WL__malloc( int32 sizeRequested ); + +void +PR_WL__free( void *ptrToFree ); + + +/*Allocates memory from the external system -- higher overhead + */ +void * +PR_ext__malloc_in_ext( size_t sizeRequested ); + +/*Frees memory that was allocated in the external system -- higher overhead + */ +void +PR_ext__free_in_ext( void *ptrToFree ); + #endif \ No newline at end of file diff -r 45f7cf8a80eb -r f3cb11baf791 prparam.h --- a/prparam.h Tue Mar 04 12:45:08 2014 -0800 +++ b/prparam.h Fri May 09 11:19:53 2014 +0200 @@ -1,59 +1,59 @@ -/* - * - * Author: SeanHalle@yahoo.com - * - * Created on November 19, 2009, 6:30 PM - */ - -#ifndef _PARAM_H -#define _PARAM_H - -#include - - -typedef -struct - { int type; - int intValue; - char * strValue; - float floatValue; - } -ParamStruc; - -#define INT_PARAM_TYPE 0 -#define STRING_PARAM_TYPE 1 -#define FLOAT_PARAM_TYPE 2 - -#define PARAM_BAG_HASHSIZE 1024 - -typedef struct _ParamBagHashEntry ParamBagHashEntry; - -struct _ParamBagHashEntry - { - char *key; - ParamStruc *param; - struct _ParamBagHashEntry *next; - } -/*ParamBagHashEntry*/; - - -typedef -struct - { int bagSz; - ParamBagHashEntry* *entries; - } -ParamBag; - - -ParamBag *makeParamBag(); -void readParamFileIntoBag( char *paramFileName, ParamBag * bag ); -ParamStruc *getParamFromBag( char *key, ParamBag * bag ); -int addParamToBag( char* key, ParamStruc *param, ParamBag *bag ); -void freeParamBag( ParamBag *bag ); -//char *paramBagToString( ParamBag * bag ); -ParamStruc *makeParamStruc(); -ParamStruc *makeParamFromStrs( char * type, char *value ); -ssize_t getline( char **lineptr, size_t *n, FILE *stream ); - -#endif /* _PARAM_H */ - +/* + * + * Author: SeanHalle@yahoo.com + * + * Created on November 19, 2009, 6:30 PM + */ + +#ifndef _PARAM_H +#define _PARAM_H + +#include + + +typedef +struct + { int type; + int intValue; + char * strValue; + float floatValue; + } +ParamStruc; + +#define INT_PARAM_TYPE 0 +#define STRING_PARAM_TYPE 1 +#define FLOAT_PARAM_TYPE 2 + +#define PARAM_BAG_HASHSIZE 1024 + +typedef struct _ParamBagHashEntry ParamBagHashEntry; + +struct _ParamBagHashEntry + { + char *key; + ParamStruc *param; + struct _ParamBagHashEntry *next; + } +/*ParamBagHashEntry*/; + + +typedef +struct + { int bagSz; + ParamBagHashEntry* *entries; + } +ParamBag; + + +ParamBag *makeParamBag(); +void readParamFileIntoBag( char *paramFileName, ParamBag * bag ); +ParamStruc *getParamFromBag( char *key, ParamBag * bag ); +int addParamToBag( char* key, ParamStruc *param, ParamBag *bag ); +void freeParamBag( ParamBag *bag ); +//char *paramBagToString( ParamBag * bag ); +ParamStruc *makeParamStruc(); +ParamStruc *makeParamFromStrs( char * type, char *value ); +ssize_t getline( char **lineptr, size_t *n, FILE *stream ); + +#endif /* _PARAM_H */ + diff -r 45f7cf8a80eb -r f3cb11baf791 prqueue.h --- a/prqueue.h Tue Mar 04 12:45:08 2014 -0800 +++ b/prqueue.h Fri May 09 11:19:53 2014 +0200 @@ -1,114 +1,116 @@ -/* - * Copyright 2009 OpenSourceResearchInstitute.org - * Licensed under GNU General Public License version 2 - * - * Author: seanhalle@yahoo.com - */ - -#ifndef _PRQUEUE_H -#define _PRQUEUE_H - -#include -#include - -#define TRUE 1 -#define FALSE 0 - -//================== Private Queue stuff =================== -/* It is the data that is shared so only need one mutex. */ -typedef struct - { void **insertPos; - void **extractPos; - void **startOfData; //data is pointers - void **endOfData; //set when alloc data - } -PrivQueueStruc; - -typedef void (*DynArrayFnPtr) ( void * ); //fn has to cast void * - -PrivQueueStruc* makePrivQ ( ); -bool32 isEmptyPrivQ ( PrivQueueStruc *Q ); //ret TRUE if empty -void* peekPrivQ ( PrivQueueStruc *Q ); //ret NULL if empty -void* readPrivQ ( PrivQueueStruc *Q ); //ret NULL if empty -void writePrivQ( void *in, PrivQueueStruc *Q ); - //return false when full -bool32 writeIfSpacePrivQ( void * in, PrivQueueStruc* Q ); -int32 numInPrivQ( PrivQueueStruc *Q ); -void pushPrivQ( void * in, PrivQueueStruc* Q ); -void freePrivQ( PrivQueueStruc *Q ); - - -//====================== Parallel Queue Stuff ==================== - -//========== pThreads based queue ========== -/* It is the data that is shared so only need one mutex. */ -typedef -struct - { pthread_mutex_t mutex_t; - pthread_cond_t cond_w_t; - pthread_cond_t cond_r_t; - int32 count; - int32 readPos; - int32 writePos; - void* data[1024]; //an array of pointers - int w_empty; - int w_full; - } -PThdQueueStruc; - -PThdQueueStruc* makePThdQ(); -void* readPThdQ( PThdQueueStruc *Q ); -void writePThdQ( void *in, PThdQueueStruc *Q ); - - -//========== CAS based queue ========== -typedef -struct - { volatile int32 insertLock; - volatile int32 extractLock; - volatile void* *insertPos; - volatile void* *extractPos; - void* startOfData[1024]; //data is pointers - void* *endOfData; //set when make queue - } -CASQueueStruc; - -CASQueueStruc* makeCASQ(); -void* readCASQ( CASQueueStruc *Q ); -void writeCASQ( void *in, CASQueueStruc *Q ); - - -//========= non-atomic instr based queue =========== -typedef -struct - { void* *insertPos; - void* *extractPos; - void* startOfData[1024]; //data is pointers - void* *endOfData; //set when make queue - } -SRSWQueueStruc; - -SRSWQueueStruc* makeSRSWQ(); -void freeSRSWQ( SRSWQueueStruc* Q ); -void* readSRSWQ( SRSWQueueStruc *Q ); -void writeSRSWQ( void *in, SRSWQueueStruc *Q ); - - -//========= non-atomic instr S R M W queue =========== -typedef -struct - { int32 lastQReadFrom; - int32 numInternalQs; - int32 internalQsSz; - SRSWQueueStruc* *internalQs; - } -SRMWQueueStruc; - -SRMWQueueStruc* makeSRMWQ(); -int addWriterToSRMWQ( SRMWQueueStruc *Q ); -void* readSRMWQ( SRMWQueueStruc *Q ); -void writeSRMWQ( void *in, SRMWQueueStruc *Q, int writerID ); - - -#endif /* _PRIVATE_QUEUE_H */ - +/* + * Copyright 2009 OpenSourceResearchInstitute.org + * Licensed under GNU General Public License version 2 + * + * Author: seanhalle@yahoo.com + */ + +#ifndef _PRQUEUE_H +#define _PRQUEUE_H + +#include +//#include //Part of pthreads-win32, needed for type definitions +#include + +#define TRUE 1 +#define FALSE 0 + +//================== Private Queue stuff =================== +/* It is the data that is shared so only need one mutex. */ +typedef struct _PrivQueueStruc + { void **insertPos; + void **extractPos; + void **startOfData; //data is pointers + void **endOfData; //set when alloc data + } +PrivQueueStruc; + +typedef void (*DynArrayFnPtr) ( void * ); //fn has to cast void * + +PrivQueueStruc* makePrivQ ( ); +bool32 isEmptyPrivQ ( PrivQueueStruc *Q ); //ret TRUE if empty +void* peekPrivQ ( PrivQueueStruc *Q ); //ret NULL if empty +void* readPrivQ ( PrivQueueStruc *Q ); //ret NULL if empty +void writePrivQ( void *in, PrivQueueStruc *Q ); + //return false when full +bool32 writeIfSpacePrivQ( void * in, PrivQueueStruc* Q ); +int32 numInPrivQ( PrivQueueStruc *Q ); +void pushPrivQ( void * in, PrivQueueStruc* Q ); +void freePrivQ( PrivQueueStruc *Q ); + + +//====================== Parallel Queue Stuff ==================== + +//========== pThreads based queue ========== +/* It is the data that is shared so only need one mutex. */ +typedef +struct _PThdQueueStruc + { + pthread_mutex_t mutex_t; + pthread_cond_t cond_w_t; + pthread_cond_t cond_r_t; + int32 count; + int32 readPos; + int32 writePos; + void* data[1024]; //an array of pointers + int w_empty; + int w_full; + } +PThdQueueStruc; + +PThdQueueStruc* makePThdQ(); +void* readPThdQ( PThdQueueStruc *Q ); +void writePThdQ( void *in, PThdQueueStruc *Q ); + + +//========== CAS based queue ========== +typedef +struct _CASQueueStruc + { volatile int32 insertLock; + volatile int32 extractLock; + volatile void* *insertPos; + volatile void* *extractPos; + void* startOfData[1024]; //data is pointers + void* *endOfData; //set when make queue + } +CASQueueStruc; + +CASQueueStruc* makeCASQ(); +void* readCASQ( CASQueueStruc *Q ); +void writeCASQ( void *in, CASQueueStruc *Q ); + + +//========= non-atomic instr based queue =========== +typedef +struct _SRSWQueueStruc + { void* *insertPos; + void* *extractPos; + void* startOfData[1024]; //data is pointers + void* *endOfData; //set when make queue + } +SRSWQueueStruc; + +SRSWQueueStruc* makeSRSWQ(); +void freeSRSWQ( SRSWQueueStruc* Q ); +void* readSRSWQ( SRSWQueueStruc *Q ); +void writeSRSWQ( void *in, SRSWQueueStruc *Q ); + + +//========= non-atomic instr S R M W queue =========== +typedef +struct _SRMWQueueStruc + { int32 lastQReadFrom; + int32 numInternalQs; + int32 internalQsSz; + SRSWQueueStruc* *internalQs; + } +SRMWQueueStruc; + +SRMWQueueStruc* makeSRMWQ(); +int addWriterToSRMWQ( SRMWQueueStruc *Q ); +void* readSRMWQ( SRMWQueueStruc *Q ); +void writeSRMWQ( void *in, SRMWQueueStruc *Q, int writerID ); + + +#endif /* _PRIVATE_QUEUE_H */ +