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

Go to the source code of this file.

Macros

#define NUM_EVENTS   6
 
#define NUM_INFILES   4
 

Functions

voidThreadIO (void *arg)
 
int main (int argc, char **argv)
 

Variables

const char * names [NUM_EVENTS] = {"READ_CALLS", "READ_BYTES","READ_USEC","WRITE_CALLS","WRITE_BYTES","WRITE_USEC"}
 
static const char * files [NUM_INFILES] = {"/etc/passwd", "/etc/group", "/etc/protocols", "/etc/nsswitch.conf"}
 

Macro Definition Documentation

#define NUM_EVENTS   6

Definition at line 24 of file appio_test_pthreads.c.

#define NUM_INFILES   4

Definition at line 27 of file appio_test_pthreads.c.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 80 of file appio_test_pthreads.c.

80  {
81  pthread_t *callThd;
82  int i, numthrds;
83  int retval;
84  pthread_attr_t attr;
85 
86  /* Set TESTS_QUIET variable */
87  tests_quiet( argc, argv );
88 
90  if (version != PAPI_VER_CURRENT) {
91  fprintf(stderr, "PAPI_library_init version mismatch\n");
92  exit(1);
93  }
94 
95 
96  pthread_attr_init(&attr);
97  if (PAPI_thread_init(pthread_self) != PAPI_OK) {
98  fprintf(stderr, "PAPI_thread_init returned an error\n");
99  exit(1);
100  }
101 #ifdef PTHREAD_CREATE_UNDETACHED
102  pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_UNDETACHED);
103 #endif
104 #ifdef PTHREAD_SCOPE_SYSTEM
105  retval = pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);
106  if (retval != 0) {
107  fprintf(stderr,"This system does not support kernel scheduled pthreads.\n");
108  exit(1);
109  }
110 #endif
111 
112  numthrds = NUM_INFILES;
113  if (!TESTS_QUIET) printf("%d threads\n",numthrds);
114  callThd = (pthread_t *)malloc(numthrds*sizeof(pthread_t));
115 
116  int rc ;
117  for (i=0;i<(numthrds-1);i++) {
118  rc = pthread_create(callThd+i, &attr, ThreadIO, (void *) files[i]);
119  if (rc != 0) perror("Error creating thread using pthread_create()");
120  }
121  ThreadIO((void *)files[numthrds-1]);
122  pthread_attr_destroy(&attr);
123 
124  for (i=0;i<(numthrds-1);i++)
125  pthread_join(callThd[i], NULL);
126 
127  test_pass( __FILE__, NULL, 0 );
128  return 0;
129 }
return PAPI_OK
Definition: linux-nvml.c:458
tests_quiet(argc, argv)
#define printf
Definition: papi_test.h:125
test_pass(__FILE__, NULL, 0)
int int argc
Definition: iozone.c:1609
int TESTS_QUIET
Definition: test_utils.c:11
char ** argv
Definition: iozone.c:1610
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
#define NUM_INFILES
#define PAPI_VER_CURRENT
Definition: fpapi.h:14
void * ThreadIO(void *arg)
pthread_t
Definition: iozone.c:18557
char version[]
Definition: fileop.c:134
int rc
Definition: iozone.c:20281
ssize_t retval
Definition: libasync.c:338
void exit()
static const char * files[NUM_INFILES]
pthread_attr_t attr
Definition: iozone.c:18466

Here is the call graph for this function:

void* ThreadIO ( void arg)

Definition at line 30 of file appio_test_pthreads.c.

30  {
31  unsigned long tid = (unsigned long)pthread_self();
32  if (!TESTS_QUIET) printf("\nThread %#lx: will read %s and write it to /dev/null\n", tid,(const char*) arg);
33  int Events[NUM_EVENTS];
34  long long values[NUM_EVENTS];
35  int retval;
36  int e;
37  for (e=0; e<NUM_EVENTS; e++) {
38  retval = PAPI_event_name_to_code((char*)names[e], &Events[e]);
39  if (retval != PAPI_OK) {
40  fprintf(stderr, "Error getting code for %s\n", names[e]);
41  exit(2);
42  }
43  }
44 
45  /* Start counting events */
46  if (PAPI_start_counters(Events, NUM_EVENTS) != PAPI_OK) {
47  fprintf(stderr, "Error in PAPI_start_counters\n");
48  exit(1);
49  }
50 
51 //if (PAPI_read_counters(values, NUM_EVENTS) != PAPI_OK)
52 // handle_error(1);
53 //printf("After reading the counters: %lld\n",values[0]);
54 
55  int fdin = open((const char*)arg, O_RDONLY);
56  if (fdin < 0) perror("Could not open file for reading: \n");
57 
58  int bytes = 0;
59  char buf[1024];
60 
61  int fdout = open("/dev/null", O_WRONLY);
62  if (fdout < 0) perror("Could not open /dev/null for writing: \n");
63  while ((bytes = read(fdin, buf, 1024)) > 0) {
64  write(fdout, buf, bytes);
65  }
66  close(fdout);
67 
68  /* Stop counting events */
69  if (PAPI_stop_counters(values, NUM_EVENTS) != PAPI_OK) {
70  fprintf(stderr, "Error in PAPI_stop_counters\n");
71  }
72 
73  if (!TESTS_QUIET) {
74  for (e=0; e<NUM_EVENTS; e++)
75  printf("Thread %#lx: %s: %lld\n", tid, names[e], values[e]);
76  }
77  return(NULL);
78 }
ssize_t read(int fd, void *buf, size_t count)
Definition: appio.c:225
int close(int fd)
Definition: appio.c:175
static int Events[NUM_EVENTS]
Definition: init_fini.c:8
return PAPI_OK
Definition: linux-nvml.c:458
#define printf
Definition: papi_test.h:125
int TESTS_QUIET
Definition: test_utils.c:11
int open(const char *pathname, int flags, mode_t mode)
Definition: appio.c:184
char buf[200]
Definition: iozone.c:19609
ssize_t write(int fd, const void *buf, size_t count)
Definition: appio.c:298
int PAPI_stop_counters(long long *values, int array_len)
Definition: papi_hl.c:803
void *long long tid
Definition: iozone.c:18586
long long
Definition: iozone.c:19827
int PAPI_event_name_to_code(char *in, int *out)
Definition: papi.c:1008
#define NUM_EVENTS
int PAPI_start_counters(int *events, int array_len)
Definition: papi_hl.c:593
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
ssize_t retval
Definition: libasync.c:338
const char * names[NUM_EVENTS]
void exit()

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

const char* files[NUM_INFILES] = {"/etc/passwd", "/etc/group", "/etc/protocols", "/etc/nsswitch.conf"}
static

Definition at line 28 of file appio_test_pthreads.c.

const char* names[NUM_EVENTS] = {"READ_CALLS", "READ_BYTES","READ_USEC","WRITE_CALLS","WRITE_BYTES","WRITE_USEC"}

Definition at line 25 of file appio_test_pthreads.c.