コード例 #1
0
int main(int argc, char **argv)
{
   int retval;

   const PAPI_component_info_t *cmpinfo;

   tests_quiet(argc, argv);     /* Set TESTS_QUIET variable */

   if ((retval = PAPI_library_init(PAPI_VER_CURRENT)) != PAPI_VER_CURRENT)
      test_fail(__FILE__, __LINE__, "PAPI_library_init", retval);

   if ((cmpinfo = PAPI_get_component_info(0)) == NULL) 
     test_fail(__FILE__, __LINE__, "PAPI_get_component_info", retval);

   printf("name: %s\n",cmpinfo->name);
   printf("substrate_version: %s\n",cmpinfo->version);
   printf("support_version: %s\n",cmpinfo->support_version);
   printf("kernel_version: %s\n",cmpinfo->kernel_version);
   printf("num_cntrs: %d\n",cmpinfo->num_cntrs);
   printf("num_mpx_cntrs: %d\n",cmpinfo->num_mpx_cntrs);
   printf("num_preset_events: %d\n",cmpinfo->num_preset_events);           /* Number of counters the substrate supports */
   printf("num_native_events: %d\n",cmpinfo->num_native_events);           /* Number of counters the substrate supports */
   printf("default_domain: 0x%x (%s)\n",cmpinfo->default_domain,stringify_all_domains(cmpinfo->default_domain));
   printf("available_domains: 0x%x (%s)\n",cmpinfo->available_domains,stringify_all_domains(cmpinfo->available_domains));       /* Available domains */ 
   printf("default_granularity: 0x%x (%s)\n",cmpinfo->default_granularity,stringify_granularity(cmpinfo->default_granularity));
   /* The default granularity when this substrate is used */
   printf("available_granularities: 0x%x (%s)\n",cmpinfo->available_granularities,stringify_all_granularities(cmpinfo->available_granularities)); /* Available granularities */
   printf("itimer_sig: %d\n",cmpinfo->itimer_sig);     
   printf("itimer_num: %d\n",cmpinfo->itimer_num);     
   printf("itimer_ns: %d\n",cmpinfo->itimer_ns);      
   printf("itimer_res_ns: %d\n",cmpinfo->itimer_res_ns); 
   printf("hardware_intr_sig: %d\n",cmpinfo->hardware_intr_sig);      /* Width of opcode matcher if exists, 0 if not */
   printf("clock_ticks: %d\n",cmpinfo->clock_ticks);      
   printf("opcode_match_width: %d\n",cmpinfo->opcode_match_width);      /* Width of opcode matcher if exists, 0 if not */
/*   printf("reserved_ints[4]: %d\n",cmpinfo->reserved_ints[4]); */
   printf("hardware_intr: %d\n",cmpinfo->hardware_intr);         /* Needs hw overflow intr to be emulated in software*/
   printf("precise_intr: %d\n",cmpinfo->precise_intr);          /* Performance interrupts happen precisely */
   printf("posix1b_timers: %d\n",cmpinfo->posix1b_timers);          /* Performance interrupts happen precisely */
   printf("kernel_profile: %d\n",cmpinfo->kernel_profile);        /* Needs kernel profile support (buffered interrupts) to be emulated */
   printf("kernel_multiplex: %d\n",cmpinfo->kernel_multiplex);      /* In kernel multiplexing */
   printf("data_address_range: %d\n",cmpinfo->data_address_range);    /* Supports data address range limiting */
   printf("instr_address_range: %d\n",cmpinfo->instr_address_range);   /* Supports instruction address range limiting */
   printf("fast_counter_read: %d\n",cmpinfo->fast_counter_read);       /* Has a fast counter read */
   printf("fast_real_timer: %d\n",cmpinfo->fast_real_timer);       /* Has a fast real timer */
   printf("fast_virtual_timer: %d\n",cmpinfo->fast_virtual_timer);    /* Has a fast virtual timer */
   printf("attach: %d\n",cmpinfo->attach);    /* Has a fast virtual timer */
   printf("attach_must_ptrace: %d\n",cmpinfo->attach_must_ptrace);    /* Has a fast virtual timer */
   printf("edge_detect: %d\n",cmpinfo->edge_detect);    /* Has a fast virtual timer */
   printf("invert: %d\n",cmpinfo->invert);    /* Has a fast virtual timer */
   printf("profile_ear: %d\n",cmpinfo->profile_ear);     /* Supports data/instr/tlb miss address sampling */
   printf("cntr_groups: %d\n",cmpinfo->cntr_groups);           /* Underlying hardware uses counter groups */
   printf("cntr_umasks: %d\n",cmpinfo->cntr_umasks);           /* counters have unit masks */
   printf("cntr_IEAR_events: %d\n",cmpinfo->cntr_IEAR_events);      /* counters support instr event addr register */
   printf("cntr_DEAR_events: %d\n",cmpinfo->cntr_DEAR_events);      /* counters support data event addr register */
   printf("cntr_OPCM_events: %d\n",cmpinfo->cntr_OPCM_events);      /* counter events support opcode matching */

   test_pass(__FILE__, NULL, 0);
   exit(0);
}
コード例 #2
0
ファイル: test_utils.c プロジェクト: pyrovski/papi-rapl
char *
stringify_all_granularities( int granularities )
{
	static char buf[PAPI_HUGE_STR_LEN];
	int i, did = 0;

	buf[0] = '\0';
	for ( i = PAPI_GRN_MIN; i <= PAPI_GRN_MAX; i = i << 1 )
		if ( granularities & i ) {
			if ( did )
				strcpy( buf + strlen( buf ), "|" );
			strcpy( buf + strlen( buf ),
					stringify_granularity( granularities & i ) );
			did++;
		}
	if ( did == 0 )
		test_fail( __FILE__, __LINE__, "Unrecognized granularity!", 0 );

	return ( buf );
}
コード例 #3
0
ファイル: attach3.c プロジェクト: jtombiamba/MABTools
int
main( int argc, char **argv )
{
    int status, retval, num_tests = 1, tmp;
    int EventSet1 = PAPI_NULL;
    long long **values;
    long long elapsed_us, elapsed_cyc, elapsed_virt_us, elapsed_virt_cyc;
    char event_name[PAPI_MAX_STR_LEN];;
    const PAPI_hw_info_t *hw_info;
    const PAPI_component_info_t *cmpinfo;
    pid_t pid;

    /* Fork before doing anything with the PMU */

    setbuf(stdout,NULL);
    pid = fork(  );
    if ( pid < 0 )
        test_fail( __FILE__, __LINE__, "fork()", PAPI_ESYS );
    if ( pid == 0 )
        exit( wait_for_attach_and_loop(  ) );

    tests_quiet( argc, argv );	/* Set TESTS_QUIET variable */


    /* Master only process below here */

    retval = PAPI_library_init( PAPI_VER_CURRENT );
    if ( retval != PAPI_VER_CURRENT )
        test_fail_exit( __FILE__, __LINE__, "PAPI_library_init", retval );

    if ( ( cmpinfo = PAPI_get_component_info( 0 ) ) == NULL )
        test_fail_exit( __FILE__, __LINE__, "PAPI_get_component_info", 0 );

    if ( cmpinfo->attach == 0 )
        test_skip( __FILE__, __LINE__, "Platform does not support attaching",
                   0 );

    hw_info = PAPI_get_hardware_info(  );
    if ( hw_info == NULL )
        test_fail_exit( __FILE__, __LINE__, "PAPI_get_hardware_info", 0 );

    /* add PAPI_TOT_CYC and one of the events in PAPI_FP_INS, PAPI_FP_OPS or
       PAPI_TOT_INS, depending on the availability of the event on the
       platform */
    retval = PAPI_create_eventset(&EventSet1);
    if ( retval != PAPI_OK )
        test_fail_exit( __FILE__, __LINE__, "PAPI_attach", retval );

    /* Force addition of component */

    retval = PAPI_assign_eventset_component( EventSet1, 0 );
    if ( retval != PAPI_OK )
        test_fail( __FILE__, __LINE__, "PAPI_assign_eventset_component",
                   retval );

    /* The following call causes this test to fail for perf_events */

    retval = PAPI_attach( EventSet1, ( unsigned long ) pid );
    if ( retval != PAPI_OK )
        test_fail_exit( __FILE__, __LINE__, "PAPI_attach", retval );

    sprintf(event_name,"PAPI_TOT_CYC");

    retval = PAPI_add_event(EventSet1, PAPI_TOT_CYC);
    if ( retval != PAPI_OK )
        test_fail_exit( __FILE__, __LINE__, "PAPI_add_event", retval );
    retval = PAPI_add_event(EventSet1, PAPI_FP_INS);
    if ( retval == PAPI_ENOEVNT ) {
        test_warn( __FILE__, __LINE__, "PAPI_FP_INS", retval);
    } else if ( retval != PAPI_OK ) {
        test_fail_exit( __FILE__, __LINE__, "PAPI_add_event", retval );
    }

    values = allocate_test_space( 1, 2);

    elapsed_us = PAPI_get_real_usec(  );

    elapsed_cyc = PAPI_get_real_cyc(  );

    elapsed_virt_us = PAPI_get_virt_usec(  );

    elapsed_virt_cyc = PAPI_get_virt_cyc(  );

    printf("must_ptrace is %d\n",cmpinfo->attach_must_ptrace);
    pid_t  child = wait( &status );
    printf( "Debugger exited wait() with %d\n",child );
    if (WIFSTOPPED( status ))
    {
        printf( "Child has stopped due to signal %d (%s)\n",
                WSTOPSIG( status ), strsignal(WSTOPSIG( status )) );
    }
    if (WIFSIGNALED( status ))
    {
        printf( "Child %ld received signal %d (%s)\n",
                (long)child,
                WTERMSIG(status) , strsignal(WTERMSIG( status )) );
    }
    printf("After %d\n",retval);

    retval = PAPI_start( EventSet1 );
    if ( retval != PAPI_OK )
        test_fail_exit( __FILE__, __LINE__, "PAPI_start", retval );

    printf("Continuing\n");
    if ( ptrace( PTRACE_CONT, pid, NULL, NULL ) == -1 ) {
        perror( "ptrace(PTRACE_CONT)" );
        return 1;
    }


    do {
        child = wait( &status );
        printf( "Debugger exited wait() with %d\n", child);
        if (WIFSTOPPED( status ))
        {
            printf( "Child has stopped due to signal %d (%s)\n",
                    WSTOPSIG( status ), strsignal(WSTOPSIG( status )) );
        }
        if (WIFSIGNALED( status ))
        {
            printf( "Child %ld received signal %d (%s)\n",
                    (long)child,
                    WTERMSIG(status) , strsignal(WTERMSIG( status )) );
        }
    } while (!WIFEXITED( status ));

    printf("Child exited with value %d\n",WEXITSTATUS(status));
    if (WEXITSTATUS(status) != 0)
        test_fail_exit( __FILE__, __LINE__, "Exit status of child to attach to", PAPI_EMISC);

    retval = PAPI_stop( EventSet1, values[0] );
    if ( retval != PAPI_OK )
        test_fail_exit( __FILE__, __LINE__, "PAPI_stop", retval );

    elapsed_virt_us = PAPI_get_virt_usec(  ) - elapsed_virt_us;

    elapsed_virt_cyc = PAPI_get_virt_cyc(  ) - elapsed_virt_cyc;

    elapsed_us = PAPI_get_real_usec(  ) - elapsed_us;

    elapsed_cyc = PAPI_get_real_cyc(  ) - elapsed_cyc;

    retval = PAPI_cleanup_eventset(EventSet1);
    if (retval != PAPI_OK)
        test_fail_exit( __FILE__, __LINE__, "PAPI_cleanup_eventset", retval );

    retval = PAPI_destroy_eventset(&EventSet1);
    if (retval != PAPI_OK)
        test_fail_exit( __FILE__, __LINE__, "PAPI_destroy_eventset", retval );

    printf( "Test case: 3rd party attach start, stop.\n" );
    printf( "-----------------------------------------------\n" );
    tmp = PAPI_get_opt( PAPI_DEFDOM, NULL );
    printf( "Default domain is: %d (%s)\n", tmp, stringify_all_domains( tmp ) );
    tmp = PAPI_get_opt( PAPI_DEFGRN, NULL );
    printf( "Default granularity is: %d (%s)\n", tmp,
            stringify_granularity( tmp ) );
    printf( "Using %d iterations of c += a*b\n", NUM_FLOPS );
    printf
    ( "-------------------------------------------------------------------------\n" );

    printf( "Test type    : \t           1\n" );

    printf( TAB1, "PAPI_TOT_CYC : \t", ( values[0] )[0] );
    printf( TAB1, "PAPI_FP_INS  : \t", ( values[0] )[1] );
    printf( TAB1, "Real usec    : \t", elapsed_us );
    printf( TAB1, "Real cycles  : \t", elapsed_cyc );
    printf( TAB1, "Virt usec    : \t", elapsed_virt_us );
    printf( TAB1, "Virt cycles  : \t", elapsed_virt_cyc );

    printf
    ( "-------------------------------------------------------------------------\n" );

    printf( "Verification: none\n" );

    test_pass( __FILE__, values, num_tests );
    exit( 1 );
}
コード例 #4
0
int main(int argc, char **argv)
{
   int retval, num_tests = 5, num_events, tmp;
   long long **values;
   int EventSet=PAPI_NULL;
   int PAPI_event, mask;
   char event_name[PAPI_MAX_STR_LEN], add_event_str[PAPI_MAX_STR_LEN];
   const PAPI_hw_info_t *hw_info;

   tests_quiet(argc, argv);     /* Set TESTS_QUIET variable */

   retval = PAPI_library_init(PAPI_VER_CURRENT);
   if (retval != PAPI_VER_CURRENT)
      test_fail(__FILE__, __LINE__, "PAPI_library_init", retval);

   hw_info = PAPI_get_hardware_info();
   if (hw_info == NULL)
     test_fail(__FILE__, __LINE__, "PAPI_get_hardware_info", 2);

   /* add PAPI_TOT_CYC and one of the events in PAPI_FP_INS, PAPI_FP_OPS or
      PAPI_TOT_INS, depending on the availability of the event on the
      platform */
   EventSet = add_two_events(&num_events, &PAPI_event, hw_info, &mask);

   retval = PAPI_event_code_to_name(PAPI_event, event_name);
   if (retval != PAPI_OK)
      test_fail(__FILE__, __LINE__, "PAPI_event_code_to_name", retval);
   sprintf(add_event_str, "PAPI_add_event[%s]", event_name);

   values = allocate_test_space(num_tests, num_events);

   retval = PAPI_start(EventSet);
   if (retval != PAPI_OK)
      test_fail(__FILE__, __LINE__, "PAPI_start", retval);

   do_flops(NUM_FLOPS);

   retval = PAPI_read(EventSet, values[0]);
   if (retval != PAPI_OK)
      test_fail(__FILE__, __LINE__, "PAPI_read", retval);

   retval = PAPI_reset(EventSet);
   if (retval != PAPI_OK)
      test_fail(__FILE__, __LINE__, "PAPI_reset", retval);

   do_flops(NUM_FLOPS);

   retval = PAPI_read(EventSet, values[1]);
   if (retval != PAPI_OK)
      test_fail(__FILE__, __LINE__, "PAPI_read", retval);

   do_flops(NUM_FLOPS);

   retval = PAPI_read(EventSet, values[2]);
   if (retval != PAPI_OK)
      test_fail(__FILE__, __LINE__, "PAPI_read", retval);

   do_flops(NUM_FLOPS);

   retval = PAPI_stop(EventSet, values[3]);
   if (retval != PAPI_OK)
      test_fail(__FILE__, __LINE__, "PAPI_stop", retval);

   retval = PAPI_read(EventSet, values[4]);
   if (retval != PAPI_OK)
      test_fail(__FILE__, __LINE__, "PAPI_read", retval);

   remove_test_events(&EventSet, mask);

   if (!TESTS_QUIET) {
      printf("Test case 1: Non-overlapping start, stop, read.\n");
      printf("-----------------------------------------------\n");
      tmp = PAPI_get_opt(PAPI_DEFDOM, NULL);
      printf("Default domain is: %d (%s)\n", tmp, stringify_all_domains(tmp));
      tmp = PAPI_get_opt(PAPI_DEFGRN, NULL);
      printf("Default granularity is: %d (%s)\n", tmp, stringify_granularity(tmp));
      printf("Using %d iterations of c += a*b\n", NUM_FLOPS);
      printf
          ("-------------------------------------------------------------------------\n");

      printf("Test type   :        1           2           3           4           5\n");
      sprintf(add_event_str, "%s:", event_name);
      printf(TAB5, add_event_str,
             (values[0])[0], (values[1])[0], (values[2])[0], (values[3])[0],
             (values[4])[0]);
      printf(TAB5, "PAPI_TOT_CYC:", (values[0])[1], (values[1])[1], (values[2])[1],
             (values[3])[1], (values[4])[1]);
      printf ("-------------------------------------------------------------------------\n"); 
      printf("Verification:\n");
      printf("Row 1 Column 1 at least %d\n", NUM_FLOPS);
      printf("%% difference between %s 1 & 2: %.2f\n",add_event_str,100.0*(float)(values[0])[0]/(float)(values[1])[0]);
      printf("%% difference between %s 1 & 2: %.2f\n","PAPI_TOT_CYC",100.0*(float)(values[0])[1]/(float)(values[1])[1]);
      printf("Column 1 approximately equals column 2\n");
      printf("Column 3 approximately equals 2 * column 2\n");
      printf("Column 4 approximately equals 3 * column 2\n");
      printf("Column 4 exactly equals column 5\n");
   }

   {
      long long min, max;
      min = (long long) (values[1][0] * .9);
      max = (long long) (values[1][0] * 1.1);

      if (values[0][0] > max || values[0][0] < min || values[2][0] > (2 * max)
          || values[2][0] < (2 * min) || values[3][0] > (3 * max)
          || values[3][0] < (3 * min)
          || values[3][0] != values[4][0]
          || values[0][0] < (long long)NUM_FLOPS) {
/*
         printf("min: ");
         printf(LLDFMT, min);
         printf("max: ");
         printf(LLDFMT, max);
         printf("1st: ");
         printf(LLDFMT, values[0][0]);
         printf("2nd: ");
         printf(LLDFMT, values[1][0]);
         printf("3rd: ");
         printf(LLDFMT, values[2][0]);
         printf("4th: ");
         printf(LLDFMT, values[3][0]);
         printf("5th: ");
         printf(LLDFMT, values[4][0]);
         printf("\n");
*/         test_fail(__FILE__, __LINE__, event_name, 1);
      }

      min = (long long) (values[1][1] * .8);
      max = (long long) (values[1][1] * 1.2);
      if (values[0][1] > max || values[0][1] < min || values[2][1] > (2 * max)
          || values[2][1] < (2 * min) || values[3][1] > (3 * max)
          || values[3][1] < (3 * min)
          || values[3][1] != values[4][1]) {
         test_fail(__FILE__, __LINE__, "PAPI_TOT_CYC", 1);
      }
   }
   test_pass(__FILE__, values, num_tests);
   exit(1);
}
コード例 #5
0
ファイル: multiattach.c プロジェクト: DanieleDeSensi/mammut
int
main( int argc, char **argv )
{
	int status, retval, num_tests = 2, tmp;
	int EventSet1 = PAPI_NULL, EventSet2 = PAPI_NULL;
	int PAPI_event, PAPI_event2, mask1, mask2;
	int num_events1, num_events2;
	long long **values;
	long long elapsed_us, elapsed_cyc, elapsed_virt_us, elapsed_virt_cyc;
	char event_name[PAPI_MAX_STR_LEN], add_event_str[PAPI_MAX_STR_LEN];
	const PAPI_component_info_t *cmpinfo;
	pid_t pid, pid2;
	double ratio1,ratio2;

	/* Set TESTS_QUIET variable */
	tests_quiet( argc, argv );

	/* Initialize the library */
	retval = PAPI_library_init( PAPI_VER_CURRENT );
	if ( retval != PAPI_VER_CURRENT ) {
	   test_fail_exit( __FILE__, __LINE__, "PAPI_library_init", retval );
	}

	/* get the component info and check if we support attach */
	if ( ( cmpinfo = PAPI_get_component_info( 0 ) ) == NULL ) {
	   test_fail_exit( __FILE__, __LINE__, "PAPI_get_component_info", 0 );
	}

	if ( cmpinfo->attach == 0 ) {
	   test_skip( __FILE__, __LINE__, 
		      "Platform does not support attaching", 0 );
	}

	/* fork off first child */
	pid = fork(  );
	if ( pid < 0 ) {
	   test_fail_exit( __FILE__, __LINE__, "fork()", PAPI_ESYS );
	}
	if ( pid == 0 ) {
	   exit( wait_for_attach_and_loop( 1 ) );
	}

	/* fork off second child, does twice as much */
	pid2 = fork(  );
	if ( pid2 < 0 ) {
	   test_fail_exit( __FILE__, __LINE__, "fork()", PAPI_ESYS );
	}
	if ( pid2 == 0 ) {
	   exit( wait_for_attach_and_loop( 2 ) );
	}

	/* add PAPI_TOT_CYC and one of the events in 
           PAPI_FP_INS, PAPI_FP_OPS or PAPI_TOT_INS, 
           depending on the availability of the event 
           on the platform                            */
	EventSet1 = add_two_events( &num_events1, &PAPI_event, &mask1 );
	EventSet2 = add_two_events( &num_events2, &PAPI_event2, &mask2 );

	if ( cmpinfo->attach_must_ptrace ) {
	   if ( ptrace( PTRACE_ATTACH, pid, NULL, NULL ) == -1 ) {
	      perror( "ptrace(PTRACE_ATTACH)" );
	      return 1 ;
	   }
	   if ( waitpid( pid, &status, 0 ) == -1 ) {
	      perror( "waitpid()" );
	      exit( 1 );
	   }
	   if ( WIFSTOPPED( status ) == 0 ) {
	      test_fail( __FILE__, __LINE__,
			"Child process didnt return true to WIFSTOPPED", 0 );
	   }
	   
	   if ( ptrace( PTRACE_ATTACH, pid2, NULL, NULL ) == -1 ) {
	      perror( "ptrace(PTRACE_ATTACH)" );
	      return 1;
	   }
	   if ( waitpid( pid2, &status, 0 ) == -1 ) {
	      perror( "waitpid()" );
	      exit( 1 );
	   }
	   if ( WIFSTOPPED( status ) == 0 ) {
 	      test_fail( __FILE__, __LINE__,
			"Child process didnt return true to WIFSTOPPED", 0 );
	   }
	}

	retval = PAPI_attach( EventSet1, ( unsigned long ) pid );
	if ( retval != PAPI_OK ) {
	   test_fail( __FILE__, __LINE__, "PAPI_attach", retval ); 
	}

	retval = PAPI_attach( EventSet2, ( unsigned long ) pid2 );
	if ( retval != PAPI_OK ) {
	   test_fail( __FILE__, __LINE__, "PAPI_attach", retval ); 
	}

	retval = PAPI_event_code_to_name( PAPI_event, event_name );
	if ( retval != PAPI_OK ) {
	   test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );
	}
	sprintf( add_event_str, "PAPI_add_event[%s]", event_name );

	/* num_events1 is greater than num_events2 so don't worry. */

	values = allocate_test_space( num_tests, num_events1 );

	/* Gather before values */
	elapsed_us = PAPI_get_real_usec(  );
	elapsed_cyc = PAPI_get_real_cyc(  );
	elapsed_virt_us = PAPI_get_virt_usec(  );
	elapsed_virt_cyc = PAPI_get_virt_cyc(  );

	/* Wait for the SIGSTOP. */
	if ( cmpinfo->attach_must_ptrace ) {
	   if ( ptrace( PTRACE_CONT, pid, NULL, NULL ) == -1 ) {
	      perror( "ptrace(PTRACE_CONT)" );
	      return 1;
	   }
	   if ( waitpid( pid, &status, 0 ) == -1 ) {
	      perror( "waitpid()" );
	      exit( 1 );
	   }
	   if ( WIFSTOPPED( status ) == 0 ) {
	      test_fail( __FILE__, __LINE__,
			"Child process didn't return true to WIFSTOPPED", 0 );
	   }
	   if ( WSTOPSIG( status ) != SIGSTOP ) {
	      test_fail( __FILE__, __LINE__,
			"Child process didn't stop on SIGSTOP", 0 );
	   }

	   if ( ptrace( PTRACE_CONT, pid2, NULL, NULL ) == -1 ) {
	      perror( "ptrace(PTRACE_CONT)" );
	      return 1;
	   }
	   if ( waitpid( pid2, &status, 0 ) == -1 ) {
	      perror( "waitpid()" );
	      exit( 1 );
	   }
	   if ( WIFSTOPPED( status ) == 0 ) {
	      test_fail( __FILE__, __LINE__,
			"Child process didn't return true to WIFSTOPPED", 0 );
	   }
	   if ( WSTOPSIG( status ) != SIGSTOP ) {
	      test_fail( __FILE__, __LINE__,
			"Child process didn't stop on SIGSTOP", 0 );
	   }
	}

	/* start first child */
	retval = PAPI_start( EventSet1 );
	if ( retval != PAPI_OK ) {
		test_fail( __FILE__, __LINE__, "PAPI_start", retval );
	}

	/* start second child */
	retval = PAPI_start( EventSet2 );
	if ( retval != PAPI_OK ) {
		test_fail( __FILE__, __LINE__, "PAPI_start", retval );
	}

	/* Wait for the SIGSTOP. */
	if ( cmpinfo->attach_must_ptrace ) {
	   if ( ptrace( PTRACE_CONT, pid, NULL, NULL ) == -1 ) {
	      perror( "ptrace(PTRACE_ATTACH)" );
	      return 1;
	   }
	   if ( waitpid( pid, &status, 0 ) == -1 ) {
	      perror( "waitpid()" );
	      exit( 1 );
	   }
	   if ( WIFSTOPPED( status ) == 0 ) {
	      test_fail( __FILE__, __LINE__,
			"Child process didn't return true to WIFSTOPPED", 0 );
	   }
	   if ( WSTOPSIG( status ) != SIGSTOP ) {
	      test_fail( __FILE__, __LINE__,
			"Child process didn't stop on SIGSTOP", 0 );
	   }

	   if ( ptrace( PTRACE_CONT, pid2, NULL, NULL ) == -1 ) {
	       perror( "ptrace(PTRACE_ATTACH)" );
	       return 1;
	   }
	   if ( waitpid( pid2, &status, 0 ) == -1 ) {
	      perror( "waitpid()" );
	      exit( 1 );
	   }
	   if ( WIFSTOPPED( status ) == 0 ) {
	      test_fail( __FILE__, __LINE__,
			"Child process didn't return true to WIFSTOPPED", 0 );
	   }
	   if ( WSTOPSIG( status ) != SIGSTOP ) {
	      test_fail( __FILE__, __LINE__,
			"Child process didn't stop on SIGSTOP", 0 );
	   }
	}

	elapsed_virt_us = PAPI_get_virt_usec(  ) - elapsed_virt_us;
	elapsed_virt_cyc = PAPI_get_virt_cyc(  ) - elapsed_virt_cyc;
	elapsed_us = PAPI_get_real_usec(  ) - elapsed_us;
	elapsed_cyc = PAPI_get_real_cyc(  ) - elapsed_cyc;

	/* stop first child */
	retval = PAPI_stop( EventSet1, values[0] );
	if ( retval != PAPI_OK ) {
	   printf( "Warning: PAPI_stop returned error %d, probably ok.\n",
				retval );
	}

	/* stop second child */
	retval = PAPI_stop( EventSet2, values[1] );
	if ( retval != PAPI_OK ) {
	   printf( "Warning: PAPI_stop returned error %d, probably ok.\n",
				retval );
	}

	remove_test_events( &EventSet1, mask1 );
	remove_test_events( &EventSet2, mask2 );

	if ( cmpinfo->attach_must_ptrace ) {
	   if ( ptrace( PTRACE_CONT, pid, NULL, NULL ) == -1 ) {
	      perror( "ptrace(PTRACE_CONT)" );
	      return 1;
	   }
	   if ( ptrace( PTRACE_CONT, pid2, NULL, NULL ) == -1 ) {
	      perror( "ptrace(PTRACE_CONT)" );
	      return 1;
	   }
	}

	if ( waitpid( pid, &status, 0 ) == -1 ) {
	   perror( "waitpid()" );
	   exit( 1 );
	}
	if ( WIFEXITED( status ) == 0 ) {
	   test_fail( __FILE__, __LINE__,
		     "Child process didn't return true to WIFEXITED", 0 );
	}

	if ( waitpid( pid2, &status, 0 ) == -1 ) {
	   perror( "waitpid()" );
	   exit( 1 );
	}
	if ( WIFEXITED( status ) == 0 ) {
		test_fail( __FILE__, __LINE__,
			  "Child process didn't return true to WIFEXITED", 0 );
	}

	/* This code isn't necessary as we know the child has exited, */
	/* it *may* return an error if the component so chooses. You  */
        /* should use read() instead. */

	printf( "Test case: multiple 3rd party attach start, stop.\n" );
	printf( "-----------------------------------------------\n" );
	tmp = PAPI_get_opt( PAPI_DEFDOM, NULL );
	printf( "Default domain is: %d (%s)\n", tmp, 
		stringify_all_domains( tmp ) );
	tmp = PAPI_get_opt( PAPI_DEFGRN, NULL );
	printf( "Default granularity is: %d (%s)\n", tmp,
			stringify_granularity( tmp ) );
	printf( "Using %d iterations of c += a*b\n", NUM_FLOPS );
	printf( "-------------------------------------------------------------------------\n" );

	sprintf( add_event_str, "(PID %jd) %-12s : \t", ( intmax_t ) pid,
			 event_name );
	printf( TAB1, add_event_str, values[0][1] );
	sprintf( add_event_str, "(PID %jd) PAPI_TOT_CYC : \t", 
		 ( intmax_t ) pid );
	printf( TAB1, add_event_str, values[0][0] );
	sprintf( add_event_str, "(PID %jd) %-12s : \t", ( intmax_t ) pid2,
			 event_name );
	printf( TAB1, add_event_str,values[1][1] );
	sprintf( add_event_str, "(PID %jd) PAPI_TOT_CYC : \t", 
		 ( intmax_t ) pid2 );
	printf( TAB1, add_event_str, values[1][0] );
	printf( TAB1, "Real usec    : \t", elapsed_us );
	printf( TAB1, "Real cycles  : \t", elapsed_cyc );
	printf( TAB1, "Virt usec    : \t", elapsed_virt_us );
	printf( TAB1, "Virt cycles  : \t", elapsed_virt_cyc );

	printf
		( "-------------------------------------------------------------------------\n" );

	printf("Verification: pid %d results should be twice pid %d\n",pid2,pid );

	ratio1=(double)values[1][0]/(double)values[0][0];
	ratio2=(double)values[1][1]/(double)values[0][1];

	printf("\t%lld/%lld = %lf\n",values[1][0],values[0][0],ratio1);
	

	if ((ratio1 >2.15 ) || (ratio1 < 1.85)) {
	  printf("Ratio out of range, should be ~2.0 not %lf\n",ratio1);
	  test_fail( __FILE__, __LINE__,
		    "Error: Counter ratio not two", 0 );
	}

	printf("\t%lld/%lld = %lf\n",values[1][1],values[0][1],ratio2);

	if ((ratio2 >2.75 ) || (ratio2 < 1.25)) {
	  printf("Ratio out of range, should be ~2.0, not %lf\n",ratio2);
	  test_fail( __FILE__, __LINE__,
		    "Known issue: Counter ratio not two", 0 );
	}

	test_pass( __FILE__, values, num_tests );
	return 0;
}
コード例 #6
0
int main(int argc, char **argv)
{
    int retval, num_tests = 6, tmp;
    long long **values;
    int EventSet=PAPI_NULL;
    const PAPI_hw_info_t *hw_info;

#ifndef PENTIUM4
    test_skip(__FILE__, __LINE__, "This test is intended only for Pentium 4.", 1);
#endif

    tests_quiet(argc, argv);     /* Set TESTS_QUIET variable */

    retval = PAPI_library_init(PAPI_VER_CURRENT);
    if (retval != PAPI_VER_CURRENT)
        test_fail(__FILE__, __LINE__, "PAPI_library_init", retval);

    hw_info = PAPI_get_hardware_info();
    if (hw_info == NULL)
        test_fail(__FILE__, __LINE__, "PAPI_get_hardware_info", 2);

    retval = PAPI_create_eventset(&EventSet);
    if (retval != PAPI_OK)
        test_fail(__FILE__, __LINE__, "PAPI_create_eventset", retval);

    values = allocate_test_space(num_tests, 2);

    /* First test: just PAPI_LD_INS */
    retval = PAPI_add_event(EventSet, PAPI_LD_INS);
    if (retval != PAPI_OK)
        test_fail(__FILE__, __LINE__, "PAPI_add_event: PAPI_LD_INS", retval);

    retval = PAPI_start(EventSet);
    if (retval != PAPI_OK)
        test_fail(__FILE__, __LINE__, "PAPI_start", retval);

    do_flops(NUM_FLOPS/10);

    retval = PAPI_stop(EventSet, values[0]);
    if (retval != PAPI_OK)
        test_fail(__FILE__, __LINE__, "PAPI_stop", retval);

    retval = PAPI_remove_event(EventSet, PAPI_LD_INS);
    if (retval != PAPI_OK)
        test_fail(__FILE__, __LINE__, "PAPI_remove_event: PAPI_LD_INS", retval);

    /* Second test: just PAPI_SR_INS */
    retval = PAPI_add_event(EventSet, PAPI_SR_INS);
    if (retval != PAPI_OK)
        test_fail(__FILE__, __LINE__, "PAPI_add_event: PAPI_SR_INS", retval);

    retval = PAPI_start(EventSet);
    if (retval != PAPI_OK)
        test_fail(__FILE__, __LINE__, "PAPI_start", retval);

    do_flops(NUM_FLOPS/10);

    retval = PAPI_stop(EventSet, values[1]);
    if (retval != PAPI_OK)
        test_fail(__FILE__, __LINE__, "PAPI_stop", retval);

    retval = PAPI_remove_event(EventSet, PAPI_SR_INS);
    if (retval != PAPI_OK)
        test_fail(__FILE__, __LINE__, "PAPI_remove_event: PAPI_SR_INS", retval);

    /* Third test: just PAPI_LST_INS */
    retval = PAPI_add_event(EventSet, PAPI_LST_INS);
    if (retval != PAPI_OK)
        test_fail(__FILE__, __LINE__, "PAPI_add_event: PAPI_LST_INS", retval);

    retval = PAPI_start(EventSet);
    if (retval != PAPI_OK)
        test_fail(__FILE__, __LINE__, "PAPI_start", retval);

    do_flops(NUM_FLOPS/10);

    retval = PAPI_stop(EventSet, values[2]);
    if (retval != PAPI_OK)
        test_fail(__FILE__, __LINE__, "PAPI_stop", retval);

    /* Fourth test: PAPI_LST_INS and PAPI_LD_INS */
    retval = PAPI_add_event(EventSet, PAPI_LD_INS);
    if (retval != PAPI_OK)
        test_fail(__FILE__, __LINE__, "PAPI_add_event: PAPI_LD_INS", retval);

    retval = PAPI_start(EventSet);
    if (retval != PAPI_OK)
        test_fail(__FILE__, __LINE__, "PAPI_start", retval);

    do_flops(NUM_FLOPS/10);

    retval = PAPI_stop(EventSet, values[3]);
    if (retval != PAPI_OK)
        test_fail(__FILE__, __LINE__, "PAPI_stop", retval);

    retval = PAPI_remove_event(EventSet, PAPI_LD_INS);
    if (retval != PAPI_OK)
        test_fail(__FILE__, __LINE__, "PAPI_remove_event: PAPI_LD_INS", retval);

    /* Fifth test: PAPI_LST_INS and PAPI_SR_INS */
    retval = PAPI_add_event(EventSet, PAPI_SR_INS);
    if (retval != PAPI_OK)
        test_fail(__FILE__, __LINE__, "PAPI_add_event: PAPI_SR_INS", retval);

    retval = PAPI_start(EventSet);
    if (retval != PAPI_OK)
        test_fail(__FILE__, __LINE__, "PAPI_start", retval);

    do_flops(NUM_FLOPS/10);

    retval = PAPI_stop(EventSet, values[4]);
    if (retval != PAPI_OK)
        test_fail(__FILE__, __LINE__, "PAPI_stop", retval);

    retval = PAPI_remove_event(EventSet, PAPI_SR_INS);
    if (retval != PAPI_OK)
        test_fail(__FILE__, __LINE__, "PAPI_remove_event: PAPI_SR_INS", retval);

    retval = PAPI_remove_event(EventSet, PAPI_LST_INS);
    if (retval != PAPI_OK)
        test_fail(__FILE__, __LINE__, "PAPI_remove_event: PAPI_LST_INS", retval);

    /* Sixth test: PAPI_LD_INS and PAPI_SR_INS */
    retval = PAPI_add_event(EventSet, PAPI_LD_INS);
    if (retval != PAPI_OK)
        test_fail(__FILE__, __LINE__, "PAPI_add_event: PAPI_LD_INS", retval);

    retval = PAPI_add_event(EventSet, PAPI_SR_INS);
    if (retval != PAPI_OK)
        test_fail(__FILE__, __LINE__, "PAPI_add_event: PAPI_SR_INS", retval);

    retval = PAPI_start(EventSet);
    if (retval != PAPI_OK)
        test_fail(__FILE__, __LINE__, "PAPI_start", retval);

    do_flops(NUM_FLOPS/10);

    retval = PAPI_stop(EventSet, values[5]);
    if (retval != PAPI_OK)
        test_fail(__FILE__, __LINE__, "PAPI_stop", retval);

    retval = PAPI_remove_event(EventSet, PAPI_LD_INS);
    if (retval != PAPI_OK)
        test_fail(__FILE__, __LINE__, "PAPI_remove_event: PAPI_LD_INS", retval);

    retval = PAPI_remove_event(EventSet, PAPI_SR_INS);
    if (retval != PAPI_OK)
        test_fail(__FILE__, __LINE__, "PAPI_remove_event: PAPI_SR_INS", retval);



    if (!TESTS_QUIET) {
        printf("Pentium 4 Load / Store tests.\n");
        printf("These PAPI events are counted by setting a tag at the front of the pipeline,\n");
        printf("and counting tags at the back of the pipeline. All the tags are the same 'color'\n");
        printf("and can't be distinguished from each other. Therefore, PAPI_LD_INS and PAPI_SR_INS\n");
        printf("cannot be counted with the other two events, or the answer will always == PAPI_LST_INS.\n");
        printf("-------------------------------------------------------------------------------------------\n");
        tmp = PAPI_get_opt(PAPI_DEFDOM, NULL);
        printf("Default domain is: %d (%s)\n", tmp, stringify_all_domains(tmp));
        tmp = PAPI_get_opt(PAPI_DEFGRN, NULL);
        printf("Default granularity is: %d (%s)\n", tmp, stringify_granularity(tmp));
        printf("Using %d iterations of c += a*b\n", NUM_FLOPS/10);
        printf("-------------------------------------------------------------------------------------------\n");

        printf("Test:                1            2            3            4            5            6\n");
        printf("%s %12lld %12s %12s %12lld %12s %12lld\n",
               "PAPI_LD_INS: ", (values[0])[0], "------", "------",
               (values[3])[1], "------", (values[5])[0]);
        printf("%s %12s %12lld %12s %12s %12lld %12lld\n",
               "PAPI_SR_INS: ", "------", (values[1])[0], "------",
               "------", (values[4])[1], (values[5])[1]);
        printf("%s %12s %12s %12lld %12lld %12lld %12s\n",
               "PAPI_LST_INS:", "------", "------", (values[2])[0],
               (values[3])[0], (values[4])[0], "------");
        printf("-------------------------------------------------------------------------------------------\n");

        printf("Test 1: PAPI_LD_INS only.\n");
        printf("Test 2: PAPI_SR_INS only.\n");
        printf("Test 3: PAPI_LST_INS only.\n");
        printf("Test 4: PAPI_LD_INS and PAPI_LST_INS.\n");
        printf("Test 5: PAPI_SR_INS and PAPI_LST_INS.\n");
        printf("Test 6: PAPI_LD_INS and PAPI_SR_INS.\n");
        printf("Verification: Values within each column should be the same.\n");
        printf("              R3C3 ~= (R1C1 + R2C2) ~= all other entries.\n");
    }

    test_pass(__FILE__, values, num_tests);
    exit(1);
}
コード例 #7
0
ファイル: tenth.c プロジェクト: FMCalisto/SMP
int
main( int argc, char **argv )
{
	int retval, num_tests = 30, tmp;
	int EventSet1 = PAPI_NULL;
	int EventSet2 = PAPI_NULL;
	int EventSet3 = PAPI_NULL;
	int mask1 = MASK1;
	int mask2 = MASK2;
	int mask3 = MASK3;
	int num_events1;
	int num_events2;
	int num_events3;
	long long **values;
	int i, j;
	long long min[3];
	long long max[3];
	long long sum[3];

	tests_quiet( argc, argv );	/* Set TESTS_QUIET variable */

	retval = PAPI_library_init( PAPI_VER_CURRENT );
	if ( retval != PAPI_VER_CURRENT )
		test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );

	/* Make sure that required resources are available */
	/* Skip (don't fail!) if they are not */
	retval = PAPI_query_event( EVT1 );
	if ( retval != PAPI_OK )
		test_skip( __FILE__, __LINE__, EVT1_STR, retval );

	retval = PAPI_query_event( EVT2 );
	if ( retval != PAPI_OK )
		test_skip( __FILE__, __LINE__, EVT2_STR, retval );

	retval = PAPI_query_event( EVT3 );
	if ( retval != PAPI_OK )
		test_skip( __FILE__, __LINE__, EVT3_STR, retval );


	EventSet1 = add_test_events( &num_events1, &mask1, 1 );
	EventSet2 = add_test_events( &num_events2, &mask2, 1 );
	EventSet3 = add_test_events( &num_events3, &mask3, 1 );

	values = allocate_test_space( num_tests, 1 );

	/* Warm me up */
	do_l1misses( ITERS );
	do_misses( 1, 1024 * 1024 * 4 );

	for ( i = 0; i < 10; i++ ) {
		retval = PAPI_start( EventSet1 );
		if ( retval != PAPI_OK )
			test_fail( __FILE__, __LINE__, "PAPI_start", retval );

		do_l1misses( ITERS );
		do_misses( 1, 1024 * 1024 * 4 );

		retval = PAPI_stop( EventSet1, values[( i * 3 ) + 0] );
		if ( retval != PAPI_OK )
			test_fail( __FILE__, __LINE__, "PAPI_stop", retval );

		retval = PAPI_start( EventSet2 );
		if ( retval != PAPI_OK )
			test_fail( __FILE__, __LINE__, "PAPI_start", retval );

		do_l1misses( ITERS );
		do_misses( 1, 1024 * 1024 * 4 );

		retval = PAPI_stop( EventSet2, values[( i * 3 ) + 1] );
		if ( retval != PAPI_OK )
			test_fail( __FILE__, __LINE__, "PAPI_stop", retval );

		retval = PAPI_start( EventSet3 );
		if ( retval != PAPI_OK )
			test_fail( __FILE__, __LINE__, "PAPI_start", retval );

		do_l1misses( ITERS );
		do_misses( 1, 1024 * 1024 * 4 );

		retval = PAPI_stop( EventSet3, values[( i * 3 ) + 2] );
		if ( retval != PAPI_OK )
			test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
	}

	remove_test_events( &EventSet1, mask1 );
	remove_test_events( &EventSet2, mask2 );
	remove_test_events( &EventSet3, mask3 );

	for ( j = 0; j < 3; j++ ) {
		min[j] = 65535;
		max[j] = sum[j] = 0;
	}
	for ( i = 0; i < 10; i++ ) {
		for ( j = 0; j < 3; j++ ) {
			if ( min[j] > values[( i * 3 ) + j][0] )
				min[j] = values[( i * 3 ) + j][0];
			if ( max[j] < values[( i * 3 ) + j][0] )
				max[j] = values[( i * 3 ) + j][0];
			sum[j] += values[( i * 3 ) + j][0];
		}
	}

	if ( !TESTS_QUIET ) {
		printf( "Test case 10: start, stop for derived event %s.\n",
				CACHE_LEVEL );
		printf( "--------------------------------------------------------\n" );
		tmp = PAPI_get_opt( PAPI_DEFDOM, NULL );
		printf( "Default domain is: %d (%s)\n", tmp,
				stringify_all_domains( tmp ) );
		tmp = PAPI_get_opt( PAPI_DEFGRN, NULL );
		printf( "Default granularity is: %d (%s)\n", tmp,
				stringify_granularity( tmp ) );
		printf( "Using %d iterations of c += a*b\n", ITERS );
		printf( "Repeated 10 times\n" );
		printf
			( "-------------------------------------------------------------------------\n" );
/* 
      for (i=0;i<10;i++) {
         printf("Test type   : %12s%13s%13s\n", "1", "2", "3");
         printf(TAB3, EVT1_STR, values[(i*3)+0][0], (long long)0, (long long)0);
         printf(TAB3, EVT2_STR, (long long)0, values[(i*3)+1][0], (long long)0);
         printf(TAB3, EVT3_STR, (long long)0, (long long)0, values[(i*3)+2][0]);
         printf
            ("-------------------------------------------------------------------------\n");
      }
*/
		printf( "Test type   : %12s%13s%13s\n", "min", "max", "sum" );
		printf( TAB3, EVT1_STR, min[0], max[0], sum[0] );
		printf( TAB3, EVT2_STR, min[1], max[1], sum[1] );
		printf( TAB3, EVT3_STR, min[2], max[2], sum[2] );
		printf
			( "-------------------------------------------------------------------------\n" );
		printf( "Verification:\n" );
#if defined(sun) && defined(sparc)
		printf( TAB1, "Sum 1 approximately equals sum 2 - sum 3 or",
				( sum[1] - sum[2] ) );
#else
		printf( TAB1, "Sum 1 approximately equals sum 2 + sum 3 or",
				( sum[1] + sum[2] ) );
#endif
	}

	{
		long long tmin, tmax;

#if defined(sun) && defined(sparc)
		tmax = ( long long ) ( sum[1] - sum[2] );
#else
		tmax = ( long long ) ( sum[1] + sum[2] );
#endif

		printf( "percent error: %f\n",
				( float ) ( abs( ( int ) ( tmax - sum[0] ) ) * 100 / sum[0] ) );
		tmin = ( long long ) ( ( double ) tmax * 0.8 );
		tmax = ( long long ) ( ( double ) tmax * 1.2 );
		if ( sum[0] > tmax || sum[0] < tmin )
			test_fail( __FILE__, __LINE__, CACHE_LEVEL, 1 );
	}
	test_pass( __FILE__, values, num_tests );
	exit( 1 );
}