PAPI  5.3.2.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
kufrin.c File Reference
Include dependency graph for kufrin.c:

Go to the source code of this file.

Functions

double loop (long n)
 
voidthread (void *arg)
 
int main (int argc, char **argv)
 

Variables

intevents
 
int numevents = 0
 
int max_events =0
 

Function Documentation

double loop ( long  n)

Definition at line 19 of file kufrin.c.

20 {
21  long i;
22  double a = 0.0012;
23 
24  for ( i = 0; i < n; i++ ) {
25  a += 0.01;
26  }
27  return a;
28 }
static double a[MATRIX_SIZE][MATRIX_SIZE]
Definition: rapl_basic.c:37
int i
Definition: fileop.c:140
int n
Definition: mendes-alt.c:164

Here is the caller graph for this function:

int main ( int  argc,
char **  argv 
)

Definition at line 98 of file kufrin.c.

99 {
100  int nthreads = 8, ret, i;
101  PAPI_event_info_t info;
102  pthread_t *threads;
103  const PAPI_hw_info_t *hw_info;
104 
105  tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */
106 
107  if ( !TESTS_QUIET ) {
108  if ( argc > 1 ) {
109  int tmp = atoi( argv[1] );
110  if ( tmp >= 1 )
111  nthreads = tmp;
112  }
113  }
114 
116  if ( ret != PAPI_VER_CURRENT ) {
117  test_fail( __FILE__, __LINE__, "PAPI_library_init", ret );
118  }
119 
120  hw_info = PAPI_get_hardware_info( );
121  if ( hw_info == NULL )
122  test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 );
123 
124  if ( strcmp( hw_info->model_string, "POWER6" ) == 0 ) {
126  if ( ret != PAPI_OK ) {
127  test_fail( __FILE__, __LINE__, "PAPI_set_domain", ret );
128  }
129  }
130 
131  ret = PAPI_thread_init( ( unsigned long ( * )( void ) ) pthread_self );
132  if ( ret != PAPI_OK ) {
133  test_fail( __FILE__, __LINE__, "PAPI_thread_init", ret );
134  }
135 
137  if ( ret != PAPI_OK ) {
138  test_fail( __FILE__, __LINE__, "PAPI_multiplex_init", ret );
139  }
140 
141  if ((max_events = PAPI_get_cmp_opt(PAPI_MAX_MPX_CTRS,NULL,0)) <= 0) {
142  test_fail( __FILE__, __LINE__, "PAPI_get_cmp_opt", max_events );
143  }
144 
145  if ((events = calloc(max_events,sizeof(int))) == NULL) {
146  test_fail( __FILE__, __LINE__, "calloc", PAPI_ESYS );
147  }
148 
149  /* Fill up the event set with as many non-derived events as we can */
150 
151  i = PAPI_PRESET_MASK;
152  do {
153  if ( PAPI_get_event_info( i, &info ) == PAPI_OK ) {
154  if ( info.count == 1 ) {
155  events[numevents++] = ( int ) info.event_code;
156  printf( "Added %s\n", info.symbol );
157  } else {
158  printf( "Skipping derived event %s\n", info.symbol );
159  }
160  }
161  } while ( ( PAPI_enum_event( &i, PAPI_PRESET_ENUM_AVAIL ) == PAPI_OK )
162  && ( numevents < max_events ) );
163 
164  printf( "Found %d events\n", numevents );
165 
166  do_stuff( );
167 
168  printf( "Creating %d threads:\n", nthreads );
169 
170  threads =
171  ( pthread_t * ) malloc( ( size_t ) nthreads * sizeof ( pthread_t ) );
172  if ( threads == NULL ) {
173  test_fail( __FILE__, __LINE__, "malloc", PAPI_ENOMEM );
174  }
175 
176  /* Create the threads */
177  for ( i = 0; i < nthreads; i++ ) {
178  ret = pthread_create( &threads[i], NULL, thread, NULL );
179  if ( ret != 0 ) {
180  test_fail( __FILE__, __LINE__, "pthread_create", PAPI_ESYS );
181  }
182  }
183 
184  /* Wait for thread completion */
185  for ( i = 0; i < nthreads; i++ ) {
186  ret = pthread_join( threads[i], NULL );
187  if ( ret != 0 ) {
188  test_fail( __FILE__, __LINE__, "pthread_join", PAPI_ESYS );
189  }
190  }
191 
192  printf( "Done." );
193  test_pass( __FILE__, NULL, 0 );
194  pthread_exit( NULL );
195  exit( 0 );
196 }
int atoi()
unsigned int count
Definition: papi.h:982
#define PAPI_ENOMEM
Definition: fpapi.h:107
Hardware info structure.
Definition: papi.h:775
int numevents
Definition: kufrin.c:15
#define PAPI_DOM_ALL
Definition: fpapi.h:25
void do_stuff(void)
Definition: do_loops.c:249
int PAPI_enum_event(int *EventCode, int modifier)
Definition: papi.c:1148
char symbol[PAPI_HUGE_STR_LEN]
Definition: papi.h:961
return PAPI_OK
Definition: linux-nvml.c:458
tests_quiet(argc, argv)
#define PAPI_PRESET_MASK
#define printf
Definition: papi_test.h:125
test_pass(__FILE__, NULL, 0)
int int argc
Definition: iozone.c:1609
int PAPI_get_event_info(int EventCode, PAPI_event_info_t *info)
Definition: papi.c:844
long long ret
Definition: iozone.c:1346
int TESTS_QUIET
Definition: test_utils.c:11
char ** argv
Definition: iozone.c:1610
test_fail(__FILE__, __LINE__,"PAPI_library_init", retval)
int PAPI_thread_init(unsigned long int(*id_fn)(void))
Definition: papi.c:118
int PAPI_library_init(int version)
Definition: papi.c:495
int i
Definition: fileop.c:140
int PAPI_get_cmp_opt(int option, PAPI_option_t *ptr, int cidx)
Definition: papi.c:4233
#define PAPI_MAX_MPX_CTRS
Definition: fpapi.h:54
void * thread(void *arg)
Definition: kufrin.c:31
#define PAPI_VER_CURRENT
Definition: fpapi.h:14
char events[MAX_EVENTS][BUFSIZ]
pthread_t
Definition: iozone.c:18557
#define PAPI_ESYS
Definition: fpapi.h:108
int max_events
Definition: kufrin.c:16
int PAPI_multiplex_init(void)
Definition: papi.c:2897
int
Definition: iozone.c:18528
int PAPI_set_domain(int domain)
Definition: papi.c:5565
char model_string[PAPI_MAX_STR_LEN]
Definition: papi.h:785
unsigned int event_code
Definition: papi.h:959
const PAPI_hw_info_t * PAPI_get_hardware_info(void)
Definition: papi.c:6059
long long tmp
Definition: iozone.c:12031
static const PAPI_hw_info_t * hw_info
Definition: byte_profile.c:23
void exit()

