# HG changeset patch # User Merten Sach # Date 1321907943 -3600 # Node ID 28650a4df2b96093d24ffb8b36ebfc4fa1358e2c # Parent c8995a602b4663d7d98ccf6e4be43a550dea003f working version diff -r c8995a602b46 -r 28650a4df2b9 src/Application/main.c --- a/src/Application/main.c Mon Nov 21 19:16:03 2011 +0100 +++ b/src/Application/main.c Mon Nov 21 21:39:03 2011 +0100 @@ -126,6 +126,8 @@ size_t chunk_size = 0; int cycles_counter_fd[NUM_CORES]; +int cycles_counter_main_fd; +struct perf_event_attr* hw_event; //======================== App Code ========================= /* @@ -137,15 +139,16 @@ int nread; \ \ nread = read(cycles_fd,&(cycles),sizeof(cycles)); \ - if(nread<=0){ \ + if(nread<0){ \ perror("Error reading cycles counter"); \ cycles = 0; \ } \ } while (0) //macro magic for scoping + void work(void* input, VirtProcr* animatingPr) { - int n,m; + int i,o; struct input_t* in = (struct input_t*)input; unsigned int totalWorkCycles = 0; unsigned int workspace1; @@ -154,7 +157,7 @@ int cpuid = sched_getcpu(); - for(m=0; m there for gcc printf("%d", workspace1); //This is to prevent gcc from optimizing out the printf("%f", workspace2); //two workspace variables } @@ -198,63 +202,21 @@ /* this is run after the VMS is set up*/ void benchmark(void *in, VirtProcr *animatingPr) { - int i; + int i, cpuID; struct input_t input[num_threads]; struct barrier_t barr; barrier_init(&barr, num_threads+1, animatingPr); - //setup performance counters - struct perf_event_attr* hw_event; - hw_event = VMS__malloc(sizeof(struct perf_event_attr)); - memset(hw_event,0,sizeof(hw_event)); - hw_event->type = PERF_TYPE_HARDWARE; - hw_event->size = sizeof(hw_event); - hw_event->disabled = 0; - hw_event->freq = 0; - hw_event->inherit = 1; /* children inherit it */ - hw_event->pinned = 1; /* must always be on PMU */ - hw_event->exclusive = 0; /* only group on PMU */ - hw_event->exclude_user = 0; /* don't count user */ - hw_event->exclude_kernel = 1; /* ditto kernel */ - hw_event->exclude_hv = 1; /* ditto hypervisor */ - hw_event->exclude_idle = 1; /* don't count when idle */ - hw_event->mmap = 0; /* include mmap data */ - hw_event->comm = 0; /* include comm data */ - - - for( i = 0; i < NUM_CORES; i++ ) - { - hw_event->config = PERF_COUNT_HW_CPU_CYCLES; //cycles - cycles_counter_fd[i] = syscall(__NR_perf_event_open, hw_event, - 0,//pid_t pid, - i,//int cpu, - -1,//int group_fd, - 0//unsigned long flags - ); - if (cycles_counter_fd[i]<0){ - fprintf(stderr,"On core %d: ",i); - perror("Failed to open cycles counter"); - } - } - - //Count on all CPUs - int cycles_counter_main_fd = syscall(__NR_perf_event_open, hw_event, - 0,//pid_t pid, - -1,//int cpu, - -1,//int group_fd, - 0//unsigned long flags - ); - if (cycles_counter_main_fd<0){ - fprintf(stderr,"On core %d: ",i); - perror("Failed to open cycles counter"); - } + //prepare input for(i=0; itype = PERF_TYPE_HARDWARE; + hw_event->size = sizeof(hw_event); + hw_event->disabled = 0; + hw_event->freq = 0; + hw_event->inherit = 1; /* children inherit it */ + hw_event->pinned = 1; /* says this virt counter must always be on HW */ + hw_event->exclusive = 0; /* only group on PMU */ + hw_event->exclude_user = 0; /* don't count user */ + hw_event->exclude_kernel = 1; /* don't count kernel */ + hw_event->exclude_hv = 1; /* ditto hypervisor */ + hw_event->exclude_idle = 1; /* don't count when idle */ + hw_event->mmap = 0; /* include mmap data */ + hw_event->comm = 0; /* include comm data */ + + hw_event->config = PERF_COUNT_HW_CPU_CYCLES; //cycles + + int cpuID, retries; + + for( cpuID = 0; cpuID < NUM_CORES; cpuID++ ) + { retries = 0; + do + { retries += 1; + cycles_counter_fd[cpuID] = + syscall(__NR_perf_event_open, hw_event, + 0,//pid_t: 0 is "pid of calling process" + cpuID,//int: cpu, the value returned by "CPUID" instr(?) + -1,//int: group_fd, -1 is "leader" or independent + 0//unsigned long: flags + ); + } + while(cycles_counter_fd[cpuID]<0 && retries < 100); + if(retries >= 100) + { + fprintf(stderr,"On core %d: ",cpuID); + perror("Failed to open cycles counter"); + } + } + printf("counters now set up\n"); + + //Set up counter to accumulate total cycles to process, across all CPUs + + retries = 0; + do + { retries += 1; + cycles_counter_main_fd = + syscall(__NR_perf_event_open, hw_event, + 0,//pid_t: 0 is "pid of calling process" + -1,//int: cpu, -1 means accumulate from all cores + -1,//int: group_fd, -1 is "leader" == independent + 0//unsigned long: flags + ); + } + while(cycles_counter_main_fd<0 && retries < 100); + if(retries >= 100) + { + fprintf(stderr,"in main "); + perror("Failed to open cycles counter"); + } + + + //This is the transition to the VMS runtime + VPThread__create_seed_procr_and_do_work(benchmark, NULL); return 0; -} + }