changeset 166:aefd87f9d12f perf_counters

loop graph
author Nina Engelhardt
date Tue, 18 Oct 2011 15:53:04 +0200
parents fe3ff53b55a6
children 981acd1db6af
files MasterLoop.c VMS.c VMS.h loop.c loop.h
diffstat 5 files changed, 157 insertions(+), 0 deletions(-) [+]
line diff
     1.1 --- a/MasterLoop.c	Wed Sep 28 14:58:41 2011 +0200
     1.2 +++ b/MasterLoop.c	Tue Oct 18 15:53:04 2011 +0200
     1.3 @@ -90,6 +90,8 @@
     1.4     volatileMasterPr = animatingPr;
     1.5     masterPr         = (VirtProcr*)volatileMasterPr; //used to force re-define after jmp
     1.6  
     1.7 +   bulb b = new_bulb();
     1.8 +   numSlotsFilled=1;
     1.9        //First animation of each MasterVP will in turn animate this part
    1.10        // of setup code.. (VP creator sets up the stack as if this function
    1.11        // was called normally, but actually get here by jmp)
    1.12 @@ -129,6 +131,14 @@
    1.13     slaveScheduler   = masterEnv->slaveScheduler;
    1.14     semanticEnv      = masterEnv->semanticEnv;
    1.15  
    1.16 +   #ifdef DETECT_LOOP_GRAPH
    1.17 +   if(numSlotsFilled > 0){
    1.18 +   b = new_bulb();
    1.19 +   addToDynArray((void*)b,masterEnv->loop_graph_array_info);
    1.20 +   set_bulb_core(b,thisCoresIdx);
    1.21 +   set_bulb_id(b,masterEnv->loop_counter[thisCoresIdx]++);
    1.22 +   }
    1.23 +   #endif
    1.24  
    1.25        //Poll each slot's Done flag
    1.26     numSlotsFilled = 0;
    1.27 @@ -160,6 +170,8 @@
    1.28                 Dependency* newd = new_dependency(currSlot->procrAssignedToSlot->procrID,lastRecord->task_position,currSlot->procrAssignedToSlot->procrID,lastRecord->task_position + 1);
    1.29                 addToDynArray((void*) newd ,masterEnv->dependenciesInfo);     
    1.30                
    1.31 +
    1.32 +               
    1.33                 //print_record_human_readable(lastRecord);
    1.34                 //create new entry in record array
    1.35                 CounterRecord* newRecord = VMS__malloc(sizeof(CounterRecord));
    1.36 @@ -217,6 +229,13 @@
    1.37              writeVMSQ( schedVirtPr, readyToAnimateQ );
    1.38            }
    1.39         }
    1.40 +               #ifdef DETECT_LOOP_GRAPH
    1.41 +               if(!currSlot->needsProcrAssigned) {
    1.42 +                   int lastRecordIdx = currSlot->procrAssignedToSlot->counter_history_array_info->numInArray -1;
    1.43 +                   CounterRecord* lastRecord = currSlot->procrAssignedToSlot->counter_history[lastRecordIdx];
    1.44 +                   set_bulb_member(b,slotIdx,currSlot->procrAssignedToSlot->procrID,lastRecord->task_position);
    1.45 +               }
    1.46 +               #endif
    1.47      }
    1.48  
    1.49     
     2.1 --- a/VMS.c	Wed Sep 28 14:58:41 2011 +0200
     2.2 +++ b/VMS.c	Tue Oct 18 15:53:04 2011 +0200
     2.3 @@ -190,7 +190,17 @@
     2.4     _VMSMasterEnv->dependencies = VMS__malloc(10*sizeof(void*));
     2.5     _VMSMasterEnv->dependenciesInfo = makePrivDynArrayInfoFrom((void***)&(_VMSMasterEnv->dependencies),10);
     2.6     #endif
     2.7 +
     2.8 +   #ifdef DETECT_LOOP_GRAPH
     2.9 +   _VMSMasterEnv->loop_graph = VMS__malloc(10*sizeof(void*));
    2.10 +   _VMSMasterEnv->loop_graph_array_info = makePrivDynArrayInfoFrom((void***)&(_VMSMasterEnv->loop_graph),10);
    2.11 +   int loop_i;
    2.12 +   for(loop_i=0;loop_i<NUM_CORES;loop_i++){
    2.13 +       _VMSMasterEnv->loop_counter[loop_i]=0;
    2.14 +   }
    2.15     
    2.16 +   #endif
    2.17 +
    2.18     #ifdef MEAS__PERF_COUNTERS
    2.19     _VMSMasterEnv->counter_history = VMS__malloc(10*sizeof(void*));
    2.20     _VMSMasterEnv->counter_history_array_info = makePrivDynArrayInfoFrom((void***)&(_VMSMasterEnv->counter_history),10);
    2.21 @@ -809,6 +819,41 @@
    2.22         printf("Could not open Dependencies file, please clean \"counters\" folder. (Must contain less than 255 files.)\n");
    2.23     }
    2.24  #endif
    2.25 +   #ifdef DETECT_LOOP_GRAPH
    2.26 +   FILE* loop_output;
    2.27 +   int loop_n;
    2.28 +   char loop_filename[255];    
    2.29 +    for(loop_n=0;loop_n<255;loop_n++)
    2.30 +    {
    2.31 +        sprintf(loop_filename, "./counters/LoopGraph.%d.dot",loop_n);
    2.32 +        loop_output = fopen(loop_filename,"r");
    2.33 +        if(loop_output)
    2.34 +        {
    2.35 +            fclose(loop_output);
    2.36 +        }else{
    2.37 +            break;
    2.38 +        }
    2.39 +    }
    2.40 +   if(loop_n<255){
    2.41 +    printf("Saving Loop Graph to File: %s ...\n", loop_filename);
    2.42 +    loop_output = fopen(loop_filename,"w+");
    2.43 +    if(loop_output!=NULL){
    2.44 +        set_dependency_file(loop_output);
    2.45 +        fprintf(loop_output,"digraph Loop {\n");
    2.46 +        set_loop_file(loop_output);
    2.47 +        forAllInDynArrayDo(_VMSMasterEnv->counter_history_array_info, &print_dot_node_info );
    2.48 +        forAllInDynArrayDo( _VMSMasterEnv->loop_graph_array_info, &print_per_slot_to_file );
    2.49 +        //int coreIdx;
    2.50 +        //for(coreIdx=0;coreIdx<NUM_CORES;coreIdx++){
    2.51 +        //    fprintf(loop_output,"sync%d_%d [shape=rect,label=\"Sync\"];\n",coreIdx,_VMSMasterEnv->loop_counter[coreIdx]);
    2.52 +        //}
    2.53 +        fprintf(loop_output,"}\n");
    2.54 +    } else
    2.55 +        printf("Opening Loop Graph file failed. Please check that folder \"counters\" exists in run directory.\n");
    2.56 +   } else {
    2.57 +       printf("Could not open Loop Graph file, please clean \"counters\" folder. (Must contain less than 255 files.)\n");
    2.58 +   }
    2.59 +#endif
    2.60     #ifdef MEAS__TIME_PLUGIN
    2.61     printHist( _VMSMasterEnv->reqHdlrLowTimeHist );
    2.62     saveHistToFile( _VMSMasterEnv->reqHdlrLowTimeHist );
     3.1 --- a/VMS.h	Wed Sep 28 14:58:41 2011 +0200
     3.2 +++ b/VMS.h	Tue Oct 18 15:53:04 2011 +0200
     3.3 @@ -18,6 +18,7 @@
     3.4  #include "vmalloc.h"
     3.5  #include "Counters/Counters.h"
     3.6  #include "dependency.h"
     3.7 +#include "loop.h"
     3.8  
     3.9  #include <pthread.h>
    3.10  #include <sys/time.h>
    3.11 @@ -77,6 +78,7 @@
    3.12  
    3.13  #define MEAS__PERF_COUNTERS
    3.14  #define DETECT_DEPENDENCIES
    3.15 +#define DETECT_LOOP_GRAPH
    3.16  
    3.17  //=========================  Hardware related Constants =====================
    3.18     //This value is the number of hardware threads in the shared memory
    3.19 @@ -280,6 +282,11 @@
    3.20     CounterRecord** counter_history;
    3.21     PrivDynArrayInfo* counter_history_array_info;
    3.22     #endif
    3.23 +   #ifdef DETECT_LOOP_GRAPH
    3.24 +   bulb* loop_graph;
    3.25 +   PrivDynArrayInfo* loop_graph_array_info;
    3.26 +   int loop_counter[NUM_CORES];
    3.27 +   #endif
    3.28   }
    3.29  MasterEnv;
    3.30  
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/loop.c	Tue Oct 18 15:53:04 2011 +0200
     4.3 @@ -0,0 +1,55 @@
     4.4 +#include "VMS.h"
     4.5 +#include "vmalloc.h"
     4.6 +#include "loop.h"
     4.7 +
     4.8 +bulb new_bulb() {
     4.9 +    bulb b = VMS__malloc((2*NUM_SCHED_SLOTS + 2)*sizeof(int));
    4.10 +    memset(b,0,(2*NUM_SCHED_SLOTS + 2)*sizeof(int));
    4.11 +    return b;
    4.12 +}
    4.13 +
    4.14 +void set_bulb_member(bulb b, int i, int vp, int task){
    4.15 +    b[2*i]=vp;
    4.16 +    b[2*i+1]=task;
    4.17 +}
    4.18 +
    4.19 +void set_bulb_core(bulb b, int core){
    4.20 +    b[2*NUM_SCHED_SLOTS] = core;
    4.21 +}
    4.22 +
    4.23 +void set_bulb_id(bulb b, int id){
    4.24 +    b[2*NUM_SCHED_SLOTS + 1] = id;
    4.25 +}
    4.26 +
    4.27 +void set_loop_file(FILE* file){
    4.28 +    loop_file=file;
    4.29 +}
    4.30 +
    4.31 +void print_bulb_to_file(void* _b){
    4.32 +    bulb b = (bulb) _b;
    4.33 +    if(b[2*NUM_SCHED_SLOTS]!=0 || b[2*NUM_SCHED_SLOTS + 1]!=0)
    4.34 +        fprintf(loop_file,"sync%d_%d [shape=rect];\n",b[2*NUM_SCHED_SLOTS],b[2*NUM_SCHED_SLOTS + 1]);
    4.35 +    int i;
    4.36 +    for(i=0;i<NUM_SCHED_SLOTS;++i){
    4.37 +        if(b[2*i] != 0){
    4.38 +            fprintf(loop_file, "sync%d_%d -> VP_%d_%d;\n",b[2*NUM_SCHED_SLOTS],b[2*NUM_SCHED_SLOTS + 1],b[2*i],b[2*i+1]);
    4.39 +            fprintf(loop_file, "VP_%d_%d -> sync%d_%d;\n",b[2*i],b[2*i+1],b[2*NUM_SCHED_SLOTS],b[2*NUM_SCHED_SLOTS + 1] + 1);
    4.40 +        }
    4.41 +    }
    4.42 +}
    4.43 +
    4.44 +int prev_slots[NUM_CORES][2*NUM_SCHED_SLOTS];
    4.45 +
    4.46 +void print_per_slot_to_file(void* _b){
    4.47 +    bulb b = (bulb) _b;
    4.48 +    int i;
    4.49 +    for(i=0;i<NUM_SCHED_SLOTS;++i){
    4.50 +        if(b[2*i] != 0){
    4.51 +            if(prev_slots[b[2*NUM_SCHED_SLOTS]][2*i] != 0){
    4.52 +               fprintf(loop_file, "VP_%d_%d -> VP_%d_%d;\n",prev_slots[b[2*NUM_SCHED_SLOTS]][2*i],prev_slots[b[2*NUM_SCHED_SLOTS]][2*i+1],b[2*i],b[2*i+1]); 
    4.53 +            }
    4.54 +            prev_slots[b[2*NUM_SCHED_SLOTS]][2*i] = b[2*i];
    4.55 +            prev_slots[b[2*NUM_SCHED_SLOTS]][2*i+1] = b[2*i+1];
    4.56 +        }
    4.57 +    }
    4.58 +}
    4.59 \ No newline at end of file
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/loop.h	Tue Oct 18 15:53:04 2011 +0200
     5.3 @@ -0,0 +1,31 @@
     5.4 +/* 
     5.5 + * File:   loop.h
     5.6 + * Author: engelhardt
     5.7 + *
     5.8 + * Created on 4. Oktober 2011, 15:54
     5.9 + */
    5.10 +
    5.11 +#ifndef LOOP_H
    5.12 +#define	LOOP_H
    5.13 +
    5.14 +#include <stdio.h>
    5.15 +
    5.16 +typedef int* bulb;
    5.17 +
    5.18 +FILE* loop_file;
    5.19 +
    5.20 +bulb new_bulb();
    5.21 +
    5.22 +void set_bulb_member(bulb b, int i, int vp, int task);
    5.23 +
    5.24 +void set_bulb_core(bulb b, int core);
    5.25 +
    5.26 +void set_bulb_id(bulb b, int id);
    5.27 +
    5.28 +void set_loop_file(FILE* file);
    5.29 +
    5.30 +void print_bulb_to_file(void* b);
    5.31 +
    5.32 +void print_per_slot_to_file(void* _b);
    5.33 +#endif	/* LOOP_H */
    5.34 +