summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Mooney <pmooney@pfmooney.com>2017-03-15 16:12:45 +0000
committerDan McDonald <danmcd@joyent.com>2020-02-27 15:05:30 -0500
commit2c2b5e89f6b9617f543c1b581759525f4730690e (patch)
tree4d8c6bdd8bd7e5f7e686a820dbb35707c53b026b
parent3e8c7f16168b2700c28b981ab66ca8ff755c5a5d (diff)
downloadillumos-joyent-2c2b5e89f6b9617f543c1b581759525f4730690e.tar.gz
11275 gettimeofday should use comm page
Reviewed by: Robert Mustacchi <rm@joyent.com> Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com> Reviewed by: Andrew Stormont <astormont@racktopsystems.com> Reviewed by: Garrett D'Amore <gdamore@racktopsystems.com> Reviewed by: Andy Fiddaman <omnios@citrus-it.co.uk> Reviewed by: Toomas Soome <tsoome@me.com> Approved by: Dan McDonald <danmcd@joyent.com>
-rw-r--r--usr/src/cmd/sgs/rtld/common/external.c24
-rw-r--r--usr/src/lib/libc/amd64/Makefile4
-rw-r--r--usr/src/lib/libc/amd64/sys/gettimeofday.s60
-rw-r--r--usr/src/lib/libc/i386/Makefile.com1
-rw-r--r--usr/src/lib/libc/i386/sys/gettimeofday.c50
-rw-r--r--usr/src/lib/libc/i386/sys/gettimeofday.s60
6 files changed, 73 insertions, 126 deletions
diff --git a/usr/src/cmd/sgs/rtld/common/external.c b/usr/src/cmd/sgs/rtld/common/external.c
index aca6522360..caade06cf1 100644
--- a/usr/src/cmd/sgs/rtld/common/external.c
+++ b/usr/src/cmd/sgs/rtld/common/external.c
@@ -22,7 +22,7 @@
/*
* Copyright (c) 1992, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright 2014 Garrett D'Amore <garrett@damore.org>
- * Copyright 2016 Joyent, Inc.
+ * Copyright (c) 2017, Joyent, Inc.
*/
/*
@@ -722,9 +722,9 @@ isalnum(int c)
#if defined(__i386) || defined(__amd64)
/*
- * Instead of utilizing the comm page for clock_gettime, rtld uses the raw
- * syscall instead. Doing so decreases the surface of symbols needed from libc
- * for a modest performance cost.
+ * Instead of utilizing the comm page for clock_gettime and gettimeofday, rtld
+ * uses the raw syscall instead. Doing so decreases the surface of symbols
+ * needed from libc for a modest performance cost.
*/
extern int __clock_gettime_sys(clockid_t, struct timespec *);
@@ -733,6 +733,22 @@ __clock_gettime(clockid_t clock_id, struct timespec *tp)
{
return (__clock_gettime_sys(clock_id, tp));
}
+
+int
+gettimeofday(struct timeval *tv, void *tz)
+{
+ if (tv != NULL) {
+ /*
+ * Perform the same logic as the libc gettimeofday() when it
+ * lacks comm page support: Make the clock_gettime syscall and
+ * divide out the tv_usec field as required.
+ */
+ __clock_gettime_sys(CLOCK_REALTIME, (timespec_t *)tv);
+ tv->tv_usec /= 1000;
+ }
+
+ return (0);
+}
#endif /* defined(__i386) || defined(__amd64) */
/*
diff --git a/usr/src/lib/libc/amd64/Makefile b/usr/src/lib/libc/amd64/Makefile
index bc1a7d3516..eeccb496e8 100644
--- a/usr/src/lib/libc/amd64/Makefile
+++ b/usr/src/lib/libc/amd64/Makefile
@@ -21,11 +21,10 @@
#
# Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
-# Copyright 2016 Joyent, Inc.
# Copyright (c) 2013, OmniTI Computer Consulting, Inc. All rights reserved.
# Copyright 2013 Garrett D'Amore <garrett@damore.org>
# Copyright 2018 Nexenta Systems, Inc.
-# Copyright (c) 2019, Joyent, Inc.
+# Copyright 2019 Joyent, Inc.
# Copyright 2019 OmniOS Community Edition (OmniOSce) Association.
#
@@ -1190,6 +1189,7 @@ $(PORTI18N_COND:%=pics/%) := \
pics/arc4random.o := CPPFLAGS += -I$(SRC)/common/crypto/chacha
pics/__clock_gettime.o := CPPFLAGS += $(COMMPAGE_CPPFLAGS)
+pics/gettimeofday.o := CPPFLAGS += $(COMMPAGE_CPPFLAGS)
.KEEP_STATE:
diff --git a/usr/src/lib/libc/amd64/sys/gettimeofday.s b/usr/src/lib/libc/amd64/sys/gettimeofday.s
deleted file mode 100644
index 1948a008d4..0000000000
--- a/usr/src/lib/libc/amd64/sys/gettimeofday.s
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License (the "License").
- * You may not use this file except in compliance with the License.
- *
- * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
- * If applicable, add the following below this CDDL HEADER, with the
- * fields enclosed by brackets "[]" replaced with your own identifying
- * information: Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- */
-
-/*
- * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
- * Use is subject to license terms.
- */
-
- .file "gettimeofday.s"
-
-#include "SYS.h"
-
- ANSI_PRAGMA_WEAK(gettimeofday,function)
-
-/*
- * implements int gettimeofday(struct timeval *tp, void *tzp)
- *
- * note that tzp is always ignored
- */
-
- ENTRY(gettimeofday)
-/*
- * use long long gethrestime()
- */
- pushq %rdi /* pointer to timeval */
- SYSFASTTRAP(GETHRESTIME)
-/*
- * gethrestime trap returns seconds in %eax, nsecs in %edx
- * need to convert nsecs to usecs & store into area pointed
- * to by struct timeval * argument.
- */
- popq %rcx /* pointer to timeval */
- jrcxz 1f /* bail if we get a null pointer */
- movq %rax, (%rcx) /* store seconds into timeval ptr */
- movl $274877907, %eax /* divide by 1000 as impl. by gcc */
- imull %edx /* See Hacker's Delight pg 162 */
- sarl $6, %edx /* simplified by 0 <= nsec <= 1e9 */
- movq %rdx, 8(%rcx) /* store usecs into timeval ptr + 8. */
-1:
- RETC /* return 0 */
- SET_SIZE(gettimeofday)
-
diff --git a/usr/src/lib/libc/i386/Makefile.com b/usr/src/lib/libc/i386/Makefile.com
index 3d1f791b6b..8e0fa7cf0f 100644
--- a/usr/src/lib/libc/i386/Makefile.com
+++ b/usr/src/lib/libc/i386/Makefile.com
@@ -1255,6 +1255,7 @@ $(PORTI18N_COND:%=pics/%) := \
pics/arc4random.o := CPPFLAGS += -I$(SRC)/common/crypto/chacha
pics/__clock_gettime.o := CPPFLAGS += $(COMMPAGE_CPPFLAGS)
+pics/gettimeofday.o := CPPFLAGS += $(COMMPAGE_CPPFLAGS)
.KEEP_STATE:
diff --git a/usr/src/lib/libc/i386/sys/gettimeofday.c b/usr/src/lib/libc/i386/sys/gettimeofday.c
new file mode 100644
index 0000000000..c2396e582a
--- /dev/null
+++ b/usr/src/lib/libc/i386/sys/gettimeofday.c
@@ -0,0 +1,50 @@
+/*
+ * This file and its contents are supplied under the terms of the
+ * Common Development and Distribution License ("CDDL"), version 1.0.
+ * You may only use this file in accordance with the terms of version
+ * 1.0 of the CDDL.
+ *
+ * A full copy of the text of the CDDL should have accompanied this
+ * source. A copy of the CDDL is also available via the Internet at
+ * http://www.illumos.org/license/CDDL.
+ */
+
+/*
+ * Copyright (c) 2017, Joyent, Inc.
+ */
+
+
+#include "thr_uberdata.h"
+#include <cp_defs.h>
+
+#pragma weak _gettimeofday = gettimeofday
+
+extern int __clock_gettime_sys(clockid_t, timespec_t *);
+
+int
+gettimeofday(struct timeval *tv, void *tz)
+{
+ comm_page_t *cp = (comm_page_t *)__uberdata.ub_comm_page;
+
+ /*
+ * Perform a NULL check before attempting to store the result directly.
+ * The old fasttrap logic would perform this same check, but after the
+ * call into hrestime().
+ */
+ if (tv == NULL) {
+ return (0);
+ }
+
+ /*
+ * Since timeval and timespec structs feature the same effective types
+ * and layout of their members, the conversion can be done in-place.
+ */
+ if (cp != NULL && __cp_can_gettime(cp) != 0) {
+ __cp_clock_gettime_realtime(cp, (struct timespec *)tv);
+ } else {
+ __clock_gettime_sys(CLOCK_REALTIME, (struct timespec *)tv);
+ }
+ /* Convert from tv_nsec to tv_usec */
+ tv->tv_usec /= 1000;
+ return (0);
+}
diff --git a/usr/src/lib/libc/i386/sys/gettimeofday.s b/usr/src/lib/libc/i386/sys/gettimeofday.s
deleted file mode 100644
index 1e21601aba..0000000000
--- a/usr/src/lib/libc/i386/sys/gettimeofday.s
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License (the "License").
- * You may not use this file except in compliance with the License.
- *
- * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
- * If applicable, add the following below this CDDL HEADER, with the
- * fields enclosed by brackets "[]" replaced with your own identifying
- * information: Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- */
-
-/*
- * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
- * Use is subject to license terms.
- */
-
- .file "gettimeofday.s"
-
-#include "SYS.h"
-
- ANSI_PRAGMA_WEAK(gettimeofday,function)
-
-/
-/ implements int gettimeofday(struct timeval *tp, void *tzp)
-/
-/ note that tzp is always ignored
-/
-
- ENTRY(gettimeofday)
-/
-/ use long long gethrestime()
-/
- SYSFASTTRAP(GETHRESTIME)
-/
-/ gethrestime trap returns seconds in %eax, nsecs in %edx
-/ need to convert nsecs to usecs & store into area pointed
-/ to by struct timeval * argument.
-/
- movl 4(%esp), %ecx / put ptr to timeval in %ecx
- jecxz 1f / bail if we get a null pointer
- movl %eax, (%ecx) / store seconds into timeval ptr
- movl $274877907, %eax / divide by 1000 as impl. by gcc
- imull %edx / See Hacker's Delight pg 162
- sarl $6, %edx / simplified by 0 <= nsec <= 1e9
- movl %edx, 4(%ecx) / store usecs into timeval ptr + 4.
-1:
- RETC / return 0
- SET_SIZE(gettimeofday)
-
-