Implement clock_gettime() (XCC)
authorBarret Rhoden <brho@cs.berkeley.edu>
Mon, 11 Apr 2016 18:36:10 +0000 (14:36 -0400)
committerBarret Rhoden <brho@cs.berkeley.edu>
Fri, 15 Apr 2016 14:29:13 +0000 (10:29 -0400)
It's half baked; we don't have multiple clocks - it is just "time since
boot" + Nanwan's 0th birthday.

Rebuild glibc.

Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
tools/compilers/gcc-glibc/glibc-2.19-akaros/sysdeps/akaros/clock_gettime.c [new file with mode: 0644]

diff --git a/tools/compilers/gcc-glibc/glibc-2.19-akaros/sysdeps/akaros/clock_gettime.c b/tools/compilers/gcc-glibc/glibc-2.19-akaros/sysdeps/akaros/clock_gettime.c
new file mode 100644 (file)
index 0000000..ee246eb
--- /dev/null
@@ -0,0 +1,27 @@
+/* Copyright (c) 2016 Google Inc.
+ * Barret Rhoden <brho@cs.berkeley.edu>
+ * See LICENSE for details.
+ *
+ * Implementation of glibc's clock_gettime
+ *
+ * TODO:
+ * - consider supporting more clocks.
+ * - read the TSC and add the offset in userspace (part of a generic overhaul of
+ *   the time library functions).
+ */
+
+#include <time.h>
+#include <sys/time.h>
+
+int __clock_gettime(clockid_t clk_id, struct timespec *tp)
+{
+       struct timeval tv;
+
+       if (gettimeofday(&tv, 0))
+               return -1;
+       tp->tv_sec = tv.tv_sec;
+       tp->tv_nsec = tv.tv_usec * 1000;
+       return 0;
+}
+weak_alias(__clock_gettime, clock_gettime)
+libc_hidden_def(__clock_gettime)