PAPI  5.6.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
zero_smp.c
Go to the documentation of this file.
1 /* This file performs the following test: start, stop and timer
2 functionality for 2 slave native SMP threads
3 
4  - It attempts to use the following two counters. It may use less
5 depending on hardware counter resource limitations. These are counted
6 in the default counting domain and default granularity, depending on
7 the platform. Usually this is the user domain (PAPI_DOM_USER) and
8 thread context (PAPI_GRN_THR).
9 
10  + PAPI_FP_INS
11  + PAPI_TOT_CYC
12 
13 Each of 2 slave pthreads:
14  - Get cyc.
15  - Get us.
16  - Start counters
17  - Do flops
18  - Stop and read counters
19  - Get us.
20  - Get cyc.
21 
22 Master pthread:
23  - Get us.
24  - Get cyc.
25  - Fork threads
26  - Wait for threads to exit
27  - Get us.
28  - Get cyc.
29 */
30 
31 
32 #include <stdio.h>
33 #include <stdlib.h>
34 
35 #include "papi.h"
36 #include "papi_test.h"
37 
38 #include "do_loops.h"
39 
40 #if defined(sun) && defined(sparc)
41 #include <thread.h>
42 #elif defined(mips) && defined(sgi) && defined(unix)
43 #include <mpc.h>
44 #elif defined(_AIX) || defined(__linux__)
45 #include <pthread.h>
46 #endif
47 
48 
49 void
50 Thread( int t, int n )
51 {
52  int retval, num_tests = 1;
53  int EventSet1 = PAPI_NULL;
54  int PAPI_event, mask1;
55  int num_events1;
56  long long **values;
57  long long elapsed_us, elapsed_cyc;
59 
60  /* add PAPI_TOT_CYC and one of the events in PAPI_FP_INS, PAPI_FP_OPS or
61  PAPI_TOT_INS, depending on the availability of the event on the
62  platform */
63  EventSet1 = add_two_events( &num_events1, &PAPI_event, &mask1 );
64 
65  retval = PAPI_event_code_to_name( PAPI_event, event_name );
66  if ( retval != PAPI_OK )
67  test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );
68 
69  values = allocate_test_space( num_tests, num_events1 );
70 
71  retval = PAPI_start( EventSet1 );
72  if ( retval != PAPI_OK )
73  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
74 
75  elapsed_us = PAPI_get_real_usec( );
76 
77  elapsed_cyc = PAPI_get_real_cyc( );
78 
79  do_flops( n );
80 
81  elapsed_us = PAPI_get_real_usec( ) - elapsed_us;
82 
83  elapsed_cyc = PAPI_get_real_cyc( ) - elapsed_cyc;
84 
85  retval = PAPI_stop( EventSet1, values[0] );
86  if ( retval != PAPI_OK )
87  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
88 
89  remove_test_events( &EventSet1, mask1 );
90 
91  if ( !TESTS_QUIET ) {
92  printf( "Thread %#x %-12s : \t%lld\n", t, event_name,
93  values[0][1] );
94  printf( "Thread %#x PAPI_TOT_CYC : \t%lld\n", t,
95  values[0][0] );
96  }
97 
98  free_test_space( values, num_tests );
99  if ( !TESTS_QUIET ) {
100  printf( "Thread %#x Real usec : \t%lld\n", t, elapsed_us );
101  printf( "Thread %#x Real cycles : \t%lld\n", t, elapsed_cyc );
102  }
104 }
105 
106 int
107 main( int argc, char **argv )
108 {
109  int i, retval, quiet;
110  long long elapsed_us, elapsed_cyc;
111 
112  /* Set TESTS_QUIET variable */
113  quiet=tests_quiet( argc, argv );
114 
116  if ( retval != PAPI_VER_CURRENT ) {
117  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
118  }
119 
120  elapsed_us = PAPI_get_real_usec( );
121 
122  elapsed_cyc = PAPI_get_real_cyc( );
123 
124 #if defined(_AIX) || defined(__linux__)
125  retval =
126  PAPI_thread_init( ( unsigned long ( * )( void ) ) ( pthread_self ) );
127  if ( retval != PAPI_OK ) {
128  if ( retval == PAPI_ECMP )
129  test_skip( __FILE__, __LINE__, "PAPI_thread_init", retval );
130  else
131  test_fail( __FILE__, __LINE__, "PAPI_thread_init", retval );
132  }
133 #if defined(_AIX)
134 #pragma ibm parallel_loop
135 #endif
136 
137 #elif defined(sgi) && defined(mips)
138  retval =
139  PAPI_thread_init( ( unsigned long ( * )( void ) ) ( mp_my_threadnum ) );
140  if ( retval != PAPI_OK ) {
141  test_fail( __FILE__, __LINE__, "PAPI_thread_init", retval );
142  }
143 #pragma parallel
144 #pragma local(i)
145 #pragma pfor
146 #elif defined(sun) && defined(sparc)
147  retval = PAPI_thread_init( ( unsigned long ( * )( void ) ) ( thr_self ) );
148  if ( retval != PAPI_OK ) {
149  test_fail( __FILE__, __LINE__, "PAPI_thread_init", retval );
150  }
151 #pragma MP taskloop private(i)
152 #else
153  if (!quiet) {
154  printf("This test only runs on AIX/IRIX/SOLOARIS\n");
155  }
156  test_skip(__FILE__, __LINE__, "Architecture not included in this test file yet.", 0);
157 #endif
158  for ( i = 1; i < 3; i++ ) {
159  Thread( i, 10000000 * i );
160  }
161 
162  elapsed_cyc = PAPI_get_real_cyc( ) - elapsed_cyc;
163 
164  elapsed_us = PAPI_get_real_usec( ) - elapsed_us;
165 
166  if ( !quiet ) {
167  printf( "Master real usec : \t%lld\n", elapsed_us );
168  printf( "Master real cycles : \t%lld\n", elapsed_cyc );
169  }
170 
171  // FIXME: we don't really validate anything here
172 
173  test_pass( __FILE__ );
174 
175  return 0;
176 }
char event_name[2][PAPI_MAX_STR_LEN]
Definition: data_range.c:29
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2314
int mask1
Definition: zero_fork.c:48
int PAPI_event[2]
Definition: data_range.c:30
void test_pass(const char *filename)
Definition: test_utils.c:432
#define PAPI_NULL
Definition: papi.h:292
int num_events1
Definition: zero_fork.c:49
return PAPI_OK
Definition: linux-nvml.c:497
int int argc
Definition: iozone.c:1609
Return codes and api definitions.
void test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:559
char ** argv
Definition: iozone.c:1610
t
Definition: iozone.c:23562
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
long long elapsed_cyc
Definition: zero_fork.c:50
int add_two_events(int *num_events, int *papi_event, int *mask)
Definition: test_utils.c:615
void free_test_space(long long **values, int num_tests)
Definition: test_utils.c:70
#define PAPI_ECMP
Definition: papi.h:256
int PAPI_event_code_to_name(int EventCode, char *out)
Definition: papi.c:915
int num_tests
Definition: zero_fork.c:53
void do_flops(int n)
Definition: multiplex.c:23
long long PAPI_get_real_usec(void)
Definition: papi.c:6264
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
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
static void * Thread(void *arg)
#define PAPI_MAX_STR_LEN
Definition: papi.h:465
long long PAPI_get_real_cyc(void)
Definition: papi.c:6217
int PAPI_start(int EventSet)
Definition: papi.c:2096
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
ssize_t retval
Definition: libasync.c:338
long long elapsed_us
Definition: zero_fork.c:50
long long ** allocate_test_space(int num_tests, int num_events)
Definition: test_utils.c:46
#define PAPI_VER_CURRENT
Definition: papi.h:225
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:201
int EventSet1
Definition: zero_fork.c:47