# HG changeset patch # User Sean Halle # Date 1362246859 28800 # Node ID 7ab0d5bf16cb9f57736bf176dab4c2689d7fd14e # Parent 43b0a2585dc32a072d7099e00ce75dc746a8ef2d Compiles and runs, up to end of process, working on end process and shutdown diff -r 43b0a2585dc3 -r 7ab0d5bf16cb Services_Offered_by_PR/Measurement_and_Stats/MEAS__Counter_Recording.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Services_Offered_by_PR/Measurement_and_Stats/MEAS__Counter_Recording.c Sat Mar 02 09:54:19 2013 -0800 @@ -0,0 +1,156 @@ +/* + * + * author: Nina Engelhardt + */ + +#include "PR_MEAS__Counter_Recording.h" +#include "PR_impl/PR.h" +//#include "../PRServ.h" + +#ifdef HOLISTIC__TURN_ON_PERF_COUNTERS + +void +PR_MEAS__init_counter_data_structs_for_Lang( SlaveVP *slave, int32 magicNum ) + { + PRServLangEnv *langEnv = + (PRServLangEnv *)PR_SS__give_lang_env_for_slave( slave, magicNum ); + int i; + for(i=0;icounterList[i] = makeListOfArrays(sizeof(CounterEvent), 128); + } + } + +/*Pass file by side effect.. + *The reason is that using doAllInListOfArrays, to which one passes the pointer + * to a function, which is then applied to all the elements.. but, that fn + * can only take one input -- the element from the list of arrays.. so, it + * can't also be passed the file.. hence pass the file by side effect + * + *However, multiple cores could be trying to do this.. so, create a separate + * lock just for counters, and acquire that when set the file, then release + * once all the printing is done. + */ +void +PR_MEAS__set_counter_file(FILE* f) + { + acquire counter lock + counterfile = f; + } + +PR_MEAS__release_counter_file() + { + release counter lock + } + +void +PR_MEAS__addToListOfArraysCounterEvent(CounterEvent value, ListOfArrays* list) + { + 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); + } + CounterEvent* typedFragment = (CounterEvent*) ((list->dim1)[list->dim1info->numInArray -1]); + typedFragment[offset_in_fragment] = value; + list->next_free_index++; + } + +void +PR_MEAS__counter_handler(int evt_type, int vpid, int task, SlaveVP* pr, uint64 cycles, uint64 instrs) + { + if (pr->typeOfVP == Master_VP || pr->typeOfVP == ShutdownVP) + { //Only save values for application work, done in a SlaveVP + return; + } + + //Note: have made many changes without compiler flag turned on, nor test.. + PRLangEnv *langEnv = + PR_int__give_proto_lang_env_from_slave( pr, magicNum); + + CounterEvent e; + e.event_type = evt_type; + e.vp = vpid; + e.task = task; + + e.cycles = cycles; + e.instrs = instrs; + + if(pr) + { e.coreID = pr->coreAnimatedBy; + e.slot = pr->animSlotAssignedTo; + } + else + { e.coreID = -1; + e.slot = NULL; + } + + int corenum; + + if(pr) + corenum = pr->coreAnimatedBy; + else + return; + + if(evt_type==Work_start || evt_type==Work_end || evt_type==AppResponderInvocation_start) + { addToListOfArrays_ext(CounterEvent,e,langEnv->counterList[corenum]); + } + else + { PR_MEAS__addToListOfArraysCounterEvent(e,langEnv->counterList[corenum]); + } + } + + + +void +PR_MEAS__print_counter_event_to_file( void* _e ) + { + CounterEvent* e = (CounterEvent*) _e; + fprintf(counterfile, "event, "); + switch(e->event_type) + { + case AppResponderInvocation_start: + fprintf(counterfile, "AppResponderInvocation_start"); + break; + case AppResponder_start: + fprintf(counterfile, "AppResponder_start"); + break; + case AppResponder_end: + fprintf(counterfile, "AppResponder_end"); + break; + case AssignerInvocation_start: + fprintf(counterfile, "AssignerInvocation_start"); + break; + case NextAssigner_start: + fprintf(counterfile, "NextAssigner_start"); + break; + case Assigner_start: + fprintf(counterfile, "Assigner_start"); + break; + case Assigner_end: + fprintf(counterfile, "Assigner_end"); + break; + case Work_end: + fprintf(counterfile, "Work_end"); + break; + case Work_start: + fprintf(counterfile, "Work_start"); + break; + case HwResponderInvocation_start: + fprintf(counterfile, "HwResponderInvocation_start"); + break; + case Timestamp_start: + fprintf(counterfile, "Timestamp_start"); + break; + case Timestamp_end: + fprintf(counterfile, "Timestamp_end"); + break; + default: + fprintf(counterfile, "unknown event"); + } + fprintf(counterfile,", %d, %d, %llu, %llu",e->vp,e->task,e->cycles,e->instrs); + if(e->coreID >=0) + fprintf(counterfile,", %d",e->coreID); + fprintf(counterfile,"\n"); + fflush(counterfile); + } +#endif diff -r 43b0a2585dc3 -r 7ab0d5bf16cb Services_Offered_by_PR/Measurement_and_Stats/MEAS__Counter_Recording.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Services_Offered_by_PR/Measurement_and_Stats/MEAS__Counter_Recording.h Sat Mar 02 09:54:19 2013 -0800 @@ -0,0 +1,36 @@ +/* + * File: PR_MEAS__Counter_Recording.h + * Author: nengel + * + * Created on January 11, 2012, 3:03 PM + */ + +#ifndef PR_MEAS__COUNTER_RECORDING_H +#define PR_MEAS__COUNTER_RECORDING_H + +#include "PR_impl/PR.h" + +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 PR_MEAS__init_counter_data_structs_for_lang( SlaveVP *slv, int32 magicNum ); + +void PR_MEAS__counter_handler(int evt_type, int vpid, int task, SlaveVP* pr, uint64 cycles, uint64 instrs); + +void PR_MEAS__set_counter_file(FILE* f); + +void PR_MEAS__print_counter_event_to_file( void* _e ); +#endif /* PRServ_COUNTER_RECORDING_H */ +