Hello gnulibbers,

I have a curious issue.  I would like to use clock_gettime with
CLOCK_PROCESS_CPUTIME_ID.  clock_gettime(2) notes some portability
issues with this timer, suggesting that the user call
clock_getcpuclockid(0) to verify that the timer is available.

I was using the clock-time module, but it turns out that on uclibc,
clock_gettime is available in libc, but clock_getcpuclockid is only
available in librt.  Thus the clock-time check doesn't add -lrt.

Here's a note from a user.  The quoted text is mine.

    > Is it perhaps that clock_getcpuclockid is in -lrt but clock_gettime is
    > in your libc?

    clock_gettime is in both of them:

    /lib # readelf -s librt.so.0 | grep clock
        42: 00001cb4    68 FUNC    GLOBAL DEFAULT    6 clock_gettime
        44: 00001a78   172 FUNC    GLOBAL DEFAULT    6 clock_nanosleep
        64: 00001b74    88 FUNC    GLOBAL DEFAULT    6 clock_getcpuclockid
    /lib # readelf -s libc.so.0 | grep clock
       166: 0000fcf4    72 FUNC    GLOBAL DEFAULT    6 clock_gettime
       514: 00011868    72 FUNC    GLOBAL DEFAULT    6 clock_settime
       537: 0000fa84    72 FUNC    GLOBAL DEFAULT    6 clock_getres
       762: 0002a588    56 FUNC    GLOBAL DEFAULT    6 clock

    but getcpuclockid is only in librt.

I "solved" this issue with a patch like the attached (to a locally
included gl_CLOCK_TIME).  What do you think is the right thing to do
here?

Thanks,

Andy

>From 5ad05b93a3f02be7c66fbab9c49e23ca314b7c33 Mon Sep 17 00:00:00 2001
From: Andy Wingo <wi...@pobox.com>
Date: Fri, 20 May 2011 18:48:33 +0200
Subject: [PATCH] check for clock_getcpuclockid in gl_CLOCK_TIME

* acinclude.m4 (gl_CLOCK_TIME): It could be that clock_gettime is in
  libc but clock_getcpuclockid is not, so check for that explicitly.
---
 acinclude.m4 |   12 +++++++++---
 1 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/acinclude.m4 b/acinclude.m4
index ba8b090..5bd1ced 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -529,8 +529,14 @@ AC_DEFUN([gl_CLOCK_TIME],
   AC_SUBST([LIB_CLOCK_GETTIME])
   gl_saved_libs=$LIBS
     AC_SEARCH_LIBS([clock_gettime], [rt posix4],
-                   [test "$ac_cv_search_clock_gettime" = "none required" ||
-                    LIB_CLOCK_GETTIME=$ac_cv_search_clock_gettime])
-    AC_CHECK_FUNCS([clock_gettime clock_settime])
+                   [if test "$ac_cv_search_clock_gettime" = "none required"; then
+                      AC_SEARCH_LIBS([clock_getcpuclockid], [rt posix4],
+                                     [test "$ac_cv_search_clock_getcpuclockid" = "none required" \
+                                      || LIB_CLOCK_GETTIME=$ac_cv_search_clock_getcpuclockid],
+                                     [LIB_CLOCK_GETTIME=$ac_cv_search_clock_gettime])
+                    else
+                      LIB_CLOCK_GETTIME=$ac_cv_search_clock_gettime
+                    fi])
+    AC_CHECK_FUNCS([clock_gettime clock_settime clock_getcpuclockid])
   LIBS=$gl_saved_libs
 ])
-- 
1.7.5.1

-- 
http://wingolog.org/

Reply via email to