appio_test_pthreads.c File Reference

Include dependency graph for appio_test_pthreads.c:

Go to the source code of this file.

Defines

#define NUM_EVENTS   6
#define NUM_INFILES   4

Functions

void * ThreadIO (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"}

Define 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.

00080                                 {
00081   pthread_t *callThd;
00082   int i, numthrds;
00083   int retval;
00084   pthread_attr_t attr;
00085 
00086   /* Set TESTS_QUIET variable */
00087   tests_quiet( argc, argv );
00088 
00089   int version = PAPI_library_init (PAPI_VER_CURRENT);
00090   if (version != PAPI_VER_CURRENT) {
00091     fprintf(stderr, "PAPI_library_init version mismatch\n");
00092     exit(1);
00093   }
00094 
00095 
00096   pthread_attr_init(&attr);
00097   if (PAPI_thread_init(pthread_self) != PAPI_OK) {
00098     fprintf(stderr, "PAPI_thread_init returned an error\n");
00099     exit(1);
00100   }
00101 #ifdef PTHREAD_CREATE_UNDETACHED
00102   pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_UNDETACHED);
00103 #endif
00104 #ifdef PTHREAD_SCOPE_SYSTEM
00105   retval = pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);
00106   if (retval != 0) {
00107     fprintf(stderr,"This system does not support kernel scheduled pthreads.\n");
00108     exit(1);
00109   }
00110 #endif
00111 
00112   numthrds = NUM_INFILES;
00113   if (!TESTS_QUIET) printf("%d threads\n",numthrds);
00114   callThd = (pthread_t *)malloc(numthrds*sizeof(pthread_t));
00115 
00116   int rc ;
00117   for (i=0;i<(numthrds-1);i++) {
00118     rc = pthread_create(callThd+i, &attr, ThreadIO, (void *) files[i]);
00119     if (rc != 0) perror("Error creating thread using pthread_create()");
00120   }
00121   ThreadIO((void *)files[numthrds-1]);
00122   pthread_attr_destroy(&attr);
00123 
00124   for (i=0;i<(numthrds-1);i++)
00125     pthread_join(callThd[i], NULL);
00126 
00127   test_pass( __FILE__, NULL, 0 );
00128   return 0;
00129 }

Here is the call graph for this function:

void* ThreadIO ( void *  arg  ) 

Definition at line 30 of file appio_test_pthreads.c.

00030                           {
00031   unsigned long tid = (unsigned long)pthread_self();
00032   if (!TESTS_QUIET) printf("\nThread %#lx: will read %s and write it to /dev/null\n", tid,(const char*) arg);
00033   int Events[NUM_EVENTS]; 
00034   long long values[NUM_EVENTS];
00035   int retval;
00036   int e;
00037   for (e=0; e<NUM_EVENTS; e++) {
00038     retval = PAPI_event_name_to_code((char*)names[e], &Events[e]);
00039     if (retval != PAPI_OK) {
00040       fprintf(stderr, "Error getting code for %s\n", names[e]);
00041       exit(2);
00042     } 
00043   }
00044 
00045   /* Start counting events */
00046   if (PAPI_start_counters(Events, NUM_EVENTS) != PAPI_OK) {
00047     fprintf(stderr, "Error in PAPI_start_counters\n");
00048     exit(1);
00049   }
00050  
00051 //if (PAPI_read_counters(values, NUM_EVENTS) != PAPI_OK)
00052 //   handle_error(1);
00053 //printf("After reading the counters: %lld\n",values[0]);
00054 
00055   int fdin = open((const char*)arg, O_RDONLY);
00056   if (fdin < 0) perror("Could not open file for reading: \n");
00057 
00058   int bytes = 0;
00059   char buf[1024];
00060 
00061   int fdout = open("/dev/null", O_WRONLY);
00062   if (fdout < 0) perror("Could not open /dev/null for writing: \n");
00063   while ((bytes = read(fdin, buf, 1024)) > 0) {
00064     write(fdout, buf, bytes);
00065   }
00066   close(fdout);
00067 
00068   /* Stop counting events */
00069   if (PAPI_stop_counters(values, NUM_EVENTS) != PAPI_OK) {
00070     fprintf(stderr, "Error in PAPI_stop_counters\n");
00071   }
00072 
00073   if (!TESTS_QUIET) {
00074     for (e=0; e<NUM_EVENTS; e++)  
00075       printf("Thread %#lx: %s: %lld\n", tid, names[e], values[e]);
00076   }
00077   return(NULL);
00078 }

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.


Generated on 26 Jan 2016 for PAPI by  doxygen 1.6.1