Port: Add OSX clock_gettime compat
authorMichael Jeanson <mjeanson@efficios.com>
Wed, 3 Aug 2016 20:54:16 +0000 (16:54 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 5 Aug 2016 19:39:15 +0000 (15:39 -0400)
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
19 files changed:
include/lttng/health-internal.h
src/bin/lttng-sessiond/main.c
src/bin/lttng-sessiond/ust-clock.h
src/bin/lttng-sessiond/ust-metadata.c
src/bin/lttng/commands/create.c
src/common/compat/Makefile.am
src/common/compat/time.h [new file with mode: 0644]
src/common/error.c
src/common/error.h
src/common/health/health.c
src/common/sessiond-comm/inet.c
src/common/sessiond-comm/inet6.c
tests/regression/kernel/Makefile.am
tests/regression/kernel/select_poll_epoll.c
tests/regression/tools/live/live_test.c
tests/regression/ust/clock-override/lttng-ust-clock-override-test.c
tests/regression/ust/getcpu-override/lttng-ust-getcpu-override-test.c
tests/utils/Makefile.am
tests/utils/utils.c

index 2225e33f1f0d77190eac25119f011d2300e038cd..1623518d110898aa6fff6a73f8fd70cd1a22ac20 100644 (file)
@@ -20,7 +20,7 @@
  */
 
 #include <assert.h>
-#include <time.h>
+#include <common/compat/time.h>
 #include <pthread.h>
 #include <urcu/tls-compat.h>
 #include <urcu/uatomic.h>
index 21bc0819db6e498dc2a355c41f23a49c944b9639..b0674612b54589de311bdfa0e76117226675223e 100644 (file)
@@ -2378,7 +2378,7 @@ static int spawn_consumer_thread(struct consumer_data *consumer_data)
        pthread_mutex_lock(&consumer_data->cond_mutex);
 
        /* Get time for sem_timedwait absolute timeout */
-       clock_ret = clock_gettime(CLOCK_MONOTONIC, &timeout);
+       clock_ret = lttng_clock_gettime(CLOCK_MONOTONIC, &timeout);
        /*
         * Set the timeout for the condition timed wait even if the clock gettime
         * call fails since we might loop on that call and we want to avoid to
index c2e0cbcc394a9708f16801802761169e8cd0ea6d..58ff8b9d01da2a032225689ad10c3f8e34053eff 100644 (file)
@@ -20,7 +20,7 @@
 #ifndef _UST_CLOCK_H
 #define _UST_CLOCK_H
 
-#include <time.h>
+#include <common/compat/time.h>
 #include <sys/time.h>
 #include <stdint.h>
 #include <stddef.h>
@@ -57,7 +57,7 @@ uint64_t trace_clock_read64_monotonic(void)
 {
        struct timespec ts;
 
-       if (clock_gettime(CLOCK_MONOTONIC, &ts)) {
+       if (lttng_clock_gettime(CLOCK_MONOTONIC, &ts)) {
                /* TODO Report error cleanly up the chain. */
                PERROR("clock_gettime CLOCK_MONOTONIC");
                ts.tv_sec = 0;
index d24df194342f144ebd2bbee832c6b7b5de69595b..49edb1711254bf9475ddc74f9432aec0e0a38312 100644 (file)
@@ -819,7 +819,7 @@ int measure_single_clock_offset(struct offset_sample *sample)
        int ret;
 
        monotonic[0] = trace_clock_read64();
-       ret = clock_gettime(CLOCK_REALTIME, &rts);
+       ret = lttng_clock_gettime(CLOCK_REALTIME, &rts);
        if (ret < 0) {
                return ret;
        }
index 0ae2b10968456adc54d4df7f4985458268c4e8f7..0f7d1a4380646804354164565746f7a30bd90a0b 100644 (file)
@@ -24,7 +24,7 @@
 #include <string.h>
 #include <sys/stat.h>
 #include <sys/types.h>
-#include <time.h>
+#include <common/compat/time.h>
 #include <unistd.h>
 #include <signal.h>
 #include <sys/wait.h>
index 865fd7f70c3e84a13d25e279051bddc78c09152f..2d2b02a0d5c8dee442831283532b77f758f3b1cc 100644 (file)
@@ -10,4 +10,5 @@ endif
 
 libcompat_la_SOURCES = poll.h fcntl.h endian.h mman.h dirent.h \
                socket.h compat-fcntl.c uuid.h tid.h \
-               getenv.h string.h prctl.h paths.h netdb.h $(COMPAT)
+               getenv.h string.h prctl.h paths.h netdb.h $(COMPAT) \
+               time.h
diff --git a/src/common/compat/time.h b/src/common/compat/time.h
new file mode 100644 (file)
index 0000000..f51075d
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2016 Michael Jeanson <mjeanson@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#ifndef _COMPAT_TIME_H
+#define _COMPAT_TIME_H
+
+#include <time.h>
+
+#ifdef __APPLE__
+typedef uint64_t timer_t;
+typedef int clockid_t;
+
+#include <mach/mach.h>
+#include <mach/clock.h>
+
+#define CLOCK_REALTIME CALENDAR_CLOCK
+#define CLOCK_MONOTONIC SYSTEM_CLOCK
+
+static inline
+int lttng_clock_gettime(clockid_t clk_id, struct timespec *tp)
+{
+       int ret = 0;
+       clock_serv_t clock;
+       mach_timespec_t now;
+
+       if (clk_id != CLOCK_REALTIME && clk_id != CLOCK_MONOTONIC) {
+               ret = -1;
+               errno = EINVAL;
+               goto end;
+       }
+
+       host_get_clock_service(mach_host_self(), clk_id, &clock);
+
+       ret = clock_get_time(clock, &now);
+       if (ret != KERN_SUCCESS) {
+               ret = -1;
+               goto deallocate;
+       }
+
+        tp->tv_sec = now.tv_sec;
+        tp->tv_nsec = now.tv_nsec;
+
+deallocate:
+       mach_port_deallocate(mach_task_self(), clock);
+end:
+       return ret;
+}
+
+#else /* __APPLE__ */
+
+static inline
+int lttng_clock_gettime(clockid_t clk_id, struct timespec *tp)
+{
+       return clock_gettime(clk_id, tp);
+}
+
+#endif /* __APPLE__ */
+
+#endif /* _COMPAT_TIME_H */
index d3d952a7de810d3ab0f52d19a8ee805ba2a9c236..1067e48527e8d3fc70a46cd3766d26bc8d475f8d 100644 (file)
@@ -46,7 +46,7 @@ const char *log_add_time(void)
        struct timespec tp;
        time_t now;
 
-       ret = clock_gettime(CLOCK_REALTIME, &tp);
+       ret = lttng_clock_gettime(CLOCK_REALTIME, &tp);
        if (ret < 0) {
                goto error;
        }
index e8c811ee60e34e2510d65907cac6ba94747fe332..9b07e0a471054a20a85150c3dc91d2a2cda35d6c 100644 (file)
@@ -24,7 +24,7 @@
 #include <string.h>
 #include <stdbool.h>
 #include <urcu/tls-compat.h>
-#include <time.h>
+#include <common/compat/time.h>
 
 #ifndef _GNU_SOURCE
 #error "lttng-tools error.h needs _GNU_SOURCE"
index 2667e393002c8cbb21c22fdd70e384d90396d92d..830b6f0ef2829e7550fcdded38b17ae8837f265c 100644 (file)
@@ -171,7 +171,7 @@ static int validate_state(struct health_app *ha, struct health_state *state)
        last = state->last;
        current = uatomic_read(&state->current);
 
-       ret = clock_gettime(CLOCK_MONOTONIC, &current_time);
+       ret = lttng_clock_gettime(CLOCK_MONOTONIC, &current_time);
        if (ret < 0) {
                PERROR("Error reading time\n");
                /* error */
index b870deef48b325614d73412a169ef086b02f5245..84bee5bd99142970ece0b1e1a1e9c2a0be10c720 100644 (file)
@@ -26,7 +26,7 @@
 #include <unistd.h>
 #include <errno.h>
 #include <fcntl.h>
-#include <time.h>
+#include <common/compat/time.h>
 #include <poll.h>
 
 #include <common/common.h>
@@ -159,7 +159,7 @@ int connect_with_timeout(struct lttcomm_sock *sock)
                return -1;
        }
 
-       ret = clock_gettime(CLOCK_MONOTONIC, &orig_time);
+       ret = lttng_clock_gettime(CLOCK_MONOTONIC, &orig_time);
        if (ret == -1) {
                PERROR("clock_gettime");
                return -1;
@@ -213,7 +213,7 @@ int connect_with_timeout(struct lttcomm_sock *sock)
                        }
                }
                /* ret == 0: timeout */
