PAPI  5.3.2.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
native.c
Go to the documentation of this file.
1 /*
2 * File: native.c
3 * Mods: Maynard Johnson
4 * maynardj@us.ibm.com
5 */
6 
7 /*
8  This test defines an array of native event names, either at compile time
9  or at run time (some x86 platforms). It then:
10  - add the table of events to an event set;
11  - starts counting
12  - does a little work
13  - stops counting;
14  - reports the results.
15 */
16 
17 #include "papi_test.h"
18 
19 static int EventSet = PAPI_NULL;
20 extern int TESTS_QUIET; /* Declared in test_utils.c */
21 
22 
23 #if (defined(PPC32))
24  /* Select 4 events common to both ppc750 and ppc7450 */
25 static char *native_name[] = { "CPU_CLK", "FLOPS", "TOT_INS", "BR_MSP", NULL
26 };
27 
28 #elif defined(_POWER4) || defined(_PPC970)
29  /* arbitrarily code events from group 28: pm_fpu3 - Floating point events by unit */
30 static char *native_name[] =
31  { "PM_FPU0_FDIV", "PM_FPU1_FDIV", "PM_FPU0_FRSP_FCONV",
32 "PM_FPU1_FRSP_FCONV",
33  "PM_FPU0_FMA", "PM_FPU1_FMA", "PM_INST_CMPL", "PM_CYC", NULL
34 };
35 
36 #elif defined(_POWER5p)
37 /* arbitrarily code events from group 33: pm_fpustall - Floating Point Unit stalls */
38 static char *native_name[] =
39  { "PM_FPU_FULL_CYC", "PM_CMPLU_STALL_FDIV", "PM_CMPLU_STALL_FPU",
40  "PM_RUN_INST_CMPL", "PM_RUN_CYC", NULL
41 };
42 
43 
44 #elif defined(_POWER5)
45  /* arbitrarily code events from group 78: pm_fpu1 - Floating Point events */
46 static char *native_name[] =
47  { "PM_FPU_FDIV", "PM_FPU_FMA", "PM_FPU_FMOV_FEST", "PM_FPU_FEST",
48  "PM_INST_CMPL", "PM_RUN_CYC", NULL
49 };
50 
51 #elif defined(POWER3)
52 static char *native_name[] =
53  { "PM_IC_MISS", "PM_FPU1_CMPL", "PM_LD_MISS_L1", "PM_LD_CMPL",
54  "PM_FPU0_CMPL", "PM_CYC", "PM_TLB_MISS", NULL
55 };
56 
57 #elif defined(__ia64__)
58 #ifdef ITANIUM2
59 static char *native_name[] =
60  { "CPU_CYCLES", "L1I_READS", "L1D_READS_SET0", "IA64_INST_RETIRED", NULL
61 };
62 #else
63 static char *native_name[] =
64  { "DEPENDENCY_SCOREBOARD_CYCLE", "DEPENDENCY_ALL_CYCLE",
65  "UNSTALLED_BACKEND_CYCLE", "MEMORY_CYCLE", NULL
66 };
67 #endif
68 
69 #elif ((defined(linux) && (defined(__i386__) || (defined __x86_64__))) )
70 static char *p3_native_name[] = { "DATA_MEM_REFS", "DCU_LINES_IN", NULL };
71 static char *core_native_name[] = { "UnhltCore_Cycles", "Instr_Retired", NULL };
72 static char *k7_native_name[] =
73  { "TOT_CYC", "IC_MISSES", "DC_ACCESSES", "DC_MISSES", NULL };
74 // static char *k8_native_name[] = { "FP_ADD_PIPE", "FP_MULT_PIPE", "FP_ST_PIPE", "FP_NONE_RET", NULL };
75 static char *k8_native_name[] =
76  { "DISPATCHED_FPU:OPS_ADD", "DISPATCHED_FPU:OPS_MULTIPLY",
77 "DISPATCHED_FPU:OPS_STORE", "CYCLES_NO_FPU_OPS_RETIRED", NULL };
78 static char *p4_native_name[] =
79  { "retired_mispred_branch_type:CONDITIONAL", "resource_stall:SBFULL",
80  "tc_ms_xfer:CISC", "instr_retired:BOGUSNTAG:BOGUSTAG",
81  "BSQ_cache_reference:RD_2ndL_HITS", NULL
82 };
83 static char **native_name = p3_native_name;
84 
85 #elif defined(mips) && defined(sgi)
86 static char *native_name[] = { "Primary_instruction_cache_misses",
87  "Primary_data_cache_misses", NULL
88 };
89 #elif defined(mips) && defined(linux)
90 static char *native_name[] = { "CYCLES", NULL };
91 #elif defined(sun) && defined(sparc)
92 static char *native_name[] = { "Cycle_cnt", "Instr_cnt", NULL };
93 
94 #elif defined(_BGL)
95 static char *native_name[] =
96  { "BGL_UPC_PU0_PREF_STREAM_HIT", "BGL_PAPI_TIMEBASE",
97 "BGL_UPC_PU1_PREF_STREAM_HIT", NULL };
98 
99 #elif defined(__bgp__)
100 static char *native_name[] =
101  { "PNE_BGP_PU0_JPIPE_LOGICAL_OPS", "PNE_BGP_PU0_JPIPE_LOGICAL_OPS",
102 "PNE_BGP_PU2_IPIPE_INSTRUCTIONS", NULL };
103 
104 #else
105 #error "Architecture not supported in test file."
106 #endif
107 
108 
109 int
110 main( int argc, char **argv )
111 {
112  int i, retval, native;
113  const PAPI_hw_info_t *hwinfo;
114  long long values[8];
115 
116  tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */
117 
118  if ( ( retval =
120  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
121 
122  if ( ( retval = PAPI_create_eventset( &EventSet ) ) != PAPI_OK )
123  test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
124 
125  if ( ( hwinfo = PAPI_get_hardware_info( ) ) == NULL )
126  test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", PAPI_EMISC );
127 
128  printf( "Architecture %s, %d\n", hwinfo->model_string, hwinfo->model );
129 
130 #if ((defined(linux) && (defined(__i386__) || (defined __x86_64__))) )
131  if ( !strncmp( hwinfo->model_string, "Intel Pentium 4", 15 ) ) {
132  native_name = p4_native_name;
133  } else if ( !strncmp( hwinfo->model_string, "AMD K7", 6 ) ) {
134  native_name = k7_native_name;
135  } else if ( !strncmp( hwinfo->model_string, "AMD K8", 6 ) ) {
136  native_name = k8_native_name;
137  } else if ( !strncmp( hwinfo->model_string, "Intel Core", 17 ) ||
138  !strncmp( hwinfo->model_string, "Intel Core 2", 17 ) ) {
139  native_name = core_native_name;
140  }
141 #endif
142 
143  for ( i = 0; native_name[i] != NULL; i++ ) {
144  retval = PAPI_event_name_to_code( native_name[i], &native );
145  if ( retval != PAPI_OK )
146  test_fail( __FILE__, __LINE__, "PAPI_event_name_to_code", retval );
147  printf( "Adding %s\n", native_name[i] );
148  if ( ( retval = PAPI_add_event( EventSet, native ) ) != PAPI_OK )
149  test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );
150  }
151 
152  if ( ( retval = PAPI_start( EventSet ) ) != PAPI_OK )
153  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
154 
155  do_both( 1000 );
156 
157  if ( ( retval = PAPI_stop( EventSet, values ) ) != PAPI_OK )
158  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
159 
160  if ( !TESTS_QUIET ) {
161  for ( i = 0; native_name[i] != NULL; i++ ) {
162  fprintf( stderr, "%-40s: ", native_name[i] );
163  fprintf( stderr, LLDFMT, values[i] );
164  fprintf( stderr, "\n" );
165  }
166  }
167 
168  retval = PAPI_cleanup_eventset( EventSet );
169  if ( retval != PAPI_OK )
170  test_fail( __FILE__, __LINE__, "PAPI_cleanup", retval );
171  retval = PAPI_destroy_eventset( &EventSet );
172  if ( retval != PAPI_OK )
173  test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset", retval );
174 
175  test_pass( __FILE__, NULL, 0 );
176  exit( 0 );
177 }
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2232
#define PAPI_EMISC
Definition: fpapi.h:119
int PAPI_add_event(int EventSet, int EventCode)
Definition: papi.c:1604
Hardware info structure.
Definition: papi.h:775
#define PAPI_NULL
Definition: fpapi.h:13
return PAPI_OK
Definition: linux-nvml.c:458
tests_quiet(argc, argv)
#define printf
Definition: papi_test.h:125
test_pass(__FILE__, NULL, 0)
int int argc
Definition: iozone.c:1609
int TESTS_QUIET
Definition: test_utils.c:11
char ** argv
Definition: iozone.c:1610
test_fail(__FILE__, __LINE__,"PAPI_library_init", retval)
int PAPI_library_init(int version)
Definition: papi.c:495
int i
Definition: fileop.c:140
static int native
Definition: event_info.c:39
#define PAPI_VER_CURRENT
Definition: fpapi.h:14
int PAPI_cleanup_eventset(int EventSet)
Definition: papi.c:2805
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1406
native_name
int PAPI_event_name_to_code(char *in, int *out)
Definition: papi.c:1008
#define LLDFMT
Definition: papi_test.h:118
int EventSet
void do_both(int n)
int model
Definition: papi.h:784
int PAPI_destroy_eventset(int *EventSet)
Definition: papi.c:1944
char model_string[PAPI_MAX_STR_LEN]
Definition: papi.h:785
int PAPI_start(int EventSet)
Definition: papi.c:2026
const PAPI_hw_info_t * PAPI_get_hardware_info(void)
Definition: papi.c:6059
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
ssize_t retval
Definition: libasync.c:338
int main(int argc, char **argv)
List all appio events codes and names.
void exit()