Question

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.

  1. why does such erroneous wait happens?
  2. How to solve it if I want a sleep time of 1ms?
Was it helpful?

Solution

There is not enough information here to completely answer your question - please add the version of MPSS and the current clocksource settings; however,...

Please have a look at dmesg and the current clocksource to make sure you're using TSC and not experiencing some problem. Also, read this excellent article from Ravi Murty to help you understand some of the problems that you might be experiencing with the Xeon Phi clocksource:

http://software.intel.com/en-us/blogs/2013/06/20/eliminate-the-dreaded-clocksource-is-unstable-message-switch-to-tsc-for-a-stable

I'd propose that your current clocksource is set to micetc, which is incurring additional overhead from reading out of the mmio space of the device everytime your code (or the kernel on your behalf) wants to read the time. Switch to TSC to avoid that. Newer versions of MPSS should be setup with TSC as the default clocksource, but please read the article from Ravi and make sure your device is setup properly.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top