[Bug 2084] New: Incorrect clock() return value if USE_TICKS_FOR_STATISTICS=1
bugzilla-daemon at rtems.org
bugzilla-daemon at rtems.org
Mon Dec 24 13:57:22 UTC 2012
https://www.rtems.org/bugzilla/show_bug.cgi?id=2084
Bug #: 2084
Summary: Incorrect clock() return value if
USE_TICKS_FOR_STATISTICS=1
Classification: Unclassified
Product: RTEMS
Version: HEAD
Platform: All
OS/Version: RTEMS
Status: NEW
Severity: normal
Priority: P3
Component: cpukit
AssignedTo: joel.sherrill at oarcorp.com
ReportedBy: pam at oktetlabs.ru
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]
.....
--
Configure bugmail: https://www.rtems.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are watching all bug changes.
More information about the bugs
mailing list