#2182 closed defect (fixed)

broken RTEMS CLOCKS_PER_SEC interface, when including only time.h

Reported by: Jeffrey Hill Owned by: Joel Sherrill
Priority: normal Milestone: 4.11
Component: bsps Version: 4.10
Severity: normal Keywords:
Cc: sebastian.huber@… Blocked By:
Blocking:

Description (last modified by Sebastian Huber)

I had to patch Lua (a very portable code) as follows for RTEMS 4.10. I had a look around in the source and maybe its not possible for _SC_CLK_TCK to be properly defined when expecting to include only the standard C lib clock interface via time.h. Maybe its fixed in 4.11, but nevertheless I should probably file a bug report while I see the issue, in case it isn’t.

/*

  • repair broken RTEMS CLOCKS_PER_SEC interface */

#ifdef rtems
# include <sys/unistd.h>
#endif

Attachments (4)

0001-Add-missing-include-for-RTEMS.patch (921 bytes) - added by Sebastian Huber on Jun 23, 2014 at 5:53:41 AM.
Proposed fix for Newlib.
0001-rtems-fix-CLOCKS_PER_SEC.patch (768 bytes) - added by Gedare Bloom on Feb 25, 2015 at 7:52:45 PM.
Different proposed fix for newlib.
0001-libcsupport-scale-times-call-to-microseconds.patch (1.5 KB) - added by Gedare Bloom on Feb 25, 2015 at 7:53:06 PM.
Corresponding fix in RTEMS for different proposed fix in newlib.
0001-psxtests-psxclock01-use-clock-and-CLOCKS_PER_SEC.patch (4.9 KB) - added by Gedare Bloom on Mar 3, 2015 at 4:12:51 PM.
Test case.

Download all attachments as: .zip

Change History (11)

Changed on Jun 23, 2014 at 5:53:41 AM by Sebastian Huber

Proposed fix for Newlib.

comment:1 Changed on Jun 24, 2014 at 6:39:06 AM by Sebastian Huber

Cc: Sebastian Huber added

As the subject says, this bug is about CLOCKS_PER_SEC not sysconf().

A test case is:

#include <time.h>

int main()
{

clock_t x = CLOCKS_PER_SEC;

(void) x;

return 0;

}

Error:

In file included from /opt/rtems-4.11/arm-rtems4.11/include/time.h:18:0,

from test.c:1:

test.c: In function 'main':
test.c:5:16: error: '_SC_CLK_TCK' undeclared (first use in this function)

clock_t x = CLOCKS_PER_SEC;


test.c:5:16: note: each undeclared identifier is reported only once for each function it appears in

comment:2 Changed on Dec 18, 2014 at 12:38:35 PM by Sebastian Huber

Description: modified (diff)

POSIX says that CLOCKS_PER_SEC is one million. So it seems this mapping to _SC_CLK_TCK is wrong.

http://pubs.opengroup.org/onlinepubs/009695399/functions/clock.html

comment:3 Changed on Feb 24, 2015 at 3:15:25 PM by Gedare Bloom

XSI requires CLOCKS_PER_SEC to be one million. If we don't care about XSI conformance we can let it be anything. However we could define CLOCKS_PER_SEC to 1000000 and scale ticks to microseconds in _times().

comment:4 Changed on Feb 25, 2015 at 8:35:08 AM by Sebastian Huber

We should definitely fix this so that we are in line with Linux and BSD.

Changed on Feb 25, 2015 at 7:52:45 PM by Gedare Bloom

Different proposed fix for newlib.

Changed on Feb 25, 2015 at 7:53:06 PM by Gedare Bloom

Corresponding fix in RTEMS for different proposed fix in newlib.

comment:5 Changed on Feb 25, 2015 at 7:55:49 PM by Gedare Bloom

I added two patches (untested) that may fix the bug. I'm a little bit confused about the original logic in the #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__ part though. Why does it divide ticks by 100 when assigning to tms_utime? I got rid of that division but maybe it belongs?

comment:6 Changed on Mar 4, 2015 at 8:39:14 PM by Gedare Bloom <gedare@…>

Resolution: fixed
Status: newclosed

In 56c719260668c35e87acda32bb12bdf81f08d9e0/rtems:

psxtests/psxclock01: use clock() and CLOCKS_PER_SEC

Closes #2182

comment:7 Changed on Oct 10, 2017 at 6:33:12 AM by Sebastian Huber

Component: libcpubsps
Note: See TracTickets for help on using tickets.