]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
mach: Add CLOCK_MONOTONIC case in clock_gettime()
authorZhaoming Luo <zhmingluo@163.com>
Mon, 6 Jan 2025 04:39:07 +0000 (12:39 +0800)
committerSamuel Thibault <samuel.thibault@ens-lyon.org>
Sun, 12 Jan 2025 21:47:00 +0000 (22:47 +0100)
The Mach RPC host_get_uptime64() is implemented. It returns the elapsed time
value since bootup. See

https://git.savannah.gnu.org/cgit/hurd/gnumach.git/commit/?id=fc494bfe3fb6363e1077dc035eb119970d84a9d1

In this patch, the RPC is used to implement the monotonic clock for
mach.

* config.h.in: Add HAVE_HOST_GET_UPTIME64 config entry
* sysdeps/mach/clock_gettime.c: Add CLOCK_MONOTONIC case
* sysdeps/mach/configure: Check the existence of host_get_uptime64 RPC
* sysdeps/mach/configure.ac: Check the existence of host_get_uptime64 RPC

Message-ID: <20250106043907.1046-1-zhmingluo@163.com>

config.h.in
sysdeps/mach/clock_gettime.c
sysdeps/mach/configure
sysdeps/mach/configure.ac

index c26f98ccd636c8a763a433aa829900df037fef05..cdbd555366b4f03853c1fa1676de3d78c23da45e 100644 (file)
 /* Mach specific: define if the `host_page_size' RPC is available.  */
 #undef HAVE_HOST_PAGE_SIZE
 
+/* Mach specific: define if the `host_get_uptime64' RPC is available.  */
+#undef HAVE_HOST_GET_UPTIME64
+
 /* Mach specific: define if the `thread_set_name' RPC is available.  */
 #undef  HAVE_MACH_THREAD_SET_NAME
 
index 139247596376fc93de927ae95445be5baaa119d4..d8c6681ec5e6ae715d1cd86133a3388392dd3268 100644 (file)
@@ -20,6 +20,7 @@
 #include <mach.h>
 #include <assert.h>
 #include <shlib-compat.h>
+#include <mach/mig_errors.h>
 
 /* Get the current time of day, putting it into *TS.
    Returns 0 on success, -1 on errors.  */
@@ -31,6 +32,29 @@ __clock_gettime (clockid_t clock_id, struct timespec *ts)
 
   switch (clock_id) {
 
+    case CLOCK_MONOTONIC:
+      /* If HAVE_HOST_GET_UPTIME64 is not defined or not available,
+         CLOCK_MONOTONIC will be equivalent to CLOCK_REALTIME.  */
+#ifdef HAVE_HOST_GET_UPTIME64
+      {
+       time_value64_t tv;
+       err = __host_get_uptime64 (__mach_host_self (), &tv);
+
+       if (err != MIG_BAD_ID)
+         {
+           if (err)
+             {
+               __set_errno (err);
+               return -1;
+             }
+
+           TIME_VALUE64_TO_TIMESPEC (&tv, ts);
+           return 0;
+         }
+      }
+      /* FALLTHROUGH */
+#endif
+
     case CLOCK_REALTIME:
       {
        /* __host_get_time can only fail if passed an invalid host_t.
index abfe084fdab80d35c9e4817f6e4716a8a43f20e5..8aa6bbb18b8883c1bfb55164ebc58acf6af10ec6 100644 (file)
@@ -461,6 +461,36 @@ if test $libc_cv_mach_rpc_host_page_size = yes; then
 
 fi
 
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for host_get_uptime64 in mach_host.defs" >&5
+printf %s "checking for host_get_uptime64 in mach_host.defs... " >&6; }
+if test ${libc_cv_mach_rpc_host_get_uptime64+y}
+then :
+  printf %s "(cached) " >&6
+else case e in #(
+  e) cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <mach/mach_host.defs>
+
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+  $EGREP_TRADITIONAL "host_get_uptime64" >/dev/null 2>&1
+then :
+  libc_cv_mach_rpc_host_get_uptime64=yes
+else case e in #(
+  e) libc_cv_mach_rpc_host_get_uptime64=no ;;
+esac
+fi
+rm -rf conftest*
+ ;;
+esac
+fi
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $libc_cv_mach_rpc_host_get_uptime64" >&5
+printf "%s\n" "$libc_cv_mach_rpc_host_get_uptime64" >&6; }
+if test $libc_cv_mach_rpc_host_get_uptime64 = yes; then
+  printf "%s\n" "#define HAVE_HOST_GET_UPTIME64 1" >>confdefs.h
+
+fi
+
 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for thread_set_name in gnumach.defs" >&5
 printf %s "checking for thread_set_name in gnumach.defs... " >&6; }
 if test ${libc_cv_mach_rpc_thread_set_name+y}
index 6dfa2b3518920688bb59612fbafed74c4dc8e8e7..08e5fdefe9d3610550a06ed8c227bf42fb7fe499 100644 (file)
@@ -92,6 +92,8 @@ fi
 
 mach_RPC_CHECK(mach_host.defs, host_page_size,
               HAVE_HOST_PAGE_SIZE)
+mach_RPC_CHECK(mach_host.defs, host_get_uptime64,
+              HAVE_HOST_GET_UPTIME64)
 mach_RPC_CHECK(gnumach.defs, thread_set_name,
               HAVE_MACH_THREAD_SET_NAME)
 mach_RPC_CHECK(gnumach.defs, thread_get_name,