PAPI  5.6.0.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

static intevents
 
static int numevents = 0
 
static int max_events =0
 

Function Documentation

double loop ( long  n)

Definition at line 26 of file kufrin.c.

27 {
28  long i;
29  double a = 0.0012;
30 
31  for ( i = 0; i < n; i++ ) {
32  a += 0.01;
33  }
34  return a;
35 }
int i
Definition: fileop.c:140
static double a[MATRIX_SIZE][MATRIX_SIZE]
Definition: libmsr_basic.c:38

Here is the caller graph for this function:

int main ( int  argc,
char **  argv 
)

Definition at line 105 of file kufrin.c.

106 {
107  int nthreads = 8, retval, i;
108  PAPI_event_info_t info;
109  pthread_t *threads;
110  int quiet;
111 
112  /* Set TESTS_QUIET variable */
113  quiet = tests_quiet( argc, argv );
114 
115  if ( !quiet ) {
116  if ( argc > 1 ) {
117  int tmp = atoi( argv[1] );
118  if ( tmp >= 1 )
119  nthreads = tmp;
120  }
121  }
122 
124  if ( retval != PAPI_VER_CURRENT ) {
125  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
126  }
127 
128  retval = PAPI_thread_init( ( unsigned long ( * )( void ) ) pthread_self );
129  if ( retval != PAPI_OK ) {
130  test_fail( __FILE__, __LINE__, "PAPI_thread_init", retval );
131  }
132 
134  if ( retval != PAPI_OK ) {
135  test_fail( __FILE__, __LINE__, "PAPI_multiplex_init", retval );
136  }
137 
138  if ((max_events = PAPI_get_cmp_opt(PAPI_MAX_MPX_CTRS,NULL,0)) <= 0) {
139  test_fail( __FILE__, __LINE__, "PAPI_get_cmp_opt", max_events );
140  }
141 
142  if ((events = calloc(max_events,sizeof(int))) == NULL) {
143  test_fail( __FILE__, __LINE__, "calloc", PAPI_ESYS );
144  }
145 
146  /* Fill up the event set with as many non-derived events as we can */
147 
148  i = PAPI_PRESET_MASK;
149  do {
150  if ( PAPI_get_event_info( i, &info ) == PAPI_OK ) {
151  if ( info.count == 1 ) {
152  events[numevents++] = ( int ) info.event_code;
153  if (!quiet) printf( "Added %s\n", info.symbol );
154  } else {
155  if (!quiet) printf( "Skipping derived event %s\n", info.symbol );
156  }
157  }
158  } while ( ( PAPI_enum_event( &i, PAPI_PRESET_ENUM_AVAIL ) == PAPI_OK )
159  && ( numevents < max_events ) );
160 
161  if (!quiet) printf( "Found %d events\n", numevents );
162 
163  if (numevents==0) {
164  test_skip(__FILE__,__LINE__,"No events found",0);
165  }
166 
167  do_stuff( );
168 
169  if (!quiet) printf( "Creating %d threads:\n", nthreads );
170 
171  threads =
172  ( pthread_t * ) malloc( ( size_t ) nthreads * sizeof ( pthread_t ) );
173  if ( threads == NULL ) {
174  test_fail( __FILE__, __LINE__, "malloc", PAPI_ENOMEM );
175  }
176 
177  /* Create the threads */
178  for ( i = 0; i < nthreads; i++ ) {
179  retval = pthread_create( &threads[i], NULL, thread, NULL );
180  if ( retval != 0 ) {
181  test_fail( __FILE__, __LINE__, "pthread_create", PAPI_ESYS );
182  }
183  }
184 
185  /* Wait for thread completion */
186  for ( i = 0; i < nthreads; i++ ) {
187  retval = pthread_join( threads[i], NULL );
188  if ( retval != 0 ) {
189  test_fail( __FILE__, __LINE__, "pthread_join", PAPI_ESYS );
190  }
191  }
192 
193  if (!quiet) printf( "Done." );
194 
195  test_pass( __FILE__ );
196 
197  pthread_exit( NULL );
198 
199  return 0;
200 }
int atoi()
unsigned int count
Definition: papi.h:987
void test_pass(const char *filename)
Definition: test_utils.c:432
static int numevents
Definition: kufrin.c:22
void do_stuff(void)
Definition: do_loops.c:256
int PAPI_enum_event(int *EventCode, int modifier)
Definition: papi.c:1152
char symbol[PAPI_HUGE_STR_LEN]
Definition: papi.h:966
return PAPI_OK
Definition: linux-nvml.c:497
#define PAPI_PRESET_MASK
int int argc
Definition: iozone.c:1609
int PAPI_get_event_info(int EventCode, PAPI_event_info_t *info)
Definition: papi.c:835
void test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:559
char events[MAX_EVENTS][BUFSIZ]
char ** argv
Definition: iozone.c:1610
int PAPI_thread_init(unsigned long int(*id_fn)(void))
Definition: papi.c:123
int PAPI_library_init(int version)
Definition: papi.c:500
int i
Definition: fileop.c:140
int quiet
Definition: rapl_overflow.c:18
int PAPI_get_cmp_opt(int option, PAPI_option_t *ptr, int cidx)
Definition: papi.c:4335
#define PAPI_ESYS
Definition: papi.h:255
void * thread(void *arg)
Definition: kufrin.c:38
#define PAPI_MAX_MPX_CTRS
Definition: papi.h:439
pthread_t
Definition: iozone.c:18557
#define PAPI_ENOMEM
Definition: papi.h:254
static int max_events
Definition: kufrin.c:23
int PAPI_multiplex_init(void)
Definition: papi.c:2982
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
Definition: iozone.c:18528
unsigned int event_code
Definition: papi.h:964
ssize_t retval
Definition: libasync.c:338
long long tmp
Definition: iozone.c:12031
#define PAPI_VER_CURRENT
Definition: papi.h:225
if(gettimeofday(&tp,(struct timezone *) NULL)==-1) perror("gettimeofday")

