[PATCH] Let RTEMS provide clock()

Sebastian Huber sebastian.huber@embedded-brains.de
Thu Sep 7 05:52:00 GMT 2017



On 06/09/17 16:30, Craig Howland wrote:
> On 09/06/2017 09:56 AM, Joel Sherrill wrote:
>>
>>
>> On 9/6/2017 3:53 AM, Sebastian Huber wrote:
>>> On 06/09/17 10:41, Corinna Vinschen wrote:
>>>
>>>> I just don't quite understand.  Is sysconf(_SC_CLK_TCK) different
>>>> from CLOCKS_PER_SEC on RTEMS?
>>>
>>> Yes, the CLOCKS_PER_SEC is a POSIX defined constant and the
>>> sysconf(_SC_CLK_TCK) returns the actual system tick frequency. Which is
>>> usually 100 or 1000 ticks per second.
>>>
>>
>> Making it more complicated, the system tick frequency is
>> something that the end user can set for each application.
>> We just need to make sure that the constant CLOCKS_PER_SECOND
>> is appropriate for use with clock() as defined here:
>>
>> http://pubs.opengroup.org/onlinepubs/9699919799/functions/clock.html
>>
>> Sebastian.. I assume that all that matches up per POSIX, right?
>>
>> --joel
> CLOCKS_PER_SEC is not necessarily constant on all systems.  It is only 
> POSIX which requires it to be fixed (at 1 million).  The C standard 
> defines it as "an expression with type clock_t that is the number per 
> second of the value returned by the clock function."  (In addition, 
> POSIX does not require microsecond accuracy, so the _times_r() return 
> value could simply be scaled to CLOCKS_PER_SEC if so desired as an 
> alternative way of doing it.)

This CLOCKS_PER_SEC seems to be a real mess. Its 100 or 1000000 on 
Newlib, 128 on FreeBSD, 100 on NetBSD and OpenBSD, 1000000 on glibc. 
XSI-conformant is 1000000:

http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/time.h.html

With respect to times() the document above says:

"To obtain the number of clock ticks per second returned by the 
/times/() 
<http://pubs.opengroup.org/onlinepubs/9699919799/functions/times.html> 
function, applications should call /sysconf/(_SC_CLK_TCK)."

-- 
Sebastian Huber, embedded brains GmbH

Address : Dornierstr. 4, D-82178 Puchheim, Germany
Phone   : +49 89 189 47 41-16
Fax     : +49 89 189 47 41-09
E-Mail  : sebastian.huber@embedded-brains.de
PGP     : Public key available on request.

Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.



More information about the Newlib mailing list