PAPI 7.1.0.0
Loading...
Searching...
No Matches
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

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"}
 

Macro Definition Documentation

◆ NUM_EVENTS

#define NUM_EVENTS   6

Definition at line 24 of file appio_test_pthreads.c.

◆ NUM_INFILES

#define NUM_INFILES   4

Definition at line 27 of file appio_test_pthreads.c.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 93 of file appio_test_pthreads.c.

93 {
94 pthread_t *callThd;
95 int i, numthrds;
96 int retval;
97 pthread_attr_t attr;
98
99 /* Set TESTS_QUIET variable */
100 tests_quiet( argc, argv );
101
103 if (version != PAPI_VER_CURRENT) {
104 fprintf(stderr, "PAPI_library_init version mismatch\n");
105 exit(1);
106 }
107
108
109 pthread_attr_init(&attr);
110 if (PAPI_thread_init(pthread_self) != PAPI_OK) {
111 fprintf(stderr, "PAPI_thread_init returned an error\n");
112 exit(1);
113 }
114#ifdef PTHREAD_CREATE_UNDETACHED
115 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_UNDETACHED);
116#endif
117#ifdef PTHREAD_SCOPE_SYSTEM
118 retval = pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);
119 if (retval != 0) {
120 fprintf(stderr,"This system does not support kernel scheduled pthreads.\n");
121 exit(1);
122 }
123#endif
124
125 numthrds = NUM_INFILES;
126 if (!TESTS_QUIET) printf("%d threads\n",numthrds);
127 callThd = (pthread_t *)malloc(numthrds*sizeof(pthread_t));
128
129 int rc ;
130 for (i=0;i<(numthrds-1);i++) {
131 rc = pthread_create(callThd+i, &attr, ThreadIO, (void *) files[i]);
132 if (rc != 0) perror("Error creating thread using pthread_create()");
133 }
134 ThreadIO((void *)files[numthrds-1]);
135 pthread_attr_destroy(&attr);
136
137 for (i=0;i<(numthrds-1);i++)
138 pthread_join(callThd[i], NULL);
139
140 test_pass( __FILE__ );
141 return 0;
142}
int i
static const char * files[NUM_INFILES]
void * ThreadIO(void *arg)
#define NUM_INFILES
initialize the PAPI library.
Initialize thread support in the PAPI library.
#define PAPI_VER_CURRENT
Definition: f90papi.h:54
#define PAPI_OK
Definition: f90papi.h:73
uint8_t version
int TESTS_QUIET
Definition: test_utils.c:18
unsigned long int pthread_t
FILE * stderr
int tests_quiet(int argc, char **argv)
Definition: test_utils.c:376
void PAPI_NORETURN test_pass(const char *filename)
Definition: test_utils.c:432
rc
Definition: pscanf.h:23
int retval
Definition: zero_fork.c:53
Here is the call graph for this function:

◆ ThreadIO()

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 EventSet = PAPI_NULL;
34 long long values[NUM_EVENTS];
35 int retval;
36 int e;
37 int event_code;
38
39 /* Create the Event Set */
41 fprintf(stderr, "Error creating event set\n");
42 exit(2);
43 }
44
45 for (e=0; e<NUM_EVENTS; e++) {
46 retval = PAPI_event_name_to_code((char*)names[e], &event_code);
47 if (retval != PAPI_OK) {
48 fprintf(stderr, "Error getting code for %s\n", names[e]);
49 exit(2);
50 }
51 retval = PAPI_add_event(EventSet, event_code);
52 if (retval != PAPI_OK) {
53 fprintf(stderr, "Error adding %s to event set\n", names[e]);
54 exit(2);
55 }
56 }
57
58 /* Start counting events */
59 if (PAPI_start(EventSet) != PAPI_OK) {
60 fprintf(stderr, "Error in PAPI_start\n");
61 exit(1);
62 }
63
64//if (PAPI_read_counters(EventSet, values) != PAPI_OK)
65// handle_error(1);
66//printf("After reading the counters: %lld\n",values[0]);
67
68 int fdin = open((const char*)arg, O_RDONLY);
69 if (fdin < 0) perror("Could not open file for reading: \n");
70
71 int bytes = 0;
72 char buf[1024];
73
74 int fdout = open("/dev/null", O_WRONLY);
75 if (fdout < 0) perror("Could not open /dev/null for writing: \n");
76 while ((bytes = read(fdin, buf, 1024)) > 0) {
77 write(fdout, buf, bytes);
78 }
79 close(fdout);
80
81 /* Stop counting events */
83 fprintf(stderr, "Error in PAPI_stop\n");
84 }
85
86 if (!TESTS_QUIET) {
87 for (e=0; e<NUM_EVENTS; e++)
88 printf("Thread %#lx: %s: %lld\n", tid, names[e], values[e]);
89 }
90 return(NULL);
91}
int open(const char *pathname, int flags, mode_t mode)
Definition: appio.c:188
int close(int fd)
Definition: appio.c:179
ssize_t write(int fd, const void *buf, size_t count)
Definition: appio.c:302
ssize_t read(int fd, void *buf, size_t count)
Definition: appio.c:229
const char * names[NUM_EVENTS]
#define NUM_EVENTS
add PAPI preset or native hardware event to an event set
Create a new empty PAPI EventSet.
Convert a name to a numeric hardware event code.
Start counting hardware events in an event set.
Stop counting hardware events in an event set.
volatile int buf[CACHE_FLUSH_BUFFER_SIZE_INTS]
Definition: do_loops.c:12
#define PAPI_NULL
Definition: f90papi.h:78
static int EventSet
Definition: init_fini.c:8
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
long long int long long
Definition: sde_internal.h:85
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ files

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.

◆ names

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.