Here is the call graph for this function:

void* thread ( void arg)

Definition at line 38 of file kufrin.c.

39 {
40  ( void ) arg; /*unused */
41  int eventset = PAPI_NULL;
42  long long *values;
43 
44  int ret = PAPI_register_thread( );
45  if ( ret != PAPI_OK )
46  test_fail( __FILE__, __LINE__, "PAPI_register_thread", ret );
47  ret = PAPI_create_eventset( &eventset );
48  if ( ret != PAPI_OK )
49  test_fail( __FILE__, __LINE__, "PAPI_create_eventset", ret );
50 
51  values=calloc(max_events,sizeof(long long));
52 
53  if (!TESTS_QUIET) printf( "Event set %d created\n", eventset );
54 
55  /* In Component PAPI, EventSets must be assigned a component index
56  before you can fiddle with their internals.
57  0 is always the cpu component */
58  ret = PAPI_assign_eventset_component( eventset, 0 );
59  if ( ret != PAPI_OK ) {
60  test_fail( __FILE__, __LINE__, "PAPI_assign_eventset_component", ret );
61  }
62 
63  ret = PAPI_set_multiplex( eventset );
64  if ( ret == PAPI_ENOSUPP) {
65  test_skip( __FILE__, __LINE__, "Multiplexing not supported", 1 );
66  }
67  else if ( ret != PAPI_OK ) {
68  test_fail( __FILE__, __LINE__, "PAPI_set_multiplex", ret );
69  }
70 
71  ret = PAPI_add_events( eventset, events, numevents );
72  if ( ret < PAPI_OK ) {
73  test_fail( __FILE__, __LINE__, "PAPI_add_events", ret );
74  }
75 
76  ret = PAPI_start( eventset );
77  if ( ret != PAPI_OK ) {
78  test_fail( __FILE__, __LINE__, "PAPI_start", ret );
79  }
80 
81  do_stuff( );
82 
83  ret = PAPI_stop( eventset, values );
84  if ( ret != PAPI_OK ) {
85  test_fail( __FILE__, __LINE__, "PAPI_stop", ret );
86  }
87 
88  ret = PAPI_cleanup_eventset( eventset );
89  if ( ret != PAPI_OK ) {
90  test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset", ret );
91  }
92 
93  ret = PAPI_destroy_eventset( &eventset );
94  if ( ret != PAPI_OK ) {
95  test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset", ret );
96  }
97 
98  ret = PAPI_unregister_thread( );
99  if ( ret != PAPI_OK )
100  test_fail( __FILE__, __LINE__, "PAPI_unregister_thread", ret );
101  return ( NULL );
102 }
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2314
static int numevents
Definition: kufrin.c:22
#define PAPI_ENOSUPP
Definition: papi.h:271
#define PAPI_NULL
Definition: papi.h:292
void do_stuff(void)
Definition: do_loops.c:256
int PAPI_register_thread(void)
Definition: papi.c:208
return PAPI_OK
Definition: linux-nvml.c:497
void
Definition: iozone.c:18627
int PAPI_add_events(int EventSet, int *Events, int number)
Definition: papi.c:5843
void test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:559
char events[MAX_EVENTS][BUFSIZ]
long long ret
Definition: iozone.c:1346
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
static int max_events
Definition: kufrin.c:23
printf("\tTry: -i 0 -i 1 \n\n")
int PAPI_unregister_thread(void)
Definition: papi.c:244
int TESTS_QUIET
Definition: test_utils.c:18
void test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:468
int PAPI_set_multiplex(int EventSet)
Definition: papi.c:3333
int PAPI_destroy_eventset(int *EventSet)
Definition: papi.c:2014
int PAPI_start(int EventSet)
Definition: papi.c:2096
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
static

Definition at line 21 of file kufrin.c.

int max_events =0
static

Definition at line 23 of file kufrin.c.

int numevents = 0
static

Definition at line 22 of file kufrin.c.