[PATCH] CPU-time clocks

Yaakov (Cygwin/X) yselkowitz@users.sourceforge.net
Sun May 15 18:37:00 GMT 2011


The attached patches implement POSIX CPU-time clock support:

http://pubs.opengroup.org/onlinepubs/9699919799/functions/clock_getcpuclockid.html
http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_getcpuclockid.html
http://pubs.opengroup.org/onlinepubs/9699919799/functions/clock_gettime.html
http://www.kernel.org/doc/man-pages/online/pages/man3/clock_getcpuclockid.3.html
http://www.kernel.org/doc/man-pages/online/pages/man3/pthread_getcpuclockid.3.html
http://www.kernel.org/doc/man-pages/online/pages/man3/clock_gettime.3.html

There are several things I need to note:

1) Unfortunately newlib's variable naming doesn't currently comply with
POSIX.  Fixing this will affect RTEMS, so this will need to be worked
out on the newlib list.

2) On Linux, clockid_t is a signed int, and glibc uses negative clock
IDs for processes and threads (e.g. clock_getcpuclockid returns -6 -
pid*8 for the given pid).  However, newlib's clockid_t is a unsigned
long, so I've chosen a slightly-different numbering scheme which makes
the code a bit cleaner.  While the scheme is arbitrary and could be
changed at any time, that should only be necessary if several more fixed
clock IDs are required in the future (a (clockid_t)10 would be mistaken
for a CPU-time clock for PID 1); right now POSIX defines only four fixed
clock IDs.

3) timer_create(2) needs to be reworked to support clocks other than
CLOCK_REALTIME.  For now, I'm falling back to the ENOTSUP case allowed
by POSIX, but this should be reexamined after reworking timer_create.

4) As noted in the comments, POSIX says that the permissions required to
set any particular clock are implementation-defined.  On Linux, CPU-time
clocks are not settable (IOW no process has such permissions); I have
done the same here.

5) The clock_getres(3) code is based on my findings on my system (156001
100ns on W7 x64); I'd appreciate some confirmation for other systems.

6) On Linux, clock_getres(3) does not appear to verify if a (potential)
CPU-time clock actually exists.

Patches for newlib, winsup/cygwin, and winsup/doc, along with test
programs for the new and affected functions, attached.


Yaakov

-------------- next part --------------
A non-text attachment was scrubbed...
Name: newlib-cpuclockid.patch
Type: text/x-patch
Size: 2118 bytes
Desc: not available
URL: <http://cygwin.com/pipermail/cygwin-patches/attachments/20110515/b56d6054/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cpuclockid.patch
Type: text/x-patch
Size: 12385 bytes
Desc: not available
URL: <http://cygwin.com/pipermail/cygwin-patches/attachments/20110515/b56d6054/attachment-0001.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cpuclockid-test2.c
Type: text/x-csrc
Size: 1137 bytes
Desc: not available
URL: <http://cygwin.com/pipermail/cygwin-patches/attachments/20110515/b56d6054/attachment-0002.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: getres-test.c
Type: text/x-csrc
Size: 1188 bytes
Desc: not available
URL: <http://cygwin.com/pipermail/cygwin-patches/attachments/20110515/b56d6054/attachment-0003.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: doc-cpuclockid.patch
Type: text/x-patch
Size: 857 bytes
Desc: not available
URL: <http://cygwin.com/pipermail/cygwin-patches/attachments/20110515/b56d6054/attachment-0004.bin>


More information about the Cygwin-patches mailing list