Here is the call graph for this function:

void* thread ( void arg)

Definition at line 31 of file kufrin.c.

32 {
33  ( void ) arg; /*unused */
34  int eventset = PAPI_NULL;
35  long long *values;
36 
37  int ret = PAPI_register_thread( );
38  if ( ret != PAPI_OK )
39  test_fail( __FILE__, __LINE__, "PAPI_register_thread", ret );
40  ret = PAPI_create_eventset( &eventset );
41  if ( ret != PAPI_OK )
42  test_fail( __FILE__, __LINE__, "PAPI_create_eventset", ret );
43 
44  values=calloc(max_events,sizeof(long long));
45 
46  printf( "Event set %d created\n", eventset );
47 
48  /* In Component PAPI, EventSets must be assigned a component index
49  before you can fiddle with their internals.
50  0 is always the cpu component */
51  ret = PAPI_assign_eventset_component( eventset, 0 );
52  if ( ret != PAPI_OK ) {
53  test_fail( __FILE__, __LINE__, "PAPI_assign_eventset_component", ret );
54  }
55 
56  ret = PAPI_set_multiplex( eventset );
57  if ( ret == PAPI_ENOSUPP) {
58  test_skip( __FILE__, __LINE__, "Multiplexing not supported", 1 );
59  }
60  else if ( ret != PAPI_OK ) {
61  test_fail( __FILE__, __LINE__, "PAPI_set_multiplex", ret );
62  }
63 
64  ret = PAPI_add_events( eventset, events, numevents );
65  if ( ret < PAPI_OK ) {
66  test_fail( __FILE__, __LINE__, "PAPI_add_events", ret );
67  }
68 
69  ret = PAPI_start( eventset );
70  if ( ret != PAPI_OK ) {
71  test_fail( __FILE__, __LINE__, "PAPI_start", ret );
72  }
73 
74  do_stuff( );
75 
76  ret = PAPI_stop( eventset, values );
77  if ( ret != PAPI_OK ) {
78  test_fail( __FILE__, __LINE__, "PAPI_stop", ret );
79  }
80 
81  ret = PAPI_cleanup_eventset( eventset );
82  if ( ret != PAPI_OK ) {
83  test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset", ret );
84  }
85 
86  ret = PAPI_destroy_eventset( &eventset );
87  if ( ret != PAPI_OK ) {
88  test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset", ret );
89  }
90 
91  ret = PAPI_unregister_thread( );
92  if ( ret != PAPI_OK )
93  test_fail( __FILE__, __LINE__, "PAPI_unregister_thread", ret );
94  return ( NULL );
95 }
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2232
int numevents
Definition: kufrin.c:15
#define PAPI_NULL
Definition: fpapi.h:13
void test_skip(char *file, int line, char *call, int retval)
Definition: test_utils.c:614
void do_stuff(void)
Definition: do_loops.c:249
int PAPI_register_thread(void)
Definition: papi.c:203
return PAPI_OK
Definition: linux-nvml.c:458
void
Definition: iozone.c:18627
#define printf
Definition: papi_test.h:125
int PAPI_add_events(int EventSet, int *Events, int number)
Definition: papi.c:5720
long long ret
Definition: iozone.c:1346
test_fail(__FILE__, __LINE__,"PAPI_library_init", retval)
#define PAPI_ENOSUPP
Definition: fpapi.h:123
char events[MAX_EVENTS][BUFSIZ]
int PAPI_cleanup_eventset(int EventSet)
Definition: papi.c:2805
int PAPI_assign_eventset_component(int EventSet, int cidx)
Definition: papi.c:1467
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1406
int max_events
Definition: kufrin.c:16
int PAPI_unregister_thread(void)
Definition: papi.c:239
int PAPI_set_multiplex(int EventSet)
Definition: papi.c:3241
int PAPI_destroy_eventset(int *EventSet)
Definition: papi.c:1944
int PAPI_start(int EventSet)
Definition: papi.c:2026
static long long values[NUM_EVENTS]
Definition: init_fini.c:10

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

int* events

Definition at line 14 of file kufrin.c.

int max_events =0

Definition at line 16 of file kufrin.c.

int numevents = 0

Definition at line 15 of file kufrin.c.