[RTEMS Project] #2084: Incorrect clock() return value if USE_TICKS_FOR_STATISTICS=1

RTEMS trac trac at rtems.org
Sun Aug 13 23:50:31 UTC 2017


#2084: Incorrect clock() return value if USE_TICKS_FOR_STATISTICS=1
--------------------------------+----------------------------
 Reporter:  Aleksandr Platonov  |       Owner:  Joel Sherrill
     Type:  defect              |      Status:  new
 Priority:  normal              |   Milestone:  4.11.3
Component:  cpukit              |     Version:  4.11
 Severity:  normal              |  Resolution:
 Keywords:                      |
--------------------------------+----------------------------

Old description:

> If RTEMS was configured with USE_TICKS_FOR_STATISTICS=1 then clock()
> function return value is incorrect (it equals to correct value * 2 in
> case if single thread application).
> This happens because of incorrect _timeo() function behavior (file
> cpukit/libcsupport/src/__times.c):
> clock_t _times(
>    struct tms  *ptms
> )
> {
> .....
>   ticks = rtems_clock_get_ticks_since_boot();
> ....
>   #else
>     ptms->tms_utime  = _Thread_Executing->cpu_time_used;
>   #endif
>   ptms->tms_stime  = ticks;
> ....
> }
>
> clock() function returns the sum of ptms structure fields, so in case of
> single thread application clock() returns (correct value) * 2.
>
> Example code:
> rtems_task Init(rtems_task_argument unused)
> {
>     time_t t, t0;
>     clock_t c;
>     rtems_time_of_day timeod;
>
>     rtems_clock_set(&timeod);
>     t0 = time(NULL);
>     while(1)
>     {
>       t = time(NULL);
>       c = clock();
>       printf("t: %04i c: %04i [%i]\n", t - t0, c / CLOCKS_PER_SEC, c);
>       while(c / CLOCKS_PER_SEC == clock() / CLOCKS_PER_SEC);
>     }
>     exit(0);
> }
>
> Example output:
> t: 0000 c: 0000 [0]
> t: 0000 c: 0001 [100]
> t: 0001 c: 0002 [200]
> t: 0001 c: 0003 [300]
> t: 0002 c: 0004 [400]
> t: 0002 c: 0005 [500]
> t: 0003 c: 0006 [600]
> .....

New description:

 If RTEMS was configured with USE_TICKS_FOR_STATISTICS=1 then clock()
 function return value is incorrect (it equals to correct value * 2 in case
 if single thread application).
 This happens because of incorrect _timeo() function behavior (file
 cpukit/libcsupport/src/__times.c):
 clock_t _times(
    struct tms  *ptms
 )
 {
 .....
   ticks = rtems_clock_get_ticks_since_boot();
 ....
   #else
     ptms->tms_utime  = _Thread_Executing->cpu_time_used;
   #endif
   ptms->tms_stime  = ticks;
 ....
 }

 clock() function returns the sum of ptms structure fields, so in case of
 single thread application clock() returns (correct value) * 2.

 Example code:
 rtems_task Init(rtems_task_argument unused)
 {
     time_t t, t0;
     clock_t c;
     rtems_time_of_day timeod;

     rtems_clock_set(&timeod);
     t0 = time(NULL);
     while(1)
     {
       t = time(NULL);
       c = clock();
       printf("t: %04i c: %04i [%i]\n", t - t0, c / CLOCKS_PER_SEC, c);
       while(c / CLOCKS_PER_SEC == clock() / CLOCKS_PER_SEC);
     }
     exit(0);
 }

 Example output:
 t: 0000 c: 0000 [0]
 t: 0000 c: 0001 [100]
 t: 0001 c: 0002 [200]
 t: 0001 c: 0003 [300]
 t: 0002 c: 0004 [400]
 t: 0002 c: 0005 [500]
 t: 0003 c: 0006 [600]
 .....

--

Comment (by Chris Johns):

 Joel, is anything going to happen with this ticket? It can be reopened if
 there is interest in the issue.

--
Ticket URL: <http://devel.rtems.org/ticket/2084#comment:6>
RTEMS Project <http://www.rtems.org/>
RTEMS Project


More information about the bugs mailing list