int main(int argc, char* argv[]) { int arg_count ; pid_t my_process_id ; unsigned long outer, middle, inner, total ; unsigned long long cycles ; unsigned int cpu_speed ; double elapsed = 0 ; int d_flag,h_flag, v_flag; #ifdef _DEBUG d_flag = 1 ; #endif // Parse any command line arguments. Use simple one character // option names preceded by a '-' character. for (arg_count = 1 ; arg_count < argc ; arg_count++) { if( argv[arg_count][0] == '-' ) { switch( argv[arg_count][1] ) { case 'c' : { // Measure data cache behavior c_flag = 1 ; break ; } case 'd' : { // Enable debug output d_flag = 1 ; break ; } case 'h' : { // Display usage information //display_usage_info(argv[0], usage_strings) ; h_flag = 1 ; break ; } case 'i' : { // Measure IPC i_flag = 1 ; break ; } case 'm' : { // Set matrix size fprintf(stderr, "*warning* -m is unimplemented\n") ; m_flag = 1 ; arg_count++ ; if (arg_count < argc) { matrix_size = atoi(argv[arg_count]) ; if ((matrix_size <= 0) || (matrix_size > MAX_MSIZE)) { fprintf(stderr, "*warning* Matrix size is limited to %d\n", MAX_MSIZE) ; matrix_size = MSIZE ; } } break ; } case 't' : { // Measure TLB behavior t_flag = 1 ; break ; } case 'v' : { v_flag = 1 ; break ; } default: { printf("Illegal option: %c\n", argv[arg_count][1]) ; break ; } } } } if (create_result_file(RESULT_FILE_NAME) == 0) { exit( EXIT_FAILURE ) ; } if (c_flag) { // Measure cache behavior // measure_cache() ; } else if (t_flag) { // Measure TLB behavior // measure_tlb() ; } else if (i_flag) { // Measure IPC (by default) //measure_cpi() ; } else { // Don't measurement any events run_no_events() ; } // print_heading("Naive matrix multiplication") ; // print_system_info() ; // Number of ARM instructions in the loop nest // outer = 8 * MSIZE ; // middle = 9 * MSIZE * MSIZE ; // inner = 9 * MSIZE * MSIZE * MSIZE ; // total = outer + middle + inner ; /* fprintf(result_file, "Run information\n") ; */ /* fprintf(result_file, " Outer loop instructions: %lu\n", outer) ; */ /* fprintf(result_file, " Middle loop instructions: %lu\n", middle) ; */ /* fprintf(result_file, " Inner loop instructions: %lu\n", inner) ; */ /* fprintf(result_file, " Total instructions: %lu\n", total) ; */ /* elapsed = get_elapsed_time() ; */ /* cpu_speed = get_cpu_speed() ; // MHz */ /* cycles = (long long int)(elapsed * 1000000.0 * (double)cpu_speed) ; */ /* fprintf(result_file, " Estimated cycles: %llu\n", cycles) ; */ /* fprintf(result_file, " Cycles (scaled by 64): %llu\n", cycles / 64) ; */ /* if (c_flag || i_flag || t_flag) { */ /* fprintf(result_file,"Performance Monitor events\n") ; */ /* print_counts(result_file) ; */ /* } */ /* fprintf(result_file, "\nRun execution summary\n") ; */ /* print_process_times() ; */ /* print_elapsed_time() ; */ /* close_result_file() ; */ return( EXIT_SUCCESS ) ; }
int main(int argc, char *argv[]) { int floatingPoint = 0; int integer = 0; int trials = 0; int arrLength = 0; int range = 0; char* endptr; struct timespec start, stop; int opt; while ((opt = getopt( argc, argv, "fin:a:r:")) != -1) { switch (opt) { case 'f': floatingPoint = 1; break; case 'i': integer = 1; break; case 'n': trials = strtol( optarg, &endptr, 10); break; case 'a': arrLength = strtol( optarg, &endptr, 10); break; case 'r': range = strtol( optarg, &endptr, 10); break; case '?': display_usage(); break; } } // printf( "float: %u, int: %u, trials: %u, array length: %u\n", floatingPoint, integer, trials, arrLength); int k = 0; int i = 0; if( integer == 1) { int a[arrLength]; int b[arrLength]; int c[arrLength]; srand(time(0)); for( i = 0; i < arrLength; i++) { a[i] = rand() % range; b[i] = rand() % range; } //"Warm-up" to remove initial memory-acces overhead intAdd( a, b, c, arrLength); //clock_gettime(CLOCK_REALTIME, &start); start_counting(ARMV6_EVENT_INSTR_EXEC, ARMV6_EVENT_CPU_CYCLES) ; //start_counting(ARMV6_EVENT_DTLB_MISS, ARMV6_EVENT_MAIN_TLB_MISS) ; //start_counting(ARMV6_EVENT_DCACHE_CACCESS, ARMV6_EVENT_DCACHE_MISS) ; for( k = trials; k > 0; k--) { intAdd( a, b, c, arrLength); } stop_counting() ; if (create_result_file("output.dat") == 0) { printf ("Error cannot create file"); exit( EXIT_FAILURE ) ; } fprintf(result_file,"Performance Monitor events\n") ; print_counts(result_file) ; //clock_gettime(CLOCK_REALTIME, &stop); double diff = ( stop.tv_sec - start.tv_sec ) + ( stop.tv_nsec - start.tv_nsec ) / 1E9; printf( "%u, %u, %lf\n", trials, arrLength, diff); }else if ( floatingPoint == 1) { double a[arrLength]; double b[arrLength]; double c[arrLength]; srand(time(0)); for( i = 0; i < arrLength; i++) { a[i] = (double)rand() / (double)(RAND_MAX/range); b[i] = (double)rand() / (double)(RAND_MAX/range); } /*"Warm-up" to remove initial memory-acces overhead fpAdd( a, b, c, arrLength); clock_gettime(CLOCK_REALTIME, &start); for( k = trials; k > 0; k--) { fpAdd( a, b, c, arrLength); } clock_gettime(CLOCK_REALTIME, &stop); */ double diff = ( stop.tv_sec - start.tv_sec ) + ( stop.tv_nsec - start.tv_nsec ) / 1E9; printf( "%u, %u, %lf\n", trials, arrLength, diff); } return 0; }