changeset 275:7ab0d5bf16cb Dev_ML

Compiles and runs, up to end of process, working on end process and shutdown
author Sean Halle <seanhalle@yahoo.com>
date Sat, 02 Mar 2013 09:54:19 -0800
parents 43b0a2585dc3
children 1d7ea1b0f176
files Services_Offered_by_PR/Measurement_and_Stats/MEAS__Counter_Recording.c Services_Offered_by_PR/Measurement_and_Stats/MEAS__Counter_Recording.h
diffstat 2 files changed, 192 insertions(+), 0 deletions(-) [+]
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/Services_Offered_by_PR/Measurement_and_Stats/MEAS__Counter_Recording.c	Sat Mar 02 09:54:19 2013 -0800
     1.3 @@ -0,0 +1,156 @@
     1.4 +/*
     1.5 + * 
     1.6 + * author: Nina Engelhardt
     1.7 + */
     1.8 +
     1.9 +#include "PR_MEAS__Counter_Recording.h"
    1.10 +#include "PR_impl/PR.h"
    1.11 +//#include "../PRServ.h"
    1.12 +
    1.13 +#ifdef HOLISTIC__TURN_ON_PERF_COUNTERS
    1.14 +
    1.15 +void 
    1.16 +PR_MEAS__init_counter_data_structs_for_Lang( SlaveVP *slave, int32 magicNum )
    1.17 + {
    1.18 +   PRServLangEnv *langEnv = 
    1.19 +                (PRServLangEnv *)PR_SS__give_lang_env_for_slave( slave, magicNum );
    1.20 +   int i;
    1.21 +   for(i=0;i<NUM_CORES;i++)
    1.22 +    { langEnv->counterList[i] = makeListOfArrays(sizeof(CounterEvent), 128);
    1.23 +    }
    1.24 + }
    1.25 +
    1.26 +/*Pass file by side effect..
    1.27 + *The reason is that using doAllInListOfArrays, to which one passes the pointer
    1.28 + * to a function, which is then applied to all the elements..  but, that fn
    1.29 + * can only take one input -- the element from the list of arrays..  so, it
    1.30 + * can't also be passed the file..  hence pass the file by side effect
    1.31 + * 
    1.32 + *However, multiple cores could be trying to do this..  so, create a separate
    1.33 + * lock just for counters, and acquire that when set the file, then release
    1.34 + * once all the printing is done.
    1.35 + */
    1.36 +void 
    1.37 +PR_MEAS__set_counter_file(FILE* f)
    1.38 + {
    1.39 +   acquire counter lock
    1.40 +   counterfile = f;
    1.41 + }
    1.42 +
    1.43 +PR_MEAS__release_counter_file()
    1.44 + {
    1.45 +   release counter lock
    1.46 + }
    1.47 +
    1.48 +void 
    1.49 +PR_MEAS__addToListOfArraysCounterEvent(CounterEvent value, ListOfArrays* list)
    1.50 + {
    1.51 +   int offset_in_fragment = list->next_free_index % list->num_entries_per_fragment; 
    1.52 +   if(offset_in_fragment == 0)
    1.53 +    { void* newBlock = malloc(list->entry_size * list->num_entries_per_fragment); 
    1.54 +     addToDynArray(newBlock,list->dim1info); 
    1.55 +    } 
    1.56 +   CounterEvent* typedFragment = (CounterEvent*) ((list->dim1)[list->dim1info->numInArray -1]); 
    1.57 +   typedFragment[offset_in_fragment] = value; 
    1.58 +   list->next_free_index++; 
    1.59 + }
    1.60 +
    1.61 +void 
    1.62 +PR_MEAS__counter_handler(int evt_type, int vpid, int task, SlaveVP* pr, uint64 cycles, uint64 instrs)
    1.63 + {
    1.64 +   if (pr->typeOfVP == Master_VP || pr->typeOfVP == ShutdownVP)
    1.65 +    { //Only save values for application work, done in a SlaveVP
    1.66 +      return;
    1.67 +    }
    1.68 +
    1.69 +   //Note: have made many changes without compiler flag turned on, nor test..
    1.70 +   PRLangEnv *langEnv = 
    1.71 +      PR_int__give_proto_lang_env_from_slave( pr, magicNum);
    1.72 +
    1.73 +   CounterEvent e;
    1.74 +   e.event_type = evt_type;
    1.75 +   e.vp = vpid;
    1.76 +   e.task = task;
    1.77 +
    1.78 +   e.cycles = cycles;
    1.79 +   e.instrs = instrs;
    1.80 +
    1.81 +   if(pr)
    1.82 +    { e.coreID = pr->coreAnimatedBy;
    1.83 +      e.slot = pr->animSlotAssignedTo;
    1.84 +    } 
    1.85 +   else 
    1.86 +    { e.coreID = -1;
    1.87 +      e.slot = NULL;
    1.88 +    }
    1.89 +
    1.90 +   int corenum;
    1.91 +
    1.92 +   if(pr) 
    1.93 +      corenum = pr->coreAnimatedBy; 
    1.94 +   else 
    1.95 +      return; 
    1.96 +
    1.97 +   if(evt_type==Work_start || evt_type==Work_end || evt_type==AppResponderInvocation_start)
    1.98 +    { addToListOfArrays_ext(CounterEvent,e,langEnv->counterList[corenum]);
    1.99 +    } 
   1.100 +   else 
   1.101 +    { PR_MEAS__addToListOfArraysCounterEvent(e,langEnv->counterList[corenum]);
   1.102 +    }
   1.103 + }
   1.104 +
   1.105 +
   1.106 +
   1.107 +void 
   1.108 +PR_MEAS__print_counter_event_to_file( void* _e )
   1.109 + {
   1.110 +   CounterEvent* e = (CounterEvent*) _e;
   1.111 +   fprintf(counterfile, "event, ");
   1.112 +   switch(e->event_type)
   1.113 +    {
   1.114 +      case AppResponderInvocation_start:
   1.115 +          fprintf(counterfile, "AppResponderInvocation_start");
   1.116 +          break;
   1.117 +      case AppResponder_start:
   1.118 +          fprintf(counterfile, "AppResponder_start");
   1.119 +          break;
   1.120 +      case AppResponder_end:
   1.121 +          fprintf(counterfile, "AppResponder_end");
   1.122 +          break;
   1.123 +      case AssignerInvocation_start:
   1.124 +          fprintf(counterfile, "AssignerInvocation_start");
   1.125 +          break;
   1.126 +      case NextAssigner_start:
   1.127 +          fprintf(counterfile, "NextAssigner_start");
   1.128 +          break;
   1.129 +      case Assigner_start:
   1.130 +          fprintf(counterfile, "Assigner_start");
   1.131 +          break;
   1.132 +      case Assigner_end:
   1.133 +          fprintf(counterfile, "Assigner_end");
   1.134 +          break;
   1.135 +      case Work_end:
   1.136 +          fprintf(counterfile, "Work_end");
   1.137 +          break;
   1.138 +      case Work_start:
   1.139 +          fprintf(counterfile, "Work_start");
   1.140 +          break;
   1.141 +      case HwResponderInvocation_start:
   1.142 +          fprintf(counterfile, "HwResponderInvocation_start");
   1.143 +          break;
   1.144 +      case Timestamp_start:
   1.145 +          fprintf(counterfile, "Timestamp_start");
   1.146 +          break;
   1.147 +      case Timestamp_end:
   1.148 +          fprintf(counterfile, "Timestamp_end");
   1.149 +          break;
   1.150 +      default:
   1.151 +          fprintf(counterfile, "unknown event");
   1.152 +    }
   1.153 +   fprintf(counterfile,", %d, %d, %llu, %llu",e->vp,e->task,e->cycles,e->instrs);
   1.154 +   if(e->coreID >=0)
   1.155 +   fprintf(counterfile,", %d",e->coreID);
   1.156 +   fprintf(counterfile,"\n");
   1.157 +   fflush(counterfile);
   1.158 + }
   1.159 +#endif
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/Services_Offered_by_PR/Measurement_and_Stats/MEAS__Counter_Recording.h	Sat Mar 02 09:54:19 2013 -0800
     2.3 @@ -0,0 +1,36 @@
     2.4 +/* 
     2.5 + * File:   PR_MEAS__Counter_Recording.h
     2.6 + * Author: nengel
     2.7 + *
     2.8 + * Created on January 11, 2012, 3:03 PM
     2.9 + */
    2.10 +
    2.11 +#ifndef PR_MEAS__COUNTER_RECORDING_H
    2.12 +#define	PR_MEAS__COUNTER_RECORDING_H
    2.13 +
    2.14 +#include "PR_impl/PR.h"
    2.15 +
    2.16 +typedef struct 
    2.17 + {
    2.18 +   int event_type;
    2.19 +   int coreID;
    2.20 +   AnimSlot* slot;
    2.21 +   int vp;
    2.22 +   int task;
    2.23 +   uint64 cycles;
    2.24 +   uint64 instrs;
    2.25 + } 
    2.26 +CounterEvent;
    2.27 +
    2.28 +FILE* counterfile; //pass file handle via side effect because
    2.29 +                   // doAllInListOfArrays only takes Fns with a single input
    2.30 +
    2.31 +void PR_MEAS__init_counter_data_structs_for_lang( SlaveVP *slv, int32 magicNum );
    2.32 +
    2.33 +void PR_MEAS__counter_handler(int evt_type, int vpid, int task, SlaveVP* pr, uint64 cycles, uint64 instrs);
    2.34 +
    2.35 +void PR_MEAS__set_counter_file(FILE* f);
    2.36 +
    2.37 +void PR_MEAS__print_counter_event_to_file( void* _e );
    2.38 +#endif	/* PRServ_COUNTER_RECORDING_H */
    2.39 +