#2084 closed defect (wontfix)

Incorrect clock() return value if USE_TICKS_FOR_STATISTICS=1

Reported by: Aleksandr Platonov Owned by: Joel Sherrill
Priority: normal Milestone: Indefinite
Component: score Version: 4.11
Severity: normal Keywords:
Cc: Blocked By:
Blocking:

Description (last modified by Chris Johns)

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]
.....

Change History (8)

comment:1 Changed on Dec 24, 2012 at 12:57:22 PM by Aleksandr Platonov

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:2 Changed on Nov 24, 2014 at 6:58:28 PM by Gedare Bloom

Version: HEAD4.11

Replace Version=HEAD with Version=4.11 for the tickets with Milestone >= 4.11

comment:3 Changed on Dec 19, 2014 at 4:38:14 AM by Gedare Bloom

Milestone: 4.114.11.1

Bump milestone to 4.11.1 in case no patch exists and PR seems delayable.

comment:4 Changed on Jan 26, 2017 at 7:16:00 AM by Sebastian Huber

Milestone: 4.11.14.11.2

comment:5 Changed on Mar 23, 2017 at 1:04:45 AM by Chris Johns

Milestone: 4.11.24.11.3

The 4.11.2 milestone is closing.

comment:6 Changed on Aug 13, 2017 at 11:50:31 PM by Chris Johns

Description: modified (diff)

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

comment:7 Changed on Feb 5, 2018 at 4:38:40 AM by Chris Johns

Milestone: 4.11.3Indefinite

Requires funding.

comment:8 Changed on Feb 5, 2018 at 8:17:23 AM by Sebastian Huber

Resolution: wontfix
Status: newclosed

The USE_TICKS_FOR_STATISTICS is no longer supported.

Note: See TracTickets for help on using tickets.