PAPI  5.6.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ctests/locks_pthreads.c File Reference
Include dependency graph for ctests/locks_pthreads.c:

Go to the source code of this file.

Macros

#define MAX_THREADS   256
 
#define APPR_TOTAL_ITER   1000000
 

Functions

void lockloop (int iters, volatile long long *mycount)
 
voidSlave (void *arg)
 
int main (int argc, char **argv)
 

Variables

volatile long long count = 0
 
volatile long long tmpcount = 0
 
volatile long long thread_iter = 0
 
static int quiet =0
 

Macro Definition Documentation

#define APPR_TOTAL_ITER   1000000

Definition at line 7 of file ctests/locks_pthreads.c.

#define MAX_THREADS   256

Definition at line 6 of file ctests/locks_pthreads.c.

Function Documentation

void lockloop ( int  iters,
volatile long long mycount 
)

Definition at line 25 of file ctests/locks_pthreads.c.

26 {
27  int i;
28  for ( i = 0; i < iters; i++ ) {
30  *mycount = *mycount + 1;
32  }
33 }
int i
Definition: fileop.c:140
#define PAPI_USR1_LOCK
Definition: papi.h:333
int PAPI_unlock(int lck)
Definition: papi.c:6421
int PAPI_lock(int lck)
Definition: papi.c:6401

Here is the call graph for this function:

Here is the caller graph for this function:

int main ( int  argc,
char **  argv 
)

Definition at line 53 of file ctests/locks_pthreads.c.

54 {
55  pthread_t slaves[MAX_THREADS];
56  int rc, i, nthr;
57  int retval;
58  const PAPI_hw_info_t *hwinfo = NULL;
59 
60  /* Set TESTS_QUIET variable */
61  quiet = tests_quiet( argc, argv );
62 
64  if (retval != PAPI_VER_CURRENT ) {
65  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
66  }
67 
68  hwinfo = PAPI_get_hardware_info( );
69  if (hwinfo == NULL ) {
70  test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 );
71  }
72 
73  retval = PAPI_thread_init((unsigned long (*)(void)) ( pthread_self ) );
74  if ( retval != PAPI_OK ) {
75  if ( retval == PAPI_ECMP ) {
76  test_skip( __FILE__, __LINE__,
77  "PAPI_thread_init", retval );
78  }
79  else {
80  test_fail( __FILE__, __LINE__,
81  "PAPI_thread_init", retval );
82  }
83  }
84 
85  if ( hwinfo->ncpu > MAX_THREADS ) {
86  nthr = MAX_THREADS;
87  }
88  else {
89  nthr = hwinfo->ncpu;
90  }
91 
92  /* Scale the per thread work to keep the serial runtime about the same. */
93  thread_iter = APPR_TOTAL_ITER/sqrt(nthr);
94 
95  if (!quiet) {
96  printf( "Creating %d threads, %lld lock/unlock\n",
97  nthr , thread_iter);
98  }
99 
100  for ( i = 0; i < nthr; i++ ) {
101  rc = pthread_create( &slaves[i], NULL, Slave, NULL );
102  if ( rc ) {
103  retval = PAPI_ESYS;
104  test_fail( __FILE__, __LINE__,
105  "pthread_create", retval );
106  }
107  }
108 
109  for ( i = 0; i < nthr; i++ ) {
110  pthread_join( slaves[i], NULL );
111  }
112 
113  if (!quiet) {
114  printf( "Expected: %lld Received: %lld\n",
115  ( long long ) nthr * thread_iter,
116  count );
117  }
118 
119  if ( nthr * thread_iter != count ) {
120  test_fail( __FILE__, __LINE__, "Thread Locks", 1 );
121  }
122 
123  test_pass( __FILE__ );
124 
125  return 0;
126 
127 }
void test_pass(const char *filename)
Definition: test_utils.c:432
Hardware info structure.
Definition: papi.h:780
#define APPR_TOTAL_ITER
return PAPI_OK
Definition: linux-nvml.c:497
int count
Definition: iozone.c:22422
#define MAX_THREADS
int int argc
Definition: iozone.c:1609
int rc
Definition: iozone.c:20281
void test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:559
void * Slave(void *arg)
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
#define PAPI_ESYS
Definition: papi.h:255
#define PAPI_ECMP
Definition: papi.h:256
pthread_t
Definition: iozone.c:18557
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
volatile long long thread_iter
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
int ncpu
Definition: papi.h:781

Here is the call graph for this function:

void* Slave ( void arg)

Definition at line 36 of file ctests/locks_pthreads.c.

37 {
38  long long duration;
39 
40  duration = PAPI_get_real_usec( );
42  duration = PAPI_get_real_usec( ) - duration;
43 
44  if (!quiet) {
45  printf("%f lock/unlocks per us\n",
46  (float)thread_iter/(float)duration);
47  }
48  pthread_exit( arg );
49 }
void lockloop(int iters, volatile long long *mycount)
int count
Definition: iozone.c:22422
int quiet
Definition: rapl_overflow.c:18
long long PAPI_get_real_usec(void)
Definition: papi.c:6264
printf("\tTry: -i 0 -i 1 \n\n")
volatile long long thread_iter

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

volatile long long count = 0

Definition at line 18 of file ctests/locks_pthreads.c.

int quiet =0
static

Definition at line 22 of file ctests/locks_pthreads.c.

volatile long long thread_iter = 0

Definition at line 20 of file ctests/locks_pthreads.c.

volatile long long tmpcount = 0

Definition at line 19 of file ctests/locks_pthreads.c.