pthread_cond_timedwait() : time internal resolution issue.

Thomas Kim thomas73.kim at gmail.com
Tue Aug 15 09:39:10 UTC 2017


Dear Joel,

I forgot this basic configuration.

Thank you very much.

Best Regards,
Thomas Kim

2017. 8. 14. 21:11에 "Joel Sherrill" <joel at rtems.org>님이 작성:

> You have to configure the clock tick length. By default it is 10
> milliseconds if I remember correctly. All timeouts are done in the clock
> tick.
>
> By using main() as the entry point and not specifying any configuration
> info you are getting the entire default settings.
>
> On Aug 14, 2017 12:19 AM, "Thomas Kim" <thomas73.kim at gmail.com> wrote:
>
>> Dear Sir,
>>
>> I am testing pthread_cond_timedwait() on realview-pbx-a9 using QEMU.
>>
>> My testing code is below;
>>
>> #include <pthread.h>
>> #include <time.h>
>> static void thread_sleep(struct timespec *ti)
>> {
>>     pthread_mutex_t mtx;
>>     pthread_cond_t cnd;
>>     pthread_mutex_init(&mtx, 0);
>>     pthread_cond_init(&cnd, 0);
>>     pthread_mutex_lock(&mtx);
>>     pthread_cond_timedwait(&cnd, &mtx, ti);
>>     pthread_mutex_unlock(&mtx);
>>     pthread_cond_destroy(&cnd);
>>     pthread_mutex_destroy(&mtx);
>> }
>> void own_msleep(unsigned long msecs)
>> {
>>     struct timeval tv;
>>     gettimeofday(&tv, 0);
>>     struct timespec ti;
>>     ti.tv_nsec = (tv.tv_usec + (msecs % 1000) * 1000) * 1000;
>>     ti.tv_sec = tv.tv_sec + (msecs / 1000) + (ti.tv_nsec / 1000000000);
>>     ti.tv_nsec %= 1000000000;
>>     thread_sleep(&ti);
>> }
>> #define TEST_1 0
>> #define TEST_2 0
>> #define TEST_3 0
>> #define TEST_4 1
>> int main(int argc, char *argv[])
>> {
>>  int count = 0;
>>
>>  while (1)
>>  {
>> #if TEST_1 // Normal operation. total time for count 100 = almost 1
>> second.
>>   own_msleep(10);
>>   count++;
>>   if (count%100 == 0) printf("count=%d\n", count);
>> #endif
>> #if TEST_2 // Abnormal operation. total time for count 200 = about 2
>> seconds.
>>   own_msleep(5);
>>   count++;
>>   if (count%200 == 0) printf("count=%d\n", count);
>> #endif
>> #if TEST_3 // Abnormal operation. total time for count 500 = about 5
>> seconds.
>>   own_msleep(2);
>>   count++;
>>   if (count%500 == 0) printf("count=%d\n", count);
>> #endif
>> #if TEST_4 // Abnormal operation. total time for count 1000 = about 10
>> seconds.
>>   own_msleep(1);
>>   count++;
>>   if (count%1000 == 0) printf("count=%d\n", count);
>> #endif
>>  }
>>  return 0;
>> }
>>
>> As you see in my testing code, I called own_msleep() function using
>> pthread mutex, condition variable API.
>>
>> As my result, when I use own_msleep(10), there is not any problem for
>> this.
>> But, when I decrease time internal from 10ms to (5 or 2 or 1)ms, msleep()
>> have addtional delay.
>>
>> As I know from BSP code for realview-pbx-a9, OS timer interval is 1ms.
>>
>> Is it correct behaivor ?
>> Is there any limitation for using short time interval ?
>>
>> Please advise me.
>>
>> Best Regards,
>> Thomas Kim.
>>
>>
>> _______________________________________________
>> users mailing list
>> users at rtems.org
>> http://lists.rtems.org/mailman/listinfo/users
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rtems.org/pipermail/users/attachments/20170815/a6192b85/attachment-0001.html>


More information about the users mailing list