You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by "maxikrie (via GitHub)" <gi...@apache.org> on 2023/01/21 20:00:44 UTC

[GitHub] [nuttx] maxikrie commented on issue #8207: usleep accuracy

maxikrie commented on issue #8207:
URL: https://github.com/apache/nuttx/issues/8207#issuecomment-1399322500

   This minimal example illustrates the problem:
   
   int main(int argc, FAR char *argv[])
   {
     printf("Hello, World!!\n");
   
     uint32_t N = 1000;
     uint32_t time[N];
     useconds_t sleep_time = 100;
   
     struct timespec t_start;
     clock_gettime(0, &t_start);
     for(int i=0; i < N; i++)
     {
   	  struct timespec t1;
   	  clock_gettime(0, &t1);
   	  usleep(sleep_time);
   	  struct timespec t2;
   	  clock_gettime(0, &t2);
   	  struct timespec dt;
   	  clock_timespec_subtract(&t2, &t1, &dt);
   	  time[i] = dt.tv_nsec/1000;
     }
     struct timespec t_end;
     clock_gettime(0, &t_end);
   
     struct timespec dt;
     clock_timespec_subtract(&t_end, &t_start, &dt);
     printf("Average sleep time: %ld (%ld)\n",  dt.tv_nsec/1000/N, sleep_time);
   
     for(int i=0; i < N; i++)
     {
   	  printf("Iteration %d: sleep time %ld (%ld)\n", i, time[i], sleep_time);
     }
     return 0;
   }
   
   On the stm32f4discovery:usbnsh (with CONFIG_SCHED_TICKLESS=y and CONFIG_USEC_PER_TICK=1) I am getting 124 us sleep instead of 100 us, which I find uprising.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org