PAPI 7.1.0.0
Loading...
Searching...
No Matches
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
19static int EventSet = PAPI_NULL;
20extern int TESTS_QUIET; /* Declared in test_utils.c */
21
22
23#if (defined(PPC32))
24 /* Select 4 events common to both ppc750 and ppc7450 */
25static 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 */
30static 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 */
38static 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 */
46static 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)
52static 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
59static char *native_name[] =
60 { "CPU_CYCLES", "L1I_READS", "L1D_READS_SET0", "IA64_INST_RETIRED", NULL
61};
62#else
63static 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__))) )
70static char *p3_native_name[] = { "DATA_MEM_REFS", "DCU_LINES_IN", NULL };
71static char *core_native_name[] = { "UnhltCore_Cycles", "Instr_Retired", NULL };
72static 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 };
75static char *k8_native_name[] =
76 { "DISPATCHED_FPU:OPS_ADD", "DISPATCHED_FPU:OPS_MULTIPLY",
77"DISPATCHED_FPU:OPS_STORE", "CYCLES_NO_FPU_OPS_RETIRED", NULL };
78static 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};
83static char **native_name = p3_native_name;
84
85#elif defined(mips) && defined(sgi)
86static char *native_name[] = { "Primary_instruction_cache_misses",
87 "Primary_data_cache_misses", NULL
88};
89#elif defined(mips) && defined(linux)
90static char *native_name[] = { "CYCLES", NULL };
91#elif defined(sun) && defined(sparc)
92static char *native_name[] = { "Cycle_cnt", "Instr_cnt", NULL };
93
94#elif defined(_BGL)
95static 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__)
100static 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
109int
110main( 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++ ) {
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
169 if ( retval != PAPI_OK )
170 test_fail( __FILE__, __LINE__, "PAPI_cleanup", retval );
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 i
add PAPI preset or native hardware event to an event set
Empty and destroy an EventSet.
Create a new empty PAPI EventSet.
Empty and destroy an EventSet.
Convert a name to a numeric hardware event code.
get information about the system hardware
initialize the PAPI library.
Start counting hardware events in an event set.
Stop counting hardware events in an event set.
void do_both(int n)
#define PAPI_VER_CURRENT
Definition: f90papi.h:54
#define PAPI_OK
Definition: f90papi.h:73
#define PAPI_NULL
Definition: f90papi.h:78
#define PAPI_EMISC
Definition: f90papi.h:122
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
static int EventSet
Definition: native.c:19
int TESTS_QUIET
Definition: test_utils.c:18
FILE * stderr
int tests_quiet(int argc, char **argv)
Definition: test_utils.c:376
#define LLDFMT
Definition: papi_test.h:104
void PAPI_NORETURN test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:491
void PAPI_NORETURN test_pass(const char *filename)
Definition: test_utils.c:432
static int native
int main()
Definition: pernode.c:20
Hardware info structure.
Definition: papi.h:774
int model
Definition: papi.h:783
char model_string[PAPI_MAX_STR_LEN]
Definition: papi.h:784
int retval
Definition: zero_fork.c:53