Notice: We have migrated to GitLab launching 2024-05-01 see here:

#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:

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>

Attachments (4)

0001-Add-missing-include-for-RTEMS.patch (921 bytes) - added by Sebastian Huber on 06/23/14 at 05:53:41.
Proposed fix for Newlib.
0001-rtems-fix-CLOCKS_PER_SEC.patch (768 bytes) - added by Gedare Bloom on 02/25/15 at 19:52:45.
Different proposed fix for newlib.
0001-libcsupport-scale-times-call-to-microseconds.patch (1.5 KB) - added by Gedare Bloom on 02/25/15 at 19:53:06.
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 03/03/15 at 16:12:51.
Test case.

Download all attachments as: .zip

Change History (11)

Changed on 06/23/14 at 05:53:41 by Sebastian Huber

Proposed fix for Newlib.

comment:1 Changed on 06/24/14 at 06:39:06 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;



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 12/18/14 at 12:38:35 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.

comment:3 Changed on 02/24/15 at 15:15:25 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 02/25/15 at 08:35:08 by Sebastian Huber

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

Changed on 02/25/15 at 19:52:45 by Gedare Bloom

Different proposed fix for newlib.

Changed on 02/25/15 at 19:53:06 by Gedare Bloom

Corresponding fix in RTEMS for different proposed fix in newlib.

comment:5 Changed on 02/25/15 at 19:55:49 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 03/04/15 at 20:39:14 by Gedare Bloom <gedare@…>

Resolution: fixed
Status: newclosed

In [changeset:"56c719260668c35e87acda32bb12bdf81f08d9e0/rtems"]:

psxtests/psxclock01: use clock() and CLOCKS_PER_SEC

Closes #2182

comment:7 Changed on 10/10/17 at 06:33:12 by Sebastian Huber

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