PAPI  5.3.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 "papi_test.h"
13 #define NUM 16384
14 
15 static void init_array( void );
16 static int do_malloc_work( long loop );
17 static int do_static_work( long loop );
18 static void measure_load_store( caddr_t start, caddr_t end );
19 static void measure_event( int index, PAPI_option_t * option );
20 
24 int PAPI_event[2];
26 
27 int
28 main( int argc, char **argv )
29 {
30  int retval;
31  const PAPI_exe_info_t *prginfo = NULL;
32  const PAPI_hw_info_t *hw_info;
33 
34  /* Set TESTS_QUIET variable */
35  tests_quiet( argc, argv );
36 
37 #if !defined(ITANIUM2) && !defined(ITANIUM3)
38  test_skip( __FILE__, __LINE__, "Currently only works on itanium2", 0 );
39  exit( 1 );
40 #endif
41 
42  tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */
43 
44  init_array( );
45  printf( "Malloc'd array pointers: %p %p %p\n", &parray1, &parray2,
46  &parray3 );
47  printf( "Malloc'd array addresses: %p %p %p\n", parray1, parray2,
48  parray3 );
49  printf( "Static array addresses: %p %p %p\n", &array1, &array2,
50  &array3 );
51 
52  tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */
53 
54  if ( ( retval =
56  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
57 
58  hw_info = PAPI_get_hardware_info( );
59  if ( hw_info == NULL )
60  test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 );
61 
62  if ( ( prginfo = PAPI_get_executable_info( ) ) == NULL )
63  test_fail( __FILE__, __LINE__, "PAPI_get_executable_info", 1 );
64 
65 #if defined(linux) && defined(__ia64__)
66  sprintf( event_name[0], "loads_retired" );
67  sprintf( event_name[1], "stores_retired" );
70 #else
71  test_skip( __FILE__, __LINE__, "only works for Itanium", PAPI_ENOSUPP );
72 #endif
73 
74  if ( ( retval = PAPI_create_eventset( &EventSet ) ) != PAPI_OK )
75  test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
76 
77  retval = PAPI_cleanup_eventset( EventSet );
78  if ( retval != PAPI_OK )
79  test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset", retval );
80 
82  if ( retval != PAPI_OK )
83  test_fail( __FILE__, __LINE__, "PAPI_assign_eventset_component",
84  retval );
85 
86 /***************************************************************************************/
87  printf
88  ( "\n\nMeasure loads and stores on the pointers to the allocated arrays\n" );
89  printf( "Expected loads: %d; Expected stores: 0\n", NUM * 2 );
90  printf
91  ( "These loads result from accessing the pointers to compute array addresses.\n" );
92  printf
93  ( "They will likely disappear with higher levels of optimization.\n" );
94 
95  measure_load_store( ( caddr_t ) & parray1, ( caddr_t ) ( &parray1 + 1 ) );
96  measure_load_store( ( caddr_t ) & parray2, ( caddr_t ) ( &parray2 + 1 ) );
97  measure_load_store( ( caddr_t ) & parray3, ( caddr_t ) ( &parray3 + 1 ) );
98 /***************************************************************************************/
99  printf
100  ( "\n\nMeasure loads and stores on the allocated arrays themselves\n" );
101  printf( "Expected loads: %d; Expected stores: %d\n", NUM, NUM );
102 
103  measure_load_store( ( caddr_t ) parray1, ( caddr_t ) ( parray1 + NUM ) );
104  measure_load_store( ( caddr_t ) parray2, ( caddr_t ) ( parray2 + NUM ) );
105  measure_load_store( ( caddr_t ) parray3, ( caddr_t ) ( parray3 + NUM ) );
106 /***************************************************************************************/
107  printf( "\n\nMeasure loads and stores on the static arrays\n" );
108  printf
109  ( "These values will differ from the expected values by the size of the offsets.\n" );
110  printf( "Expected loads: %d; Expected stores: %d\n", NUM, NUM );
111 
112  measure_load_store( ( caddr_t ) array1, ( caddr_t ) ( array1 + NUM ) );
113  measure_load_store( ( caddr_t ) array2, ( caddr_t ) ( array2 + NUM ) );
114  measure_load_store( ( caddr_t ) array3, ( caddr_t ) ( array3 + NUM ) );
115 /***************************************************************************************/
116 
117  retval = PAPI_destroy_eventset( &EventSet );
118  if ( retval != PAPI_OK )
119  test_fail( __FILE__, __LINE__, "PAPI_destroy", retval );
120 
121  free( parray1 );
122  free( parray2 );
123  free( parray3 );
124 
125  test_pass( __FILE__, NULL, 0 );
126 
127  exit( 1 );
128 }
129 
130 static void
131 measure_load_store( caddr_t start, caddr_t end )
132 {
133  PAPI_option_t option;
134  int retval;
135 
136  /* set up the optional address structure for starting and ending data addresses */
137  option.addr.eventset = EventSet;
138  option.addr.start = start;
139  option.addr.end = end;
140 
141  if ( ( retval = PAPI_set_opt( PAPI_DATA_ADDRESS, &option ) ) != PAPI_OK )
142  test_fail( __FILE__, __LINE__, "PAPI_set_opt(PAPI_DATA_ADDRESS)",
143  retval );
144 
145  measure_event( 0, &option );
146  measure_event( 1, &option );
147 }
148 
149 static void
150 measure_event( int index, PAPI_option_t * option )
151 {
152  int retval;
153  long long value;
154 
155  if ( ( retval = PAPI_add_event( EventSet, PAPI_event[index] ) ) != PAPI_OK )
156  test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );
157 
158  if ( index == 0 ) {
159 /* if ((retval = PAPI_get_opt(PAPI_DATA_ADDRESS, option)) != PAPI_OK)
160  test_fail(__FILE__, __LINE__, "PAPI_get_opt(PAPI_DATA_ADDRESS)", retval);
161 */
162  printf
163  ( "Requested Start Address: %p; Start Offset: 0x%5x; Actual Start Address: %p\n",
164  option->addr.start, option->addr.start_off,
165  option->addr.start - option->addr.start_off );
166  printf
167  ( "Requested End Address: %p; End Offset: 0x%5x; Actual End Address: %p\n",
168  option->addr.end, option->addr.end_off,
169  option->addr.end + option->addr.end_off );
170  }
171 
172  PAPI_start( EventSet );
173  do_malloc_work( NUM );
174  do_static_work( NUM );
175  PAPI_stop( EventSet, &value );
176 
177  printf( "%s: %lld\n", event_name[index], value );
178 
179  if ( ( retval =
180  PAPI_remove_event( EventSet, PAPI_event[index] ) ) != PAPI_OK )
181  test_fail( __FILE__, __LINE__, "PAPI_remove_event", retval );
182 }
183 
184 static void
185 init_array( void )
186 {
187  parray1 = ( int * ) malloc( NUM * sizeof ( int ) );
188  if ( parray1 == NULL )
189  test_fail( __FILE__, __LINE__, "No memory available!\n", 0 );
190  memset( parray1, 0x0, NUM * sizeof ( int ) );
191 
192  parray2 = ( int * ) malloc( NUM * sizeof ( int ) );
193  if ( parray2 == NULL )
194  test_fail( __FILE__, __LINE__, "No memory available!\n", 0 );
195  memset( parray2, 0x0, NUM * sizeof ( int ) );
196 
197  parray3 = ( int * ) malloc( NUM * sizeof ( int ) );
198  if ( parray3 == NULL )
199  test_fail( __FILE__, __LINE__, "No memory available!\n", 0 );
200  memset( parray3, 0x0, NUM * sizeof ( int ) );
201 
202 }
203 
204 static int
206 {
207  int i;
208  int sum = 0;
209 
210  for ( i = 0; i < loop; i++ ) {
211  array1[i] = i;
212  sum += array1[i];
213  }
214 
215  for ( i = 0; i < loop; i++ ) {
216  array2[i] = i;
217  sum += array2[i];
218  }
219 
220  for ( i = 0; i < loop; i++ ) {
221  array3[i] = i;
222  sum += array3[i];
223  }
224 
225  return sum;
226 }
227 
228 static int
230 {
231  int i;
232  int sum = 0;
233 
234  for ( i = 0; i < loop; i++ ) {
235  parray1[i] = i;
236  sum += parray1[i];
237  }
238 
239  for ( i = 0; i < loop; i++ ) {
240  parray2[i] = i;
241  sum += parray2[i];
242  }
243 
244  for ( i = 0; i < loop; i++ ) {
245  parray3[i] = i;
246  sum += parray3[i];
247  }
248 
249  return sum;
250 }
char event_name[2][PAPI_MAX_STR_LEN]
Definition: data_range.c:23
sprintf(splash[splash_line++],"\tIozone: Performance Test of File I/O\n")
memset(eventId, 0, size)
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2225
int PAPI_event[2]
Definition: data_range.c:24
int * parray3
Definition: data_range.c:21
int PAPI_add_event(int EventSet, int EventCode)
Definition: papi.c:1597
Hardware info structure.
Definition: papi.h:775
#define PAPI_NULL
Definition: fpapi.h:13
static int do_malloc_work(long loop)
Definition: data_range.c:229
#define PAPI_MAX_STR_LEN
Definition: fpapi.h:43
start
Definition: iozone.c:22736
int PAPI_remove_event(int EventSet, int EventCode)
Definition: papi.c:1692
void test_skip(char *file, int line, char *call, int retval)
Definition: test_utils.c:614
#define PAPI_DATA_ADDRESS
Definition: papi.h:450
get the executable&#39;s info
Definition: papi.h:702
return PAPI_OK
Definition: linux-nvml.c:458
tests_quiet(argc, argv)
A pointer to the following is passed to PAPI_set/get_opt()
Definition: papi.h:843
#define printf
Definition: papi_test.h:125
double loop(long n)
Definition: kufrin.c:19
void double value
Definition: iozone.c:18781
test_pass(__FILE__, NULL, 0)
int PAPI_set_opt(int option, PAPI_option_t *ptr)
Definition: papi.c:3360
int int argc
Definition: iozone.c:1609
int * parray1
Definition: data_range.c:21
PAPI_addr_range_option_t addr
Definition: papi.h:860
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
#define PAPI_ENOSUPP
Definition: fpapi.h:123
const PAPI_exe_info_t * PAPI_get_executable_info(void)
Definition: papi.c:5975
free(dummyfile[xx])
#define NUM
Definition: data_range.c:13
#define PAPI_VER_CURRENT
Definition: fpapi.h:14
int PAPI_cleanup_eventset(int EventSet)
Definition: papi.c:2795
int PAPI_assign_eventset_component(int EventSet, int cidx)
Definition: papi.c:1460
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1399
int array3[NUM]
Definition: data_range.c:22
static void measure_load_store(caddr_t start, caddr_t end)
Definition: data_range.c:131
int PAPI_event_name_to_code(char *in, int *out)
Definition: papi.c:1003
int EventSet
int array2[NUM]
Definition: data_range.c:22
int PAPI_destroy_eventset(int *EventSet)
Definition: papi.c:1937
static void init_array(void)
Definition: data_range.c:185
int PAPI_start(int EventSet)
Definition: papi.c:2019
static void measure_event(int index, PAPI_option_t *option)
Definition: data_range.c:150
const PAPI_hw_info_t * PAPI_get_hardware_info(void)
Definition: papi.c:6046
ssize_t retval
Definition: libasync.c:338
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 * parray2
Definition: data_range.c:21
void exit()
static int do_static_work(long loop)
Definition: data_range.c:205
int array1[NUM]
Definition: data_range.c:22