PAPI  5.6.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
data_range.c
Go to the documentation of this file.
1 /*
2 * File: data_range.c
3 * Author: Dan Terpstra
4 * terpstra@cs.utk.edu
5 * Mods: <your name here>
6 * <your email address>
7 */
8 
9 /* This file performs the following test: */
10 /* exercise the Itanium data address range interface */
11 
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <string.h>
15 
16 #include "papi.h"
17 #include "papi_test.h"
18 
19 #define NUM 16384
20 
21 static void init_array( void );
22 static int do_malloc_work( long loop );
23 static int do_static_work( long loop );
24 static void measure_load_store( caddr_t start, caddr_t end );
25 static void measure_event( int index, PAPI_option_t * option );
26 
30 int PAPI_event[2];
32 
33 int
34 main( int argc, char **argv )
35 {
36  int retval;
37  const PAPI_exe_info_t *prginfo = NULL;
38  const PAPI_hw_info_t *hw_info;
39 
40  /* Set TESTS_QUIET variable */
41  tests_quiet( argc, argv );
42 
43 #if !defined(ITANIUM2) && !defined(ITANIUM3)
44  test_skip( __FILE__, __LINE__, "Currently only works on itanium2", 0 );
45  exit( 1 );
46 #endif
47 
48  tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */
49 
50  init_array( );
51  printf( "Malloc'd array pointers: %p %p %p\n", &parray1, &parray2,
52  &parray3 );
53  printf( "Malloc'd array addresses: %p %p %p\n", parray1, parray2,
54  parray3 );
55  printf( "Static array addresses: %p %p %p\n", &array1, &array2,
56  &array3 );
57 
58  tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */
59 
60  if ( ( retval =
62  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
63 
64  hw_info = PAPI_get_hardware_info( );
65  if ( hw_info == NULL )
66  test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 );
67 
68  prginfo = PAPI_get_executable_info( );
69  if ( prginfo == NULL )
70  test_fail( __FILE__, __LINE__, "PAPI_get_executable_info", 1 );
71 
72 #if defined(linux) && defined(__ia64__)
73  sprintf( event_name[0], "loads_retired" );
74  sprintf( event_name[1], "stores_retired" );
77 #else
78  test_skip( __FILE__, __LINE__, "only works for Itanium", PAPI_ENOSUPP );
79 #endif
80 
81  if ( ( retval = PAPI_create_eventset( &EventSet ) ) != PAPI_OK )
82  test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
83 
84  retval = PAPI_cleanup_eventset( EventSet );
85  if ( retval != PAPI_OK )
86  test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset", retval );
87 
89  if ( retval != PAPI_OK )
90  test_fail( __FILE__, __LINE__, "PAPI_assign_eventset_component",
91  retval );
92 
93 /***************************************************************************************/
94  printf
95  ( "\n\nMeasure loads and stores on the pointers to the allocated arrays\n" );
96  printf( "Expected loads: %d; Expected stores: 0\n", NUM * 2 );
97  printf
98  ( "These loads result from accessing the pointers to compute array addresses.\n" );
99  printf
100  ( "They will likely disappear with higher levels of optimization.\n" );
101 
102  measure_load_store( ( caddr_t ) & parray1, ( caddr_t ) ( &parray1 + 1 ) );
103  measure_load_store( ( caddr_t ) & parray2, ( caddr_t ) ( &parray2 + 1 ) );
104  measure_load_store( ( caddr_t ) & parray3, ( caddr_t ) ( &parray3 + 1 ) );
105 /***************************************************************************************/
106  printf
107  ( "\n\nMeasure loads and stores on the allocated arrays themselves\n" );
108  printf( "Expected loads: %d; Expected stores: %d\n", NUM, NUM );
109 
110  measure_load_store( ( caddr_t ) parray1, ( caddr_t ) ( parray1 + NUM ) );
111  measure_load_store( ( caddr_t ) parray2, ( caddr_t ) ( parray2 + NUM ) );
112  measure_load_store( ( caddr_t ) parray3, ( caddr_t ) ( parray3 + NUM ) );
113 /***************************************************************************************/
114  printf( "\n\nMeasure loads and stores on the static arrays\n" );
115  printf
116  ( "These values will differ from the expected values by the size of the offsets.\n" );
117  printf( "Expected loads: %d; Expected stores: %d\n", NUM, NUM );
118 
119  measure_load_store( ( caddr_t ) array1, ( caddr_t ) ( array1 + NUM ) );
120  measure_load_store( ( caddr_t ) array2, ( caddr_t ) ( array2 + NUM ) );
121  measure_load_store( ( caddr_t ) array3, ( caddr_t ) ( array3 + NUM ) );
122 /***************************************************************************************/
123 
124  retval = PAPI_destroy_eventset( &EventSet );
125  if ( retval != PAPI_OK )
126  test_fail( __FILE__, __LINE__, "PAPI_destroy", retval );
127 
128  free( parray1 );
129  free( parray2 );
130  free( parray3 );
131 
132  test_pass( __FILE__ );
133 
134  return 0;
135 
136 }
137 
138 static void
139 measure_load_store( caddr_t start, caddr_t end )
140 {
141  PAPI_option_t option;
142  int retval;
143 
144  /* set up the optional address structure for starting and ending data addresses */
145  option.addr.eventset = EventSet;
146  option.addr.start = start;
147  option.addr.end = end;
148 
149  if ( ( retval = PAPI_set_opt( PAPI_DATA_ADDRESS, &option ) ) != PAPI_OK )
150  test_fail( __FILE__, __LINE__, "PAPI_set_opt(PAPI_DATA_ADDRESS)",
151  retval );
152 
153  measure_event( 0, &option );
154  measure_event( 1, &option );
155 }
156 
157 static void
158 measure_event( int index, PAPI_option_t * option )
159 {
160  int retval;
161  long long value;
162 
163  if ( ( retval = PAPI_add_event( EventSet, PAPI_event[index] ) ) != PAPI_OK )
164  test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );
165 
166  if ( index == 0 ) {
167 /* if ((retval = PAPI_get_opt(PAPI_DATA_ADDRESS, option)) != PAPI_OK)
168  test_fail(__FILE__, __LINE__, "PAPI_get_opt(PAPI_DATA_ADDRESS)", retval);
169 */
170  printf
171  ( "Requested Start Address: %p; Start Offset: %#5x; Actual Start Address: %p\n",
172  option->addr.start, option->addr.start_off,
173  option->addr.start - option->addr.start_off );
174  printf
175  ( "Requested End Address: %p; End Offset: %#5x; Actual End Address: %p\n",
176  option->addr.end, option->addr.end_off,
177  option->addr.end + option->addr.end_off );
178  }
179 
180  retval = PAPI_start( EventSet );
181  if ( retval != PAPI_OK ) {
182  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
183  }
184  do_malloc_work( NUM );
185  do_static_work( NUM );
186  retval = PAPI_stop( EventSet, &value );
187  if ( retval != PAPI_OK ) {
188  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
189  }
190 
191  printf( "%s: %lld\n", event_name[index], value );
192 
193  if ( ( retval =
194  PAPI_remove_event( EventSet, PAPI_event[index] ) ) != PAPI_OK )
195  test_fail( __FILE__, __LINE__, "PAPI_remove_event", retval );
196 }
197 
198 static void
199 init_array( void )
200 {
201  parray1 = ( int * ) malloc( NUM * sizeof ( int ) );
202  if ( parray1 == NULL )
203  test_fail( __FILE__, __LINE__, "No memory available!\n", 0 );
204  memset( parray1, 0x0, NUM * sizeof ( int ) );
205 
206  parray2 = ( int * ) malloc( NUM * sizeof ( int ) );
207  if ( parray2 == NULL )
208  test_fail( __FILE__, __LINE__, "No memory available!\n", 0 );
209  memset( parray2, 0x0, NUM * sizeof ( int ) );
210 
211  parray3 = ( int * ) malloc( NUM * sizeof ( int ) );
212  if ( parray3 == NULL )
213  test_fail( __FILE__, __LINE__, "No memory available!\n", 0 );
214  memset( parray3, 0x0, NUM * sizeof ( int ) );
215 
216 }
217 
218 static int
220 {
221  int i;
222  int sum = 0;
223 
224  for ( i = 0; i < loop; i++ ) {
225  array1[i] = i;
226  sum += array1[i];
227  }
228 
229  for ( i = 0; i < loop; i++ ) {
230  array2[i] = i;
231  sum += array2[i];
232  }
233 
234  for ( i = 0; i < loop; i++ ) {
235  array3[i] = i;
236  sum += array3[i];
237  }
238 
239  return sum;
240 }
241 
242 static int
244 {
245  int i;
246  int sum = 0;
247 
248  for ( i = 0; i < loop; i++ ) {
249  parray1[i] = i;
250  sum += parray1[i];
251  }
252 
253  for ( i = 0; i < loop; i++ ) {
254  parray2[i] = i;
255  sum += parray2[i];
256  }
257 
258  for ( i = 0; i < loop; i++ ) {
259  parray3[i] = i;
260  sum += parray3[i];
261  }
262 
263  return sum;
264 }
char event_name[2][PAPI_MAX_STR_LEN]
Definition: data_range.c:29
sprintf(splash[splash_line++],"\tIozone: Performance Test of File I/O\n")
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2314
int PAPI_event[2]
Definition: data_range.c:30
int * parray3
Definition: data_range.c:27
void test_pass(const char *filename)
Definition: test_utils.c:432
int PAPI_add_event(int EventSet, int EventCode)
Definition: papi.c:1663
Hardware info structure.
Definition: papi.h:780
static int do_malloc_work(long loop)
Definition: data_range.c:243
start
Definition: iozone.c:22736
int PAPI_remove_event(int EventSet, int EventCode)
Definition: papi.c:1758
#define PAPI_ENOSUPP
Definition: papi.h:271
#define PAPI_NULL
Definition: papi.h:292
#define PAPI_DATA_ADDRESS
Definition: papi.h:452
int EventSet
get the executable&#39;s info
Definition: papi.h:707
return PAPI_OK
Definition: linux-nvml.c:497
int PAPI_event_name_to_code(const char *in, int *out)
Definition: papi.c:1004
A pointer to the following is passed to PAPI_set/get_opt()
Definition: papi.h:848
double loop(long n)
Definition: kufrin.c:26
void double value
Definition: iozone.c:18781
int PAPI_set_opt(int option, PAPI_option_t *ptr)
Definition: papi.c:3465
int int argc
Definition: iozone.c:1609
Return codes and api definitions.
int * parray1
Definition: data_range.c:27
void test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:559
PAPI_addr_range_option_t addr
Definition: papi.h:865
char ** argv
Definition: iozone.c:1610
int PAPI_library_init(int version)
Definition: papi.c:500
int i
Definition: fileop.c:140
const PAPI_exe_info_t * PAPI_get_executable_info(void)
Definition: papi.c:6114
free(dummyfile[xx])
#define NUM
Definition: data_range.c:19
int PAPI_cleanup_eventset(int EventSet)
Definition: papi.c:2890
int PAPI_assign_eventset_component(int EventSet, int cidx)
Definition: papi.c:1526
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1464
int array3[NUM]
Definition: data_range.c:28
static void measure_load_store(caddr_t start, caddr_t end)
Definition: data_range.c:139
int array2[NUM]
Definition: data_range.c:28
printf("\tTry: -i 0 -i 1 \n\n")
int tests_quiet(int argc, char **argv)
Definition: test_utils.c:376
void test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:468
int PAPI_destroy_eventset(int *EventSet)
Definition: papi.c:2014
#define PAPI_MAX_STR_LEN
Definition: papi.h:465
static void init_array(void)
Definition: data_range.c:199
int PAPI_start(int EventSet)
Definition: papi.c:2096
static void measure_event(int index, PAPI_option_t *option)
Definition: data_range.c:158
const PAPI_hw_info_t * PAPI_get_hardware_info(void)
Definition: papi.c:6185
ssize_t retval
Definition: libasync.c:338
#define PAPI_VER_CURRENT
Definition: papi.h:225
static const PAPI_hw_info_t * hw_info
Definition: byte_profile.c:28
int main(int argc, char **argv)
List all appio events codes and names.
int * parray2
Definition: data_range.c:27
void exit()
static int do_static_work(long loop)
Definition: data_range.c:219
int array1[NUM]
Definition: data_range.c:28