-               ret = clock_gettime(CLOCK_MONOTONIC, &cur_time);
+               ret = lttng_clock_gettime(CLOCK_MONOTONIC, &cur_time);
                if (ret == -1) {
                        PERROR("clock_gettime");
                        connect_ret = ret;
index 51d02ebb91d426fffc3928e0435240e8077ac861..1413c35172a32bfda2293bbe8aae6fd8acba6c1a 100644 (file)
@@ -26,7 +26,7 @@
 #include <unistd.h>
 #include <errno.h>
 #include <fcntl.h>
-#include <time.h>
+#include <common/compat/time.h>
 #include <poll.h>
 
 #include <common/common.h>
@@ -157,7 +157,7 @@ int connect_with_timeout(struct lttcomm_sock *sock)
                return -1;
        }
 
-       ret = clock_gettime(CLOCK_MONOTONIC, &orig_time);
+       ret = lttng_clock_gettime(CLOCK_MONOTONIC, &orig_time);
        if (ret == -1) {
                PERROR("clock_gettime");
                return -1;
@@ -211,7 +211,7 @@ int connect_with_timeout(struct lttcomm_sock *sock)
                        }
                }
                /* ret == 0: timeout */
-               ret = clock_gettime(CLOCK_MONOTONIC, &cur_time);
+               ret = lttng_clock_gettime(CLOCK_MONOTONIC, &cur_time);
                if (ret == -1) {
                        PERROR("clock_gettime");
                        connect_ret = ret;
index cfdeeb93be186baa1236726313bf7deb66e6473a..e9ec04ea9593dbfbc61005859a7ea4ff4573c997 100644 (file)
@@ -1,3 +1,4 @@
+AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/src
 EXTRA_DIST = test_event_basic test_all_events test_syscall \
                test_clock_override test_rotation_destroy_flush \
                test_select_poll_epoll
index dfb52370bf761a050ca68ac64a8f88ae42411d1b..4b703b38039f60ac9ad146ca750d60af743e1a3f 100644 (file)
@@ -17,7 +17,7 @@
 #include <limits.h>
 #include <pthread.h>
 #include <sys/mman.h>
-#include <time.h>
+#include <common/compat/time.h>
 
 #define BUF_SIZE 256
 #define NB_FD 1
index cce6d10698375b19d727cc53109cd93184e8fc07..8ff97db253652dad50e5f3d08816bba689b7288f 100644 (file)
@@ -21,7 +21,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
-#include <time.h>
+#include <common/compat/time.h>
 #include <sys/types.h>
 #include <inttypes.h>
 #include <stdlib.h>
index deaa16405511b3146d364f261c9c58fddacab193..b918f787c4fc1892874c33f9704e7f6498717312 100644 (file)
@@ -25,7 +25,7 @@
  */
 
 #include <stdlib.h>
-#include <time.h>
+#include <common/compat/time.h>
 #include <string.h>
 #include <stdio.h>
 #include <lttng/ust-clock.h>
index f86826ca47700eaf6220774a84063516014f37fe..5b4e559524058eee0fd32b5a1737015a3da0d4a3 100644 (file)
@@ -25,7 +25,7 @@
  */
 
 #include <stdlib.h>
-#include <time.h>
+#include <common/compat/time.h>
 #include <string.h>
 #include <stdio.h>
 #include <unistd.h>
index 9d327e0ec7b96fbb0aa554dab2699ffcbb765bd5..d2eb49fa6fcbaab359db7069847f5dcba61282b4 100644 (file)
@@ -1,5 +1,6 @@
 SUBDIRS = . tap testapp
 
+AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/src
 EXTRA_DIST = utils.sh test_utils.py babelstats.pl warn_processes.sh
 dist_noinst_SCRIPTS = utils.sh test_utils.py babelstats.pl
 noinst_LTLIBRARIES = libtestutils.la
index e7bd9ce9fbeef567bd8abb79434f8d728f6813c3..7aa8667d4f4520891d4b5d013ae752641897dde8 100644 (file)
@@ -16,7 +16,7 @@
  */
 
 #include <stdint.h>
-#include <time.h>
+#include <common/compat/time.h>
 #include <assert.h>
 #include <unistd.h>
 #include <stdio.h>
@@ -43,7 +43,7 @@ int usleep_safe(useconds_t usec)
        struct timespec t1, t2;
        int64_t time_remaining_ns = (int64_t) usec * (int64_t) NSEC_PER_USEC;
 
-       ret = clock_gettime(CLOCK_MONOTONIC, &t1);
+       ret = lttng_clock_gettime(CLOCK_MONOTONIC, &t1);
        if (ret) {
                ret = -1;
                perror("clock_gettime");
This page took 0.036035 seconds and 4 git commands to generate.