osproject_threadpipe.c 1.21 KB
#include<stdio.h>
#include<string.h>
#include<pthread.h>
#include<stdlib.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/time.h>
int fd[2];
int n = 0;
long now = 0;
unsigned int time1, time2, time3;
unsigned int avg = 0;
void * writeThread()
{
// for(n=1000;n>0;n--)
// {
asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (time1));
write(fd[1],(void*)&time1,sizeof(time1));
usleep(1000);
// }
return 0;
}
void * readThread()
{
unsigned int switchTime;
// for(n=1000;n>0;n--)
// {
read(fd[0],(void*)&time3,sizeof(time3));
asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (time2));
switchTime = time2 - time3;
avg = avg + switchTime;
// }
avg = avg/1000;
return 0;
}
int main(int argc, char ** argv) {
pthread_t tid1,tid2;
int i = 0;
unsigned int regr;
/* Create the pipe. */
if (pipe (fd)) {
printf ("Pipe failed.\n");
return EXIT_FAILURE;
}
asm volatile("mrc p15, 0, %0, c9, c14, 0" : "=r" (regr));
printf("regr: %x\n", regr);
if (regr == 0)
exit(1);
printf("here\n");
pthread_create(&tid1,NULL,writeThread,NULL);
pthread_create(&tid2,NULL,readThread,NULL);
/*pthread_join(tid1,NULL);
* pthread_join(tid2,NULL);
* */
printf("%u",avg);
return 0;
}