My main aim was to insert 1ms delay in xeon phi coprocessor but I was getting ~9ms difference in my results. So, I tried experimenting with xeon host machine and phi coprocessor to find the timer resolution. I executed the following code:
#include <stdio.h>
#include <time.h>
#include <sys/time.h>
int main()
{
struct timespec tim, tim2;
tim.tv_sec = 0;
tim.tv_nsec = 100000;
struct timeval tv;
double temp_2=0;
int i =0;
for ( i=0;i<1000;i++)
{
gettimeofday(&tv, NULL);
double t1=tv.tv_sec+(tv.tv_usec/1000000.0);
nanosleep(&tim , NULL);
gettimeofday(&tv, NULL);
double t2=tv.tv_sec+(tv.tv_usec/1000000.0);
temp_2+=(t2-t1);
}
printf("Nano sleep successfull %lf\n",temp_2/1000);
return 0;
}
Running the following program in host:
./a.out Nano sleep successfull 0.000155
Running in xeon phi coprocessor:
./nsleep_mic Nano sleep successfull 0.009998
soo I get almost 90% errored wait in xeon phi.
- why does such erroneous wait happens?
- How to solve it if I want a sleep time of 1ms?