PAPI 7.1.0.0
Loading...
Searching...
No Matches
byte_profile.c
Go to the documentation of this file.
1/*
2* File: byte_profile.c
3* Author: Dan Terpstra
4* terpstra@cs.utk.edu
5* Mods: Maynard Johnson
6* maynardj@us.ibm.com
7*/
8
9/* This file profiles multiple events with byte level address resolution.
10 It's patterned after code suggested by John Mellor-Crummey, Rob Fowler,
11 and Nathan Tallent.
12 It is intended to illustrate the use of Multiprofiling on a very tight
13 block of code at byte level resolution of the instruction addresses.
14*/
15
16#include <stdio.h>
17#include <stdlib.h>
18#include <string.h>
19
20#include "papi.h"
21#include "papi_test.h"
22#include "prof_utils.h"
23
24#include "do_loops.h"
25
26#define PROFILE_ALL
27
28static const PAPI_hw_info_t *hw_info;
29
30static int num_events = 0;
31
32#define N (1 << 23)
33#define T (10)
34
35double aa[N], bb[N];
36double s = 0, s2 = 0;
37
38static void
39cleara( double a[N] )
40{
41 int i;
42
43 for ( i = 0; i < N; i++ ) {
44 a[i] = 0;
45 }
46}
47
48static int
49my_dummy( int i )
50{
51 return ( i + 1 );
52}
53
54static void
55my_main( void )
56{
57 int i, j;
58
59 for ( j = 0; j < T; j++ ) {
60 for ( i = 0; i < N; i++ ) {
61 bb[i] = 0;
62 }
63 cleara( aa );
64 memset( aa, 0, sizeof ( aa ) );
65 for ( i = 0; i < N; i++ ) {
66 s += aa[i] * bb[i];
67 s2 += aa[i] * aa[i] + bb[i] * bb[i];
68 }
69 }
70}
71
72static int
73do_profile( vptr_t start, unsigned long plength, unsigned scale, int thresh,
74 int bucket, unsigned int mask ) {
75
76 int i, retval;
77 unsigned long blength;
78 int num_buckets,j=0;
79
80 int num_bufs = num_events;
81 int event = num_events;
82
84 char header[BUFSIZ];
85
86 strncpy(header,"address\t\t",BUFSIZ);
87
88 //= "address\t\t\tcyc\tins\tfp_ins\n";
89
90 for(i=0;i<MAX_TEST_EVENTS;i++) {
91 if (mask & test_events[i].mask) {
93
94 if (events[j]==PAPI_TOT_CYC) {
95 strncat(header,"\tcyc",BUFSIZ-1);
96 }
97 if (events[j]==PAPI_TOT_INS) {
98 strncat(header,"\tins",BUFSIZ-1);
99 }
100 if (events[j]==PAPI_FP_INS) {
101 strncat(header,"\tfp_ins",BUFSIZ-1);
102 }
103 if (events[j]==PAPI_FP_OPS) {
104 strncat(header,"\tfp_ops",BUFSIZ-1);
105 }
106 if (events[j]==PAPI_L2_TCM) {
107 strncat(header,"\tl2_tcm",BUFSIZ-1);
108 }
109
110 j++;
111
112 }
113 }
114
115 strncat(header,"\n",BUFSIZ-1);
116
117
118
119 blength = prof_size( plength, scale, bucket, &num_buckets );
120 prof_alloc( num_bufs, blength );
121
122 if ( !TESTS_QUIET ) printf( "Overall event counts:\n" );
123
124 for ( i = 0; i < num_events; i++ ) {
125 if ( ( retval =
126 PAPI_profil( profbuf[i], ( unsigned int ) blength, start, scale,
127 EventSet, events[i], thresh,
128 PAPI_PROFIL_POSIX | bucket ) ) != PAPI_OK ) {
129 if (retval == PAPI_EINVAL) {
130 test_warn( __FILE__, __LINE__, "Trying to profile with derived event", 1);
132 break;
133 }
134 else {
135 printf("Failed with event %d %#x\n",i,events[i]);
136 test_fail( __FILE__, __LINE__, "PAPI_profil", retval );
137 }
138 }
139 }
140
141 if ( ( retval = PAPI_start( EventSet ) ) != PAPI_OK )
142 test_fail( __FILE__, __LINE__, "PAPI_start", retval );
143
144 my_main( );
145
146 if ( ( retval = PAPI_stop( EventSet, values[0] ) ) != PAPI_OK )
147 test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
148
149 if ( !TESTS_QUIET ) {
150 printf( TAB1, "PAPI_TOT_CYC:", ( values[0] )[--event] );
151 if ( strcmp( hw_info->model_string, "POWER6" ) != 0 ) {
152 printf( TAB1, "PAPI_TOT_INS:", ( values[0] )[--event] );
153 }
154#if defined(__powerpc__)
155 printf( TAB1, "PAPI_FP_INS", ( values[0] )[--event] );
156#else
157 if ( strcmp( hw_info->model_string, "Intel Pentium III" ) != 0 ) {
158 printf( TAB1, "PAPI_FP_OPS:", ( values[0] )[--event] );
159 printf( TAB1, "PAPI_L2_TCM:", ( values[0] )[--event] );
160 }
161#endif
162 }
163
164 for ( i = 0; i < num_events; i++ ) {
165 if ( ( retval =
166 PAPI_profil( profbuf[i], ( unsigned int ) blength, start, scale,
167 EventSet, events[i], 0,
169 test_fail( __FILE__, __LINE__, "PAPI_profil", retval );
170 }
171
172 if (!TESTS_QUIET) {
173 prof_head( blength, bucket, num_buckets, header );
174 prof_out( start, num_events, bucket, num_buckets, scale );
175 }
176 retval = prof_check( num_bufs, bucket, num_buckets );
177 for ( i = 0; i < num_bufs; i++ ) {
178 free( profbuf[i] );
179 }
180 return retval;
181}
182
183
184
185int
186main( int argc, char **argv )
187{
188 long length;
189 int mask;
190 int retval;
191 const PAPI_exe_info_t *prginfo;
192 vptr_t start, end;
193 int quiet;
194
195 /* Set TESTS_QUIET variable */
196 quiet=tests_quiet( argc, argv );
197
199 if (retval != PAPI_VER_CURRENT) {
200 test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
201 }
202
203 if ( ( prginfo = PAPI_get_executable_info( ) ) == NULL ) {
204 test_fail( __FILE__, __LINE__, "PAPI_get_executable_info", 1 );
205 }
206
208 if ( hw_info == NULL ) {
209 test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 );
210 }
211
213
214#if defined(__powerpc__)
215 if ( strcmp( hw_info->model_string, "POWER6" ) == 0 )
216 mask = MASK_TOT_CYC | MASK_FP_INS;
217 else
219#endif
220
221#if defined(ITANIUM2)
223#endif
224 EventSet = add_test_events( &num_events, &mask, 0 );
225 if (num_events==0) {
226 if (!quiet) printf("Trouble adding events\n");
227 test_skip(__FILE__,__LINE__,"add_test_events",2);
228 }
230
231/* profile the cleara and my_main address space */
232 start = ( vptr_t ) cleara;
233 end = ( vptr_t ) my_dummy;
234
235/* Itanium and PowerPC64 processors return function descriptors instead
236 * of function addresses. You must dereference the descriptor to get the address.
237*/
238#if defined(ITANIUM1) || defined(ITANIUM2) \
239 || (defined(__powerpc64__) && (_CALL_ELF != 2))
240 start = ( vptr_t ) ( ( ( struct fdesc * ) start )->ip );
241 end = ( vptr_t ) ( ( ( struct fdesc * ) end )->ip );
242 /* PPC64 Big Endian is ELF version 1 which uses function descriptors.
243 * PPC64 Little Endian is ELF version 2 which does not use
244 * function descriptors
245 */
246#endif
247
248 /* call dummy so it doesn't get optimized away */
249 retval = my_dummy( 1 );
250
251 length = end - start;
252 if ( length < 0 )
253 test_fail( __FILE__, __LINE__, "Profile length < 0!", ( int ) length );
254
255 if (!quiet) {
256 prof_print_address( "Test case byte_profile: "
257 "Multi-event profiling at byte resolution.\n",
258 prginfo );
260 }
261
262 retval = do_profile( start, ( unsigned ) length,
264 PAPI_PROFIL_BUCKET_32, mask );
265
267
268 if (retval == 0) {
269 test_fail( __FILE__, __LINE__, "No information in buffers", 1 );
270 }
271
272 test_pass( __FILE__ );
273
274 return 0;
275}
276
277
278
279
int i
#define N
Definition: byte_profile.c:32
#define T
Definition: byte_profile.c:33
double bb[N]
Definition: byte_profile.c:35
static const PAPI_hw_info_t * hw_info
Definition: byte_profile.c:28
static int num_events
Definition: byte_profile.c:30
double s2
Definition: byte_profile.c:36
static void cleara(double a[N])
Definition: byte_profile.c:39
static int my_dummy(int i)
Definition: byte_profile.c:49
double aa[N]
Definition: byte_profile.c:35
static void my_main(void)
Definition: byte_profile.c:55
double s
Definition: byte_profile.c:36
static int do_profile(vptr_t start, unsigned long plength, unsigned scale, int thresh, int bucket, unsigned int mask)
Definition: byte_profile.c:73
Get the executable's address space info.
get information about the system hardware
initialize the PAPI library.
Generate a histogram of hardware counter overflows vs. PC addresses.
Start counting hardware events in an event set.
Stop counting hardware events in an event set.
char event_name[2][PAPI_MAX_STR_LEN]
Definition: data_range.c:29
#define THRESHOLD
Definition: earprofile.c:37
#define PAPI_VER_CURRENT
Definition: f90papi.h:54
#define PAPI_PROFIL_BUCKET_32
Definition: f90papi.h:248
#define PAPI_OK
Definition: f90papi.h:73
#define PAPI_PROFIL_POSIX
Definition: f90papi.h:44
#define PAPI_TOT_CYC
Definition: f90papi.h:308
#define PAPI_L2_TCM
Definition: f90papi.h:320
#define PAPI_EINVAL
Definition: f90papi.h:115
#define PAPI_FP_INS
Definition: f90papi.h:366
#define PAPI_FP_OPS
Definition: f90papi.h:319
#define PAPI_TOT_INS
Definition: f90papi.h:317
char events[MAX_EVENTS][BUFSIZ]
static int EventSet
Definition: init_fini.c:8
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
static struct timeval start
static double a[MATRIX_SIZE][MATRIX_SIZE]
Definition: libmsr_basic.c:38
int TESTS_QUIET
Definition: test_utils.c:18
Return codes and api definitions.
void * vptr_t
Definition: papi.h:576
int tests_quiet(int argc, char **argv)
Definition: test_utils.c:376
int add_test_events(int *number, int *mask, int allow_derived)
Definition: test_utils.c:152
#define MASK_FP_OPS
Definition: papi_test.h:24
struct test_events_t test_events[]
Definition: test_utils.c:130
#define MASK_L2_TCM
Definition: papi_test.h:34
#define TAB1
Definition: papi_test.h:98
#define MASK_L1_DCM
Definition: papi_test.h:35
void PAPI_NORETURN test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:491
long long ** allocate_test_space(int num_tests, int num_events)
Definition: test_utils.c:46
#define MASK_FP_INS
Definition: papi_test.h:38
void PAPI_NORETURN test_pass(const char *filename)
Definition: test_utils.c:432
#define MASK_TOT_CYC
Definition: papi_test.h:40
#define MAX_TEST_EVENTS
Definition: papi_test.h:42
void test_warn(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:547
void PAPI_NORETURN test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:584
int remove_test_events(int *EventSet, int mask)
Definition: test_utils.c:201
#define MASK_TOT_INS
Definition: papi_test.h:39
int main()
Definition: pernode.c:20
int prof_check(int n, int bucket, int num_buckets)
Definition: prof_utils.c:272
void prof_head(unsigned long blength, int bucket, int num_buckets, const char *header)
Definition: prof_utils.c:183
void prof_print_prof_info(vptr_t start, vptr_t end, int threshold, char *event_name)
Definition: prof_utils.c:93
unsigned long prof_size(unsigned long plength, unsigned scale, int bucket, int *num_buckets)
Definition: prof_utils.c:310
void prof_alloc(int num, unsigned long blength)
Definition: prof_utils.c:140
void prof_out(vptr_t start, int n, int bucket, int num_buckets, unsigned int scale)
Definition: prof_utils.c:202
void prof_print_address(const char *title, const PAPI_exe_info_t *prginfo)
Definition: prof_utils.c:69
void * profbuf[5]
Definition: prof_utils.c:33
#define FULL_SCALE
Definition: prof_utils.h:20
unsigned int length
int quiet
Definition: rapl_overflow.c:19
get the executable's info
Definition: papi.h:696
Hardware info structure.
Definition: papi.h:774
char model_string[PAPI_MAX_STR_LEN]
Definition: papi.h:784
unsigned int event
Definition: papi_test.h:46
int retval
Definition: zero_fork.c:53