PAPI  5.3.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
byte_profile.c
Go to the documentation of this file.
1 /*
2 * File: byte_profile.c
3 * CVS: $Id$
4 * Author: Dan Terpstra
5 * terpstra@cs.utk.edu
6 * Mods: Maynard Johnson
7 * maynardj@us.ibm.com
8 * Mods: <your name here>
9 * <your email address>
10 */
11 
12 /* This file profiles multiple events with byte level address resolution.
13  It's patterned after code suggested by John Mellor-Crummey, Rob Fowler,
14  and Nathan Tallent.
15  It is intended to illustrate the use of Multiprofiling on a very tight
16  block of code at byte level resolution of the instruction addresses.
17 */
18 
19 #include "papi_test.h"
20 #include "prof_utils.h"
21 #define PROFILE_ALL
22 
23 static const PAPI_hw_info_t *hw_info;
24 
25 static int num_events = 0;
26 
27 #define N (1 << 23)
28 #define T (10)
29 
30 double aa[N], bb[N];
31 double s = 0, s2 = 0;
32 
33 static void
34 cleara( double a[N] )
35 {
36  int i;
37 
38  for ( i = 0; i < N; i++ ) {
39  a[i] = 0;
40  }
41 }
42 
43 static int
44 my_dummy( int i )
45 {
46  return ( i + 1 );
47 }
48 
49 static void
51 {
52  int i, j;
53 
54  for ( j = 0; j < T; j++ ) {
55  for ( i = 0; i < N; i++ ) {
56  bb[i] = 0;
57  }
58  cleara( aa );
59  memset( aa, 0, sizeof ( aa ) );
60  for ( i = 0; i < N; i++ ) {
61  s += aa[i] * bb[i];
62  s2 += aa[i] * aa[i] + bb[i] * bb[i];
63  }
64  }
65 }
66 
67 static int
68 do_profile( caddr_t start, unsigned long plength, unsigned scale, int thresh,
69  int bucket, unsigned int mask ) {
70 
71  int i, retval;
72  unsigned long blength;
73  int num_buckets,j=0;
74 
75  int num_bufs = num_events;
76  int event = num_events;
77 
79  char header[BUFSIZ];
80 
81  strncpy(header,"address\t\t",BUFSIZ);
82 
83  //= "address\t\t\tcyc\tins\tfp_ins\n";
84 
85  for(i=0;i<MAX_TEST_EVENTS;i++) {
86  if (mask & test_events[i].mask) {
87  events[j]=test_events[i].event;
88 
89  if (events[j]==PAPI_TOT_CYC) {
90  strncat(header,"\tcyc",BUFSIZ-1);
91  }
92  if (events[j]==PAPI_TOT_INS) {
93  strncat(header,"\tins",BUFSIZ-1);
94  }
95  if (events[j]==PAPI_FP_INS) {
96  strncat(header,"\tfp_ins",BUFSIZ-1);
97  }
98  if (events[j]==PAPI_FP_OPS) {
99  strncat(header,"\tfp_ops",BUFSIZ-1);
100  }
101  if (events[j]==PAPI_L2_TCM) {
102  strncat(header,"\tl2_tcm",BUFSIZ-1);
103  }
104 
105  j++;
106 
107  }
108  }
109 
110  strncat(header,"\n",BUFSIZ-1);
111 
112 
113 
114  blength = prof_size( plength, scale, bucket, &num_buckets );
115  prof_alloc( num_bufs, blength );
116 
117  if ( !TESTS_QUIET )
118  printf( "Overall event counts:\n" );
119 
120  for ( i = 0; i < num_events; i++ ) {
121  if ( ( retval =
122  PAPI_profil( profbuf[i], ( unsigned int ) blength, start, scale,
123  EventSet, events[i], thresh,
124  PAPI_PROFIL_POSIX | bucket ) ) != PAPI_OK ) {
125  if (retval == PAPI_EINVAL) {
126  test_warn( __FILE__, __LINE__, "Trying to profile with derived event", 1);
127  num_events=i;
128  break;
129  }
130  else {
131  printf("Failed with event %d %#x\n",i,events[i]);
132  test_fail( __FILE__, __LINE__, "PAPI_profil", retval );
133  }
134  }
135  }
136 
137  if ( ( retval = PAPI_start( EventSet ) ) != PAPI_OK )
138  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
139 
140  my_main( );
141 
142  if ( ( retval = PAPI_stop( EventSet, values[0] ) ) != PAPI_OK )
143  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
144 
145  if ( !TESTS_QUIET ) {
146  printf( TAB1, "PAPI_TOT_CYC:", ( values[0] )[--event] );
147  if ( strcmp( hw_info->model_string, "POWER6" ) != 0 ) {
148  printf( TAB1, "PAPI_TOT_INS:", ( values[0] )[--event] );
149  }
150 #if defined(__powerpc__)
151  printf( TAB1, "PAPI_FP_INS", ( values[0] )[--event] );
152 #else
153  if ( strcmp( hw_info->model_string, "Intel Pentium III" ) != 0 ) {
154  printf( TAB1, "PAPI_FP_OPS:", ( values[0] )[--event] );
155  printf( TAB1, "PAPI_L2_TCM:", ( values[0] )[--event] );
156  }
157 #endif
158  }
159 
160  for ( i = 0; i < num_events; i++ ) {
161  if ( ( retval =
162  PAPI_profil( profbuf[i], ( unsigned int ) blength, start, scale,
163  EventSet, events[i], 0,
164  PAPI_PROFIL_POSIX ) ) != PAPI_OK )
165  test_fail( __FILE__, __LINE__, "PAPI_profil", retval );
166  }
167 
168  prof_head( blength, bucket, num_buckets, header );
169  prof_out( start, num_events, bucket, num_buckets, scale );
170  retval = prof_check( num_bufs, bucket, num_buckets );
171  for ( i = 0; i < num_bufs; i++ ) {
172  free( profbuf[i] );
173  }
174  return retval;
175 }
176 
177 
178 
179 int
180 main( int argc, char **argv )
181 {
182  long length;
183  int mask;
184  int retval;
185  const PAPI_exe_info_t *prginfo;
186  caddr_t start, end;
187 
188  prof_init( argc, argv, &prginfo );
189 
190  hw_info = PAPI_get_hardware_info( );
191  if ( hw_info == NULL )
192  test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 );
193 
195 
196 #if defined(__powerpc__)
197  if ( strcmp( hw_info->model_string, "POWER6" ) == 0 )
198  mask = MASK_TOT_CYC | MASK_FP_INS;
199  else
201 #endif
202 
203 #if defined(ITANIUM2)
205 #endif
206  EventSet = add_test_events( &num_events, &mask, 0 );
208 
209 /* profile the cleara and my_main address space */
210  start = ( caddr_t ) cleara;
211  end = ( caddr_t ) my_dummy;
212 
213 /* Itanium and PowerPC64 processors return function descriptors instead
214  * of function addresses. You must dereference the descriptor to get the address.
215 */
216 #if defined(ITANIUM1) || defined(ITANIUM2) || defined(__powerpc64__)
217  start = ( caddr_t ) ( ( ( struct fdesc * ) start )->ip );
218  end = ( caddr_t ) ( ( ( struct fdesc * ) end )->ip );
219 #endif
220 
221  /* call dummy so it doesn't get optimized away */
222  retval = my_dummy( 1 );
223 
224  length = end - start;
225  if ( length < 0 )
226  test_fail( __FILE__, __LINE__, "Profile length < 0!", ( int ) length );
227 
229  ( "Test case byte_profile: Multi-event profiling at byte resolution.\n",
230  prginfo );
231  prof_print_prof_info( start, end, THRESHOLD, event_name );
232 
233  retval =
234  do_profile( start, ( unsigned ) length,
235  FULL_SCALE * 2, THRESHOLD,
236  PAPI_PROFIL_BUCKET_32, mask );
237 
238  remove_test_events( &EventSet, mask );
239 
240  if ( retval )
241  test_pass( __FILE__, values, 1 );
242  else
243  test_fail( __FILE__, __LINE__, "No information in buffers", 1 );
244  return 1;
245 }
246 
247 
248 
249 
char event_name[2][PAPI_MAX_STR_LEN]
Definition: data_range.c:23
memset(eventId, 0, size)
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2225
#define PAPI_L2_TCM
Definition: fpapi.h:142
unsigned long long length
Definition: iozone.c:17106
void prof_print_address(char *title, const PAPI_exe_info_t *prginfo)
Definition: prof_utils.c:82
Hardware info structure.
Definition: papi.h:775
void prof_head(unsigned long blength, int bucket, int num_buckets, char *header)
Definition: prof_utils.c:194
struct in_addr * ip
Definition: iozone.c:20416
start
Definition: iozone.c:22736
#define T
Definition: byte_profile.c:28
#define PAPI_TOT_INS
Definition: fpapi.h:185
static int num_events
#define TAB1
Definition: papi_test.h:112
device[deviceId] domain[domainId] event
Definition: linux-cuda.c:306
#define MAX_TEST_EVENTS
Definition: papi_test.h:51
get the executable&#39;s info
Definition: papi.h:702
return PAPI_OK
Definition: linux-nvml.c:458
#define PAPI_FP_OPS
Definition: fpapi.h:237
double aa[N]
Definition: byte_profile.c:30
#define PAPI_PROFIL_POSIX
Definition: fpapi.h:75
return PAPI_EINVAL
Definition: linux-nvml.c:408
#define printf
Definition: papi_test.h:125
test_pass(__FILE__, NULL, 0)
int int argc
Definition: iozone.c:1609
static double a[MATRIX_SIZE][MATRIX_SIZE]
Definition: rapl_basic.c:37
int TESTS_QUIET
Definition: test_utils.c:11
char ** argv
Definition: iozone.c:1610
unsigned long prof_size(unsigned long plength, unsigned scale, int bucket, int *num_buckets)
Definition: prof_utils.c:321
#define MASK_FP_INS
Definition: papi_test.h:47
test_fail(__FILE__, __LINE__,"PAPI_library_init", retval)
int PAPI_profil(void *buf, unsigned bufsiz, caddr_t offset, unsigned scale, int EventSet, int EventCode, int threshold, int flags)
Definition: papi.c:5303
int i
Definition: fileop.c:140
void test_warn(char *file, int line, char *call, int retval)
Definition: test_utils.c:578
void prof_out(caddr_t start, int n, int bucket, int num_buckets, unsigned int scale)
Definition: prof_utils.c:213
static void cleara(double a[N])
Definition: byte_profile.c:34
#define PAPI_TOT_CYC
Definition: fpapi.h:194
#define FULL_SCALE
Definition: prof_utils.h:23
free(dummyfile[xx])
static void my_main()
Definition: byte_profile.c:50
void * profbuf[5]
Definition: prof_utils.c:28
s
Definition: iozone.c:20289
static int my_dummy(int i)
Definition: byte_profile.c:44
char events[MAX_EVENTS][BUFSIZ]
double bb[N]
Definition: byte_profile.c:30
#define PAPI_FP_INS
Definition: fpapi.h:187
#define MASK_TOT_CYC
Definition: papi_test.h:49
double s2
Definition: byte_profile.c:31
#define MASK_FP_OPS
Definition: papi_test.h:33
#define N
Definition: byte_profile.c:27
int EventSet
#define MASK_TOT_INS
Definition: papi_test.h:48
struct test_events_t test_events[]
Definition: test_utils.c:191
void prof_init(int argc, char **argv, const PAPI_exe_info_t **prginfo)
Definition: prof_utils.c:39
void prof_print_prof_info(caddr_t start, caddr_t end, int threshold, char *event_name)
Definition: prof_utils.c:106
#define MASK_L2_TCM
Definition: papi_test.h:43
#define MASK_L1_DCM
Definition: papi_test.h:44
int prof_check(int n, int bucket, int num_buckets)
Definition: prof_utils.c:283
unsigned int event
Definition: papi_test.h:55
char model_string[PAPI_MAX_STR_LEN]
Definition: papi.h:785
static int do_profile(caddr_t start, unsigned long plength, unsigned scale, int thresh, int bucket, unsigned int mask)
Definition: byte_profile.c:68
#define PAPI_PROFIL_BUCKET_32
Definition: fpapi.h:80
int PAPI_start(int EventSet)
Definition: papi.c:2019
#define THRESHOLD
Definition: earprofile.c:31
long j
Definition: iozone.c:19135
const PAPI_hw_info_t * PAPI_get_hardware_info(void)
Definition: papi.c:6046
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
ssize_t retval
Definition: libasync.c:338
long long ** allocate_test_space(int num_tests, int num_events)
Definition: test_utils.c:107
static const PAPI_hw_info_t * hw_info
Definition: byte_profile.c:23
int main(int argc, char **argv)
List all appio events codes and names.
int remove_test_events(int *EventSet, int mask)
Definition: test_utils.c:277
void prof_alloc(int num, unsigned long blength)
Definition: prof_utils.c:151
int add_test_events(int *number, int *mask, int allow_derived)
Definition: test_utils.